r97990 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97989‎ | r97990 | r97991 >
Date:10:51, 24 September 2011
Author:wikinaut
Status:deferred
Tags:
Comment:
version v0.309 adds detection of PND and GND numbers; currently not working is the fetch for names for PND and GND numbers from Toolserver. This will be added in a following commit when the toolserver API is able to serve such requests, too.
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.306
15 -README last updated: 20110909
 14+Version: 0.309
 15+README last updated: 20110924
1616
1717 What are VIAF numbers ?
1818
@@ -124,13 +124,15 @@
125125 ]
126126
127127 == solved ==
128 -+ check why it does not work inside <span class=plainlinks> </span> tags
129 - fixed in r95940 (0.204)
 128++ searching now also PND and GND number
130129 + add a ajax request module to fetch author names for numbers from toolserver
131130 and show them live on the current page; define a JSONP data format
132131 (0.306)
 132++ check why it does not work inside <span class=plainlinks> </span> tags
 133+ fixed in r95940 (0.204)
133134
134135 == To Do ==
 136+* adding Toolserver software and requests to also fetch names for PND/GMD number
135137 * add a user-interface or mechanism to enable/disable the summary alert box
136138 without the need to change program code
137139 * revise and enable the update mechanism
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.307 201109200845
 8+// @description locate VIAF numbers in texts and urls on web pages, fetch corresponding names from toolserver. (c)T.Gries Version 0.309 201109241230
99 // @include *
1010 // ==/UserScript==
1111
12 -var VERSION = "0.307";
 12+var VERSION = "0.309";
1313 /***
1414 * Copyright (c) 2011 T. Gries
1515 *
@@ -50,6 +50,7 @@
5151 * debug parameter bitwise
5252 * 20110920 removed parent() and add the new links close after the place
5353 * where the VIAF was found; jQuery 1.6.4
 54+ * 20110923 beginning to detect and link PND numbers as well
5455 *
5556 ***/
5657
@@ -176,7 +177,8 @@
177178 return dumped_text;
178179 }
179180
180 -var out = Array();
 181+var viaf = Array();
 182+var pnd = Array();
181183 var out_js = Array();
182184 var output = '';
183185 var nbsp = "<span>&nbsp</span>";
@@ -189,7 +191,7 @@
190192 // for base64 online encoder http://www.motobit.com/util/base64-decoder-encoder.asp
191193 // for inline images http://www.elf.org/essay/inline-image.html
192194
193 -function VIAFtoNames( items ) {
 195+function numberToNames( numberType, items ) {
194196
195197 if ( items.length == 0 ) return;
196198
@@ -239,7 +241,6 @@
240242 // callback function
241243 function cb_updateFromServer( data ){
242244 if ( debug & 2 ) output += "\n\nreceived from server:\n"+ data;
243 -
244245 var data_js = JSON.parse( data );
245246 if ( debug & 4 ) alert( dump( data_js ) );
246247
@@ -275,9 +276,7 @@
276277 .css( markNamesFromServer )
277278 .after( nbsp )
278279 .before( nbsp );
279 -
280280 }
281 -
282281 }
283282
284283 if ( ( debug & 8 ) && ( names.length > 0 ) ) {
@@ -290,11 +289,19 @@
291290 }
292291
293292
294 -function doAnyOtherBusiness( viaf ) {
 293+function doAnyOtherBusiness( numberType, number ) {
295294 // add the element only if it does not exist in list
296 - if ( out.indexOf(viaf) == -1 ) {
297 - out.push( viaf );
298 - out_js.push( { "viaf" : [ viaf ] } );
 295+ if ( numberType == "viaf" ) {
 296+ if ( viaf.indexOf( number ) == -1 ) {
 297+ viaf.push( number );
 298+ out_js.push( { "viaf" : [number] } );
 299+ }
 300+ } else {
 301+ if ( pnd.indexOf( number ) == -1 ) {
 302+ pnd.push( number );
 303+// FIXME
 304+ // out_js.push( { "pnd" : [number] } );
 305+ }
299306 }
300307 }
301308
@@ -308,7 +315,12 @@
309316 // but don't look in an active textareas like mediawiki input textarea
310317
311318 $("body *:not(textarea)")
312 - .replaceText( /(viaf[1-9]?)(:|\/|%2B|%3A|%2F|\s|ID:|=|%3D)+\s*([0-9]+)/gi, "<span class='viaf viaf-in-text' viaf='$3'>$1$2$3</span>" );
 319+ .replaceText( /(viaf[1-9]?)(:|\/|%2B|%3A|%2F|\s|ID:|=|%3D)+\s*([0-9]+)/gi, "<span class='viaf viaf-in-text' viaf='$3'>$1$2$3</span>" )
 320+// .replaceText( /([pg]nd[1-9]?)(:|\/|%2B|%3A|%2F|\s|ID:|=|%3D)+\s*([0-9]+x?)/gi, "<span class='pnd pnd-in-text' viaf='$3'>$1$2$3</span>" );
 321+ .replaceText( /([pg]nd[1-9]?)(:|\/|%2B|%3A|%2F|\s|ID:|=|%3D)+\s*([0-9]+x?)/gi, function( s0, s1, s2, s3 ){
 322+ s3 = s3.toUpperCase();
 323+ return "<span class='pnd pnd-in-text' pnd='" + s3 + "'>" + s1 + s2 + s3 + "</span>"
 324+ });
313325
314326 // PASS 2
315327 // try to retrieve viaf numbers in urls
@@ -316,6 +328,7 @@
317329 $("a").each(function(){
318330 var $this = $(this);
319331 if ( $this.find(".viaf").length != 0 ) return; // in PASS 2, skip all entries which have this attribute from PASS 1
 332+ if ( $this.find(".pnd").length != 0 ) return; // in PASS 2, skip all entries which have this attribute from PASS 1
320333 var url = $this.attr("href");
321334
322335 var magicUrlRegExp = new RegExp( /(http:\/\/viaf.org\/(viaf\/)?(\d+)|http:\/\/www.librarything.de\/commonknowledge\/search.php?f=13&exact=1&q=VIAF%3A(\d)+)/gi );
@@ -334,8 +347,8 @@
335348
336349 $(".viaf").each(function(){
337350 var $this = $(this);
 351+
338352 var viaf = $this.attr( "viaf" );
339 -
340353 var newLink = new Array();
341354 newLink.unshift( $( "<span> </span><a href='http://viaf.org/viaf/"+viaf+"/'><span class='addedlink viaf' viaf='"+viaf+"'>VIAF</span></a>" ) );
342355 newLink.unshift( $( "<span> </span><a href='http://www.librarything.de/commonknowledge/search.php?f=13&exact=1&q=VIAF%3A"+viaf+"'><span class='addedlink viaf' viaf='"+viaf+"'>LT de</span></a>" ) );
@@ -352,10 +365,33 @@
353366 for ( i in newLink ) {
354367 $this.after( newLink[i] )
355368 }
356 - doAnyOtherBusiness( viaf );
 369+
 370+ doAnyOtherBusiness( "viaf", viaf );
357371 })
358372
 373+$(".pnd").each(function(){
 374+ var $this = $(this);
359375
 376+ var pnd = $this.attr( "pnd" );
 377+ var newLink = new Array();
 378+
 379+ newLink.unshift( $( "<span> </span><a href='http://d-nb.info/gnd/"+pnd+"/'><span class='addedlink pnd' pnd='"+pnd+"'>DNB</span></a>" ) );
 380+ newLink.unshift( $( "<span> </span><a href='http://opac.bib-bvb.de/InfoGuideClient.fasttestsis/start.do?Query=100%3D%22"+pnd+"%22'><span class='addedlink pnd' pnd='"+pnd+"'>BVB</span></a>" ) );
 381+ newLink.unshift( $( "<span> </span><a href='http://mi.librarything.com/commonknowledge/search.php?f=13&exact=1&q=VIAF%3APND%3A"+pnd+"'><span class='addedlink pnd' pnd='"+pnd+"'>LT mi</span></a>" ) );
 382+ newLink.unshift( $( "<span> </span><a href='http://toolserver.org/~apper/pd/person/pnd/"+pnd+"'><span class='addedlink pnd' pnd='"+pnd+"'>TS</span></a>" ) );
 383+ // newLink.unshift( $( "<span> </span><label class='show-summary'><input type='checkbox' class='show-summary-checkbox' checked='checked'><span id='show-summary-text'></span></label>" ) );
 384+
 385+ // add a placeholder and a class for this specific pnd for the name texts
 386+ // which come per xhr callback handler cb_updateFromServer
 387+ newLink.unshift( $( "<span class='pnd-"+pnd+"'></span>" ) );
 388+ for ( i in newLink ) {
 389+ $this.after( newLink[i] )
 390+ }
 391+
 392+ doAnyOtherBusiness( "pnd", pnd );
 393+})
 394+
 395+
360396 // style all checkboxes
361397 $( ".show-summary-checkbox" )
362398 .click(function(e){
@@ -369,14 +405,17 @@
370406
371407 // style all detected numbers
372408 $( ".viaf" ).css( { "background":"cyan", "color":"black" } );
 409+$( ".pnd" ).css( { "background":"cyan", "color":"black" } );
373410
374411 // style all detected numbers in urls
375412 $( ".viaf-in-url" ).css( "border-bottom", "1px dotted black" );
 413+$( ".pnd-in-url" ).css( "border-bottom", "1px dotted black" );
376414
377415 // style all added links
378416 $( ".addedlink" ).css( { "background":"yellow" , "color":"black" } );
379417
380 -VIAFtoNames( out_js );
 418+numberToNames( "viaf", out_js );
 419+// numberToNames( "pnd", out_js );
381420
382421 // show a summary of the collected numbers
383422 if ( out.length > 0 ) {

Status & tagging log