Index: trunk/tools/viaf/README |
— | — | @@ -10,8 +10,8 @@ |
11 | 11 | http://de.wikipedia.org/wiki/Wikipedia:WikiConvention/ \ |
12 | 12 | Programm/VIAF#Greasemonkey-Skript (de) |
13 | 13 | |
14 | | -Version: 0.400 |
15 | | -README last updated: 20110924 |
| 14 | +Version: 0.401 |
| 15 | +README last updated: 20110925 |
16 | 16 | |
17 | 17 | What are VIAF numbers ? |
18 | 18 | |
— | — | @@ -59,25 +59,30 @@ |
60 | 60 | |
61 | 61 | JSON data layout for data exchange with Toolserver |
62 | 62 | ================================================== |
| 63 | +the request url has the general form: |
| 64 | +http://toolserver.org/~apper/pd/x.php?format=json&data=name&for= |
63 | 65 | |
64 | 66 | 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"]}] |
67 | 70 | |
68 | 71 | received from server: |
69 | 72 | [{"viaf":["40254510"],"names":[{"lang":"de,en,fr","name":"Herbert Matar\u00e9"}]}] |
70 | 73 | |
71 | 74 | |
72 | 75 | 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"]}] |
75 | 79 | |
76 | 80 | 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"}]}] |
78 | 82 | |
79 | 83 | 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"]}] |
82 | 87 | |
83 | 88 | received from server: |
84 | 89 | [ |
— | — | @@ -90,8 +95,9 @@ |
91 | 96 | ] |
92 | 97 | |
93 | 98 | 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"]}] |
96 | 102 | |
97 | 103 | received from server: |
98 | 104 | [ |
— | — | @@ -124,50 +130,33 @@ |
125 | 131 | ] |
126 | 132 | |
127 | 133 | 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"]}] |
131 | 137 | |
132 | 138 | received from server: |
133 | 139 | [ |
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"}]} |
141 | 142 | ] |
142 | 143 | |
143 | 144 | the same response in array notation: |
144 | 145 | '0' ... |
145 | 146 | 'viaf' ... |
146 | | - '0' => "100272799" |
| 147 | + '0' => "30359946" |
147 | 148 | 'names' ... |
148 | 149 | '0' ... |
149 | 150 | 'lang' => "de" |
150 | | - 'name' => "Peter Noll" |
| 151 | + 'name' => "Sabine Ludwig" |
151 | 152 | '1' ... |
152 | 153 | 'pnd' ... |
153 | | - '0' => "118588664" |
| 154 | + '0' => "120155567" |
154 | 155 | 'names' ... |
155 | 156 | '0' ... |
156 | 157 | 'lang' => "de" |
157 | | - 'name' => "Peter Noll" |
| 158 | + 'name' => "Sabine Ludwig" |
158 | 159 | |
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 | | - |
169 | 160 | == To Do == |
170 | 161 | * add a user-interface or mechanism to enable/disable the summary alert box |
171 | 162 | without the need to change program code |
172 | 163 | * 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 @@ |
5 | 5 | // @require https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js |
6 | 6 | // @require http://svn.wikimedia.org/svnroot/mediawiki/trunk/tools/viaf/jquery.cookie.js |
7 | 7 | // @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 |
9 | 9 | // @include * |
10 | 10 | // ==/UserScript== |
11 | 11 | |
12 | | -var VERSION = "0.400"; |
| 12 | +var VERSION = "0.401"; |
13 | 13 | /*** |
14 | 14 | * Copyright (c) 2011 T. Gries |
15 | 15 | * |
— | — | @@ -53,6 +53,7 @@ |
54 | 54 | * 20110924 detecting and linking PND and GND numbers as well |
55 | 55 | * Toolserver API adapted: names now returned for VIAF, PND, GND |
56 | 56 | * numbers; detected GND numbers are treated as PND |
| 57 | + * 20110925 summary shows VIAF, and PDN/GND numbers in a single alert box |
57 | 58 | * |
58 | 59 | ***/ |
59 | 60 | |
— | — | @@ -72,15 +73,19 @@ |
73 | 74 | * |
74 | 75 | ***/ |
75 | 76 | |
| 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 |
76 | 80 | var showSummaryBox = false; |
| 81 | + |
77 | 82 | var showAllNames = false; |
78 | 83 | |
79 | 84 | var markUrlDetectedItems = true; // if detected items in Urls will be marked |
80 | 85 | var markUrlDetectedItemsCSS = { "borderBottom" : "1px orangered dotted" }; |
81 | 86 | var markNamesFromServer = { "background":"magenta", "color":"white", "font-weight":"bold" }; |
82 | 87 | |
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; |
85 | 90 | |
86 | 91 | // Script update checker source: http://a32.me/2009/11/greasemonkey/ |
87 | 92 | var SCRIPT_NAME = "viaf" |
— | — | @@ -192,7 +197,7 @@ |
193 | 198 | // for base64 online encoder http://www.motobit.com/util/base64-decoder-encoder.asp |
194 | 199 | // for inline images http://www.elf.org/essay/inline-image.html |
195 | 200 | |
196 | | -function numberToNames( numberType, items ) { |
| 201 | +function numberToNames( items ) { |
197 | 202 | |
198 | 203 | if ( items.length == 0 ) return; |
199 | 204 | |
— | — | @@ -223,26 +228,26 @@ |
224 | 229 | * http://toolserver.org/~apper/pd/x.php?format=json&data=name&for=[{"viaf":["15571981"]},{"viaf":["79410188"]},{"viaf":["2878675"]},{"viaf":["122255788"]}] |
225 | 230 | * |
226 | 231 | * 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"]}] |
228 | 233 | * |
229 | 234 | * 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"}]}] |
231 | 236 | * |
232 | 237 | * example 2 response in array notation as produced by the enclosed dump() function: |
233 | 238 | * '0' ... |
234 | 239 | * 'viaf' ... |
235 | | - * '0' => "100272799" |
| 240 | + * '0' => "30359946" |
236 | 241 | * 'names' ... |
237 | 242 | * '0' ... |
238 | 243 | * 'lang' => "de" |
239 | | - * 'name' => "Peter Noll" |
| 244 | + * 'name' => "Sabine Ludwig" |
240 | 245 | * '1' ... |
241 | 246 | * 'pnd' ... |
242 | | - * '0' => "118588664" |
| 247 | + * '0' => "120155567" |
243 | 248 | * 'names' ... |
244 | 249 | * '0' ... |
245 | 250 | * 'lang' => "de" |
246 | | - * 'name' => "Peter Noll" |
| 251 | + * 'name' => "Sabine Ludwig" |
247 | 252 | * |
248 | 253 | ***/ |
249 | 254 | |
— | — | @@ -464,32 +469,45 @@ |
465 | 470 | // style all added links |
466 | 471 | $( ".addedlink" ).css( { "background":"yellow" , "color":"black" } ); |
467 | 472 | |
468 | | -numberToNames( "viaf", out_js ); |
469 | | -// numberToNames( "pnd", out_js ); |
| 473 | +numberToNames( out_js ); |
470 | 474 | |
471 | 475 | // show a summary of the collected numbers |
| 476 | +if ( viaf.length > 0 ) { |
472 | 477 | |
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 | + } |
478 | 483 | |
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 ); |
480 | 498 | 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"; |
483 | 501 | } |
484 | 502 | |
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; |
487 | 506 | |
488 | 507 | // comment the following line if you don't want to see the summary (alert) box |
489 | 508 | 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 ); |
491 | 510 | } |
492 | 511 | |
493 | | - |
494 | 512 | } |
495 | | -***/ |
| 513 | + |
496 | 514 | }) ( jQuery ); |