r98061 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98060‎ | r98061 | r98062 >
Date:08:29, 25 September 2011
Author:wikinaut
Status:deferred
Tags:
Comment:
v0.401 added PND/GND numbers to the summary box so that this now shows all distinct VIAF, PND/GND numbers, limited to a certain maximum, currently 30 numbers per number type
Modified paths:
  • /trunk/tools/viaf/README (modified) (history)
  • /trunk/tools/viaf/viaf.user.js (modified) (history)

Diff [purge]

Index: trunk/tools/viaf/README
@@ -10,8 +10,8 @@
1111 http://de.wikipedia.org/wiki/Wikipedia:WikiConvention/ \
1212 Programm/VIAF#Greasemonkey-Skript (de)
1313
14 -Version: 0.400
15 -README last updated: 20110924
 14+Version: 0.401
 15+README last updated: 20110925
1616
1717 What are VIAF numbers ?
1818
@@ -59,25 +59,30 @@
6060
6161 JSON data layout for data exchange with Toolserver
6262 ==================================================
 63+the request url has the general form:
 64+http://toolserver.org/~apper/pd/x.php?format=json&data=name&for=
6365
6466 Example 1
65 -sent to server:
66 -[{"viaf":["40254510"]}]
 67+=========
 68+simple example, one viaf requested, one name returned
 69+sent to server: [{"viaf":["40254510"]}]
6770
6871 received from server:
6972 [{"viaf":["40254510"],"names":[{"lang":"de,en,fr","name":"Herbert Matar\u00e9"}]}]
7073
7174
7275 Example 2
73 -sent to server:
74 -[{"viaf":["30429608"]}]
 76+=========
 77+simple example, one pnd requested, on name returned
 78+sent to server: [{"pnd":["122837231"]}]
7579
7680 received from server:
77 -[{"viaf":["30429608"],"names":[{"lang":"de,en","name":"Jan Josef Liefers"}]}]
 81+[{"pnd":["122837231"],"names":[{"lang":"de,en","name":"Jan Josef Liefers"}]}]
7882
7983 Example 3
80 -sent to server:
81 -[{"viaf":["2878675"]},{"viaf":["122255788"]}]
 84+=========
 85+request with a persons with two viaf numbers, only one has a name in the toolserver
 86+sent to server: [{"viaf":["2878675"]},{"viaf":["122255788"]}]
8287
8388 received from server:
8489 [
@@ -90,8 +95,9 @@
9196 ]
9297
9398 Example 4
94 -sent to server:
95 -[{"viaf":["2878675"]},{"viaf":["15571981"]}]
 99+=========
 100+request with two viaf numbers for two different persons
 101+sent to server: [{"viaf":["2878675"]},{"viaf":["15571981"]}]
96102
97103 received from server:
98104 [
@@ -124,50 +130,33 @@
125131 ]
126132
127133 Example 5
128 -request and response shows mixed viaf and pnd number for one person
129 -sent to server
130 -http://toolserver.org/~apper/pd/x.php?format=json&data=name&for=[{"viaf":["100272799"]},{"pnd":["118588664"]}]
 134+=========
 135+request with both a viaf and pnd number for one person
 136+sent to server: [{"viaf":["30359946"]},{"pnd":["120155567"]}]
131137
132138 received from server:
133139 [
134 -{"viaf":["100272799"],
135 -"names":[
136 -{"lang":"de","name":"Peter Noll"}]},
137 -{"pnd":["118588664"],
138 -"names":[
139 -{"lang":"de","name":"Peter Noll"}
140 -]}
 140+{"viaf":["30359946"],"names":[{"lang":"de","name":"Sabine Ludwig"}]},
 141+{"pnd":["120155567"],"names":[{"lang":"de","name":"Sabine Ludwig"}]}
141142 ]
142143
143144 the same response in array notation:
144145 '0' ...
145146 'viaf' ...
146 - '0' => "100272799"
 147+ '0' => "30359946"
147148 'names' ...
148149 '0' ...
149150 'lang' => "de"
150 - 'name' => "Peter Noll"
 151+ 'name' => "Sabine Ludwig"
151152 '1' ...
152153 'pnd' ...
153 - '0' => "118588664"
 154+ '0' => "120155567"
154155 'names' ...
155156 '0' ...
156157 'lang' => "de"
157 - 'name' => "Peter Noll"
 158+ 'name' => "Sabine Ludwig"
158159
159 -== solved ==
160 -+ searching now also PND and GND number
161 -+ Toolserver API changed, it returns names for VIAF, PND, GND numbers
162 - if they are available
163 -+ add a ajax request module to fetch author names for numbers from toolserver
164 - and show them live on the current page; define a JSONP data format
165 - (0.306)
166 -+ check why it does not work inside <span class=plainlinks> </span> tags
167 - fixed in r95940 (0.204)
168 -
169160 == To Do ==
170161 * add a user-interface or mechanism to enable/disable the summary alert box
171162 without the need to change program code
172163 * revise and enable the update mechanism
173 -* better positioning of added links - when they come from links they are
174 - placed too far away.
Index: trunk/tools/viaf/viaf.user.js
@@ -4,11 +4,11 @@
55 // @require https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js
66 // @require http://svn.wikimedia.org/svnroot/mediawiki/trunk/tools/viaf/jquery.cookie.js
77 // @require http://svn.wikimedia.org/svnroot/mediawiki/trunk/tools/viaf/jquery.ba-replacetext.js
8 -// @description locate VIAF numbers in texts and urls on web pages, fetch corresponding names from toolserver. (c)T.Gries Version 0.400 201109242100
 8+// @description locate VIAF numbers in texts and urls on web pages, fetch corresponding names from toolserver. (c)T.Gries Version 0.401 201109251000
99 // @include *
1010 // ==/UserScript==
1111
12 -var VERSION = "0.400";
 12+var VERSION = "0.401";
1313 /***
1414 * Copyright (c) 2011 T. Gries
1515 *
@@ -53,6 +53,7 @@
5454 * 20110924 detecting and linking PND and GND numbers as well
5555 * Toolserver API adapted: names now returned for VIAF, PND, GND
5656 * numbers; detected GND numbers are treated as PND
 57+ * 20110925 summary shows VIAF, and PDN/GND numbers in a single alert box
5758 *
5859 ***/
5960
@@ -72,15 +73,19 @@
7374 *
7475 ***/
7576
 77+// whether a summary box is shown at the end
 78+// which shows all distinct VIAF, PND/GND numbers of the current web page
 79+// TODO user interface to enable/disable this box per cookie or other method
7680 var showSummaryBox = false;
 81+
7782 var showAllNames = false;
7883
7984 var markUrlDetectedItems = true; // if detected items in Urls will be marked
8085 var markUrlDetectedItemsCSS = { "borderBottom" : "1px orangered dotted" };
8186 var markNamesFromServer = { "background":"magenta", "color":"white", "font-weight":"bold" };
8287
83 -// maximum of VIAF numbers which are shown in the summary box
84 -var maxVIAFNumbers = 30;
 88+// cumulative maximum of VIAF, PND, or GND numbers which are shown in the summary box
 89+var maxNumbers = 30;
8590
8691 // Script update checker source: http://a32.me/2009/11/greasemonkey/
8792 var SCRIPT_NAME = "viaf"
@@ -192,7 +197,7 @@
193198 // for base64 online encoder http://www.motobit.com/util/base64-decoder-encoder.asp
194199 // for inline images http://www.elf.org/essay/inline-image.html
195200
196 -function numberToNames( numberType, items ) {
 201+function numberToNames( items ) {
197202
198203 if ( items.length == 0 ) return;
199204
@@ -223,26 +228,26 @@
224229 * http://toolserver.org/~apper/pd/x.php?format=json&data=name&for=[{"viaf":["15571981"]},{"viaf":["79410188"]},{"viaf":["2878675"]},{"viaf":["122255788"]}]
225230 *
226231 * example 2 request and response shows mixed viaf and pnd number for one person
227 - * http://toolserver.org/~apper/pd/x.php?format=json&data=name&for=[{"viaf":["100272799"]},{"pnd":["118588664"]}]
 232+ * http://toolserver.org/~apper/pd/x.php?format=json&data=name&for=[{"viaf":["30359946"]},{"pnd":["120155567"]}]
228233 *
229234 * example 2 JSON response:
230 - * [{"viaf":["100272799"],"names":[{"lang":"de","name":"Peter Noll"}]},{"pnd":["118588664"],"names":[{"lang":"de","name":"Peter Noll"}]}]
 235+ * [{"viaf":["30359946"],"names":[{"lang":"de","name":"Sabine Ludwig"}]},{"pnd":["120155567"],"names":[{"lang":"de","name":"Sabine Ludwig"}]}]
231236 *
232237 * example 2 response in array notation as produced by the enclosed dump() function:
233238 * '0' ...
234239 * 'viaf' ...
235 - * '0' => "100272799"
 240+ * '0' => "30359946"
236241 * 'names' ...
237242 * '0' ...
238243 * 'lang' => "de"
239 - * 'name' => "Peter Noll"
 244+ * 'name' => "Sabine Ludwig"
240245 * '1' ...
241246 * 'pnd' ...
242 - * '0' => "118588664"
 247+ * '0' => "120155567"
243248 * 'names' ...
244249 * '0' ...
245250 * 'lang' => "de"
246 - * 'name' => "Peter Noll"
 251+ * 'name' => "Sabine Ludwig"
247252 *
248253 ***/
249254
@@ -464,32 +469,45 @@
465470 // style all added links
466471 $( ".addedlink" ).css( { "background":"yellow" , "color":"black" } );
467472
468 -numberToNames( "viaf", out_js );
469 -// numberToNames( "pnd", out_js );
 473+numberToNames( out_js );
470474
471475 // show a summary of the collected numbers
 476+if ( viaf.length > 0 ) {
472477
473 -/***
474 - *
475 - * FIXME
476 - *
477 -if ( out.length > 0 ) {
 478+ viaf.sort( numSort );
 479+ var x = "";
 480+ for ( var i=0; i < Math.min( viaf.length, maxNumbers ) ; i++ ) {
 481+ x += viaf[i]+"\n";
 482+ }
478483
479 - out.sort( numSort );
 484+ if ( viaf.length > maxNumbers ) x += "...\n("+maxNumbers+" of "+viaf.length+" distinct numbers are shown.)";
 485+ var pluralS = ( viaf.length > 1 ) ? "s" : "";
 486+ var viafSummary = "The present page contains "+viaf.length+" distinct VIAF number"+pluralS+" in text or links.\nModify the script if you want to remove the alert box permanently.\n\n"+x ;
 487+
 488+ // comment the following line if you don't want to see the summary (alert) box
 489+ // if ( showSummaryBox ) {
 490+ // alert( viafSummary );
 491+ // }
 492+
 493+}
 494+// show a summary of the collected numbers
 495+if ( pnd.length > 0 ) {
 496+
 497+ pnd.sort( numSort );
480498 var x = "";
481 - for ( var i=0; i < Math.min( out.length, maxVIAFNumbers ) ; i++ ) {
482 - x += out[i]+"\n";
 499+ for ( var i=0; i < Math.min( pnd.length, maxNumbers ) ; i++ ) {
 500+ x += pnd[i]+"\n";
483501 }
484502
485 - if ( out.length > maxVIAFNumbers ) x += "...\n("+maxVIAFNumbers+" of "+out.length+" distinct numbers are shown.)";
486 - var pluralS = ( out.length > 1 ) ? "s" : "";
 503+ if ( pnd.length > maxNumbers ) x += "...\n("+maxNumbers+" of "+pnd.length+" distinct numbers are shown.)";
 504+ var pluralS = ( pnd.length > 1 ) ? "s" : "";
 505+ var pndSummary = "The present page contains "+pnd.length+" distinct PND number"+pluralS+" in text or links.\n\n"+x;
487506
488507 // comment the following line if you don't want to see the summary (alert) box
489508 if ( showSummaryBox ) {
490 - alert( "The present page contains "+out.length+" distinct VIAF number"+pluralS+" in text or links.\nModify the script if you want to remove the alert box permanently.\n\n"+x );
 509+ alert( viafSummary + "\n" + pndSummary );
491510 }
492511
493 -
494512 }
495 -***/
 513+
496514 }) ( jQuery );

Status & tagging log