r96681 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96680‎ | r96681 | r96682 >
Date:18:43, 9 September 2011
Author:wikinaut
Status:deferred
Tags:
Comment:
new version 0.306 added: fetches names via gm_xhr-request from the toolserver; binary debug options
Modified paths:
  • /trunk/tools/viaf/README (modified) (history)
  • /trunk/tools/viaf/viaf.user.js (modified) (history)

Diff [purge]

Index: trunk/tools/viaf/README
@@ -1,5 +1,6 @@
22 viaf.user.js, a Greasemonkey script
33 which detects VIAF numbers on web pages and creates related links
 4+and fetches names for the detected numbers from toolserver.
45
56 Provisionally homepages and screenshots:
67
@@ -9,8 +10,8 @@
1011 http://de.wikipedia.org/wiki/Wikipedia:WikiConvention/ \
1112 Programm/VIAF#Greasemonkey-Skript (de)
1213
13 -Version: 0.204
14 -README last updated: 20110901
 14+Version: 0.306
 15+README last updated: 20110909
1516
1617 What are VIAF numbers ?
1718
@@ -41,10 +42,15 @@
4243 The VIAF number is then extracted from the url and also shown on the page
4344 in cyan colour with a black dotted underline as indication.
4445
45 -A summary box (6) lists all distinct VIAF numbers to facilitate cut & paste of
 46+The script calls asynchronously the toolserver with all detected VIAF numbers
 47+and receives as response names which correspond to the numbers, i.e. the
 48+authors' names. Names are shown on magenta labels.
 49+
 50+A summary box lsts all distinct VIAF numbers to facilitate cut & paste of
4651 the extracted numbers; this can be disabled in the program code.
4752
4853 The set of further server urls can be adapted in the program code.
 54+
4955 It relies on jQuery and two further javascripts, which are fetched automatically
5056 and has an integrated update checker (currently disabled) which looks for newer
5157 versions of it and prompts the user in such case.
@@ -54,11 +60,13 @@
5561 == solved ==
5662 + check why it does not work inside <span class=plainlinks> </span> tags
5763 fixed in r95940 (0.204)
 64++ add a ajax request module to fetch author names for numbers from toolserver
 65+ and show them live on the current page; define a JSONP data format
 66+ (0.306)
5867
5968 == To Do ==
60 -* check detection and algorithm of VIAF2...VIAF9 numbers
6169 * add a user-interface or mechanism to enable/disable the summary alert box
6270 without the need to change program code
6371 * revise and enable the update mechanism
64 -* add a ajax request module to fetch author names for numbers from toolserver
65 - and show them live on the current page; define a JSONP data format
 72+* better positioning of added links - when the come from links they are
 73+ placed too far away.
Index: trunk/tools/viaf/viaf.user.js
@@ -4,10 +4,11 @@
55 // @require https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/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. (c) T.Gries Version 0.206 201109030200
 8+// @description locate VIAF numbers in texts and urls on web pages, fetch corresponding names from toolserver. (c)T.Gries Version 0.306 201109091200
99 // @include *
1010 // ==/UserScript==
1111
 12+var VERSION = "0.306";
1213 /***
1314 * Copyright (c) 2011 T. Gries
1415 *
@@ -33,20 +34,50 @@
3435 * in span class=plainlinks; added blank spans left and right
3536 * of addedlinks for LTR/RTL pages
3637 * 20110903 less blanks between added links
 38+ * 20110907 calling a database to fetch names for detected VIAF numbers
 39+ * http://www.oclc.org/developer/ may be of help (API calls)
 40+ * "The OCLC Developer Network is a community of developers
 41+ * collaborating to propose, discuss and test OCLC Web Services.
 42+ * This open source, code-sharing infrastructure improves the
 43+ * value of OCLC data for all users by encouraging new OCLC
 44+ * Web Service uses."
 45+ * 20110908 calling toolserver API to fetch all avaliable names for a VIAF
 46+ * the first name from the server is shown on magenta background
 47+ * debug parameter 0 (no debug info) .. 3 (max)
 48+ * 20110909 POST instead of GET avoids server
 49+ * "Error 414: Request-URI too large" for long queries
 50+ * when many VIAF are found on a page
 51+ * debug parameter bitwise
 52+ *
3753 ***/
3854
39 -// wrapper see http://www.mediawiki.org/wiki/JQuery
 55+// wrapper -- see http://www.mediawiki.org/wiki/JQuery
4056 // to avoid possible conflicts with other scripts on the current page
 57+
4158 ( function ( $ ) {
4259
 60+var debug = 0;
 61+
 62+/***
 63+ * 0 off
 64+ * bit0: 1 show what has been sent to server
 65+ * bit1: 2 show what has been received as server response
 66+ * bit2: 4 dump the response in a readible form
 67+ * bit3: 8 list the names space-separated
 68+ *
 69+ ***/
 70+
 71+var showSummaryBox = false;
 72+var showAllNames = false;
 73+
4374 var markUrlDetectedItems = true; // if detected items in Urls will be marked
4475 var markUrlDetectedItemsCSS = { "borderBottom" : "1px orangered dotted" };
 76+var markNamesFromServer = { "background":"magenta", "color":"white", "font-weight":"bold" };
4577
4678 // maximum of VIAF numbers which are shown in the summary box
4779 var maxVIAFNumbers = 30;
4880
4981 // Script update checker source: http://a32.me/2009/11/greasemonkey/
50 -var VERSION = "0.206";
5182 var SCRIPT_NAME = "viaf"
5283 var SCRIPT_URL = "http://$$$yourhost$$$/"+SCRIPT_NAME+".user.js"
5384
@@ -89,16 +120,182 @@
90121 }
91122 }
92123
93 -var out = new Array();
 124+// utility functions
94125
 126+// our own sort order
 127+function numSort( a, b ) { return a-b }
 128+
 129+/**
 130+ *
 131+ * function : dump( array, depth )
 132+ *
 133+ * source:
 134+ * http://www.openjs.com/scripts/others/dump_function_php_print_r.php
 135+ *
 136+ * arguments: the data - array,hash(associative array),object
 137+ * the depth - OPTIONAL
 138+ *
 139+ * returns: the textual representation of the array
 140+ *
 141+ * This function was inspired by the PHP print_r function.
 142+ *
 143+ * This will accept some data as the argument and returns a text
 144+ * that will be a more readable version of the array/hash/object that is given.
 145+ *
 146+ **/
 147+function dump( arr, depth ) {
 148+ var dumped_text = "";
 149+ if( !depth ) depth = 0;
 150+
 151+ // The padding pattern given at the beginning of the line
 152+ var depth_padding = "";
 153+
 154+ for ( var j=0; j < depth+1; j++ ) {
 155+ depth_padding += " ";
 156+ }
 157+
 158+ if ( typeof( arr ) == 'object' ) { //Array/Hashes/Objects
 159+ for ( var item in arr ) {
 160+ var value = arr[item];
 161+
 162+ if ( typeof( value ) == 'object' ) { //If it is an array,
 163+ dumped_text += depth_padding + "'" + item + "' ...\n";
 164+ dumped_text += dump( value, depth+1 );
 165+ } else {
 166+ dumped_text += depth_padding + "'" + item + "' => \"" + value + "\"\n";
 167+ }
 168+ }
 169+ } else { //Strings/Chars/Numbers etc.
 170+ dumped_text = "===>"+arr+"<===(" + typeof( arr ) + ")";
 171+ }
 172+ if ( dumped_text == '' ) {
 173+ dumped_text = "no results";
 174+ }
 175+ return dumped_text;
 176+}
 177+
 178+var out = Array();
 179+var out_js = Array();
 180+var output = '';
 181+var nbsp = "<span>&nbsp</span>";
 182+
 183+// an animated "AJAX" loading wheel is shown and cleared in getPage2 when that page is processed
 184+// for online loader spinner image generation
 185+// http://www.google.com/search?hl=en&q=generate+animated+loading&btnG=Google+Search&aq=f&oq=
 186+// http://www.ajaxload.info/
 187+// http://preloaders.net/
 188+// for base64 online encoder http://www.motobit.com/util/base64-decoder-encoder.asp
 189+// for inline images http://www.elf.org/essay/inline-image.html
 190+
 191+function VIAFtoNames( items ) {
 192+
 193+ if ( items.length == 0 ) return;
 194+
 195+ // viaf-spinner-rotatin-arrows-cyan-80px
 196+ var $spinner = $( '<img src="data:image/x-icon;base64,R0lGODlhRgBGAKUAAAT+9IT+/ET+9MT+/CT+9GT+/KT+/OT+/FT+9DT+9BT+9JT+/Ez+9NT+/Cz+9HT+/LT+/PT+/Fz+/Dz+9Az+9Iz+/ET+/Mz+/CT+/Gz+/Kz+/Oz+/FT+/Bz+9Jz+/Ez+/Nz+/Cz+/Hz+/Lz+/Pz+/Dz+/P///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH/C05FVFNDQVBFMi4wAwEAAAAh+QQJCgAmACwAAAAARgBGAAAG/kCTcEgsGo/IpHLJbDqf0Kh0Sq1ar9isdsvter/gsHhMLh9Jh4F6zW6vQaTzJkKKkzcJgH7P7+szdkUkDyEFEBtlGxZ+jHuAZw97HQ9wYwcMjYyPRoN7FACTlWEgmJl8m4KRfgkGEWIgAqaOgUSdjBQPiGEHE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ViW8AF16BkC8i3FFHp4qV2SbS2vPyA15yA0A+FxX0irhlOJgOQCxOR0ceCZihCJZzaEwECXhbPAJjgiZ0DDM5sEpGjQ0TQerTWHBVyU4gJQF7wEQgVMiheKabK5I2AcBILhXCQYU/hoRTWZ+JNCWFBnA5ZEfGXRoBAMn+aRiEfyllkgHIwIkFVPx3cZdIqBZ4QGIfkRgXxTglKPIBBlo8CIRD/RXyQhDilSARX5MAAImU7xlHgAj1OhEZwXFsoGCLz6AWoMODrDkA3v5RgwFCaQIhQVE8dOBIyqKsF1RJ9YSQQVYivRjQQQUMMABd5yRhAYETUUVAg4omdN0hG5QAAgBLBDlPHUZeSEIj1yBFUomWpIjERYIOI0EgyypUacyKtJARiJISAsBGFiABxcPBNBQTdxshoSWFETgQaBfPGDABDuCtRUSB0gAAZlk0LNMmH0I6YqkkYgQgmRb0qLAbpE0IYIFMBgQ5Wk85TqhUAMSTKCqAma1a8gDGtwzwL4MfMCtvQAHLPDABBds8MEIJ6zwwlQEAQA7">' );
 197+
 198+ $( $spinner )
 199+ .css( {
 200+ "position":"fixed",
 201+ "top":"50%",
 202+ "left":"50%",
 203+ "display":"none"
 204+ } )
 205+ .attr( "id", "spinner" )
 206+
 207+ $( "body" ).append( $spinner );
 208+ $( "#spinner" ).fadeIn(4000);
 209+
 210+ var items_str = JSON.stringify( items );
 211+ if ( debug & 1 ) output = "sent to server:\n"+items_str;
 212+
 213+ // get names via Greasemonkey_xmlhttpRequest across domain borders
 214+ // example using "GET"
 215+ // http://toolserver.org/~apper/pd/x.php?format=json&data=name&for=[{"viaf":["15571981"]},{"viaf":["79410188"]},{"viaf":["2878675"]},{"viaf":["122255788"]}]
 216+
 217+ // http://wiki.greasespot.net/GM_xmlhttpRequest#POST_request
 218+ GM_xmlhttpRequest({
 219+ method: "POST",
 220+ url: "http://toolserver.org/~apper/pd/x.php",
 221+ data: "format=json&data=name&for="+items_str,
 222+ dataType: "json",
 223+ headers: {
 224+ "Content-Type": "application/x-www-form-urlencoded"
 225+ },
 226+ onload: function( request ) {
 227+ $( "#spinner" ).hide();
 228+ if ( request.status != '200' || typeof request.responseText == 'undefined' ) {
 229+ return;
 230+ } else {
 231+ cb_updateFromServer( request.responseText )
 232+ }
 233+ }
 234+ });
 235+
 236+}
 237+
 238+// callback function
 239+function cb_updateFromServer( data ){
 240+ if ( debug & 2 ) output += "\n\nreceived from server:\n"+ data;
 241+
 242+ var data_js = JSON.parse( data );
 243+ if ( debug & 4 ) alert( dump( data_js ) );
 244+
 245+ var names = '';
 246+
 247+ // for all returned viaf numbers do
 248+ for ( viaf_i in data_js ) {
 249+
 250+ // get the first viaf number per record,
 251+ // as this was the one which was found on the web page.
 252+ //
 253+ // All occurences are already marked as class "viaf-<viafnr>"
 254+ // when coming back here.
 255+ //
 256+ // Remark: the server response may contain further numbers for
 257+ // persons having more than one viaf number.
 258+
 259+ var viaf = data_js[viaf_i]['viaf'][0];
 260+
 261+ if ( data_js[viaf_i]['names'].length > 0 ) {
 262+
 263+ // for all available names for that viaf do
 264+ for ( name_i in data_js[viaf_i]['names'] ) {
 265+ names += data_js[viaf_i]['names'][name_i]['name']+" ";
 266+ }
 267+
 268+ // replace the class "viaf-<viafnr>"
 269+ // with all names string or with the first name only
 270+ var nameString = ( showAllNames ) ? names : data_js[viaf_i]['names'][0]['name'];
 271+
 272+ $(".viaf-" + viaf )
 273+ .text( " " + nameString + " " )
 274+ .css( markNamesFromServer )
 275+ .after( nbsp )
 276+ .before( nbsp );
 277+
 278+ }
 279+
 280+ }
 281+
 282+ if ( ( debug & 8 ) && ( names.length > 0 ) ) {
 283+ output += "\n\n" + names;
 284+ }
 285+ if ( debug & (8+2+1) ) {
 286+ alert( output );
 287+ }
 288+
 289+}
 290+
 291+
95292 function doAnyOtherBusiness( viaf ) {
96293 // add the element only if it does not exist in list
97294 if ( out.indexOf(viaf) == -1 ) {
98 - out.push(viaf);
 295+ out.push( viaf );
 296+ out_js.push( { "viaf" : [ viaf ] } );
99297 }
100298 }
101299
102 -
103300 // update checker (disabled)
104301 // GM_registerMenuCommand("Check for update of "+SCRIPT_NAME, updateCheck2);
105302 // updateCheck(0);
@@ -109,7 +306,7 @@
110307 // but don't look in an active textareas like mediawiki input textarea
111308
112309 $("body *:not(textarea)")
113 - .replaceText( /(viaf[1-9]?)(:|\/|%3A|%2F|\s|ID:|=|%3D)+([0-9]+)/gi, "<span class='viaf viaf-in-text' viaf='$3'>$1$2$3</span>" );
 310+ .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>" );
114311
115312 // PASS 2
116313 // try to retrieve viaf numbers in urls
@@ -136,7 +333,7 @@
137334 $(".viaf").each(function(){
138335 var $this = $(this);
139336 var viaf = $this.attr( "viaf" );
140 -
 337+
141338 var newLink = new Array();
142339 newLink.unshift( $( "<span> </span><a href='http://viaf.org/viaf/"+viaf+"/'><span class='addedlink viaf' viaf='"+viaf+"'>VIAF</span></a>" ) );
143340 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>" ) );
@@ -147,13 +344,16 @@
148345 newLink.unshift( $( "<span> </span><a href='http://www.google.com/search?num=100&q=viaf+"+viaf+"'><span class='addedlink viaf' viaf='"+viaf+"'>G</span></a>" ) );
149346 // newLink.unshift( $( "<span> </span><label class='show-summary'><input type='checkbox' class='show-summary-checkbox' checked='checked'><span id='show-summary-text'></span></label>" ) );
150347
151 - newLink.unshift( $( "<span> </span>" ) );
 348+ // add a placeholder and a class for this specific viaf for the name texts
 349+ // which come per xhr callback handler cb_updateFromServer
 350+ newLink.unshift( $( "<span class='viaf-"+viaf+"'></span>" ) );
152351 for ( i in newLink ) {
153352 $this.after( newLink[i] )
154353 }
155354 doAnyOtherBusiness( viaf );
156355 })
157356
 357+
158358 // style all checkboxes
159359 $( ".show-summary-checkbox" )
160360 .click(function(e){
@@ -174,9 +374,8 @@
175375 // style all added links
176376 $( ".addedlink" ).css( { "background":"yellow" , "color":"black" } );
177377
178 -function numSort( a, b ) { return a-b }
 378+VIAFtoNames( out_js );
179379
180 -
181380 // show a summary of the collected numbers
182381 if ( out.length > 0 ) {
183382
@@ -190,7 +389,11 @@
191390 var pluralS = ( out.length > 1 ) ? "s" : "";
192391
193392 // comment the following line if you don't want to see the summary (alert) box
194 - 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 );
 393+ if ( showSummaryBox ) {
 394+ 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 );
 395+ }
 396+
 397+
195398 }
196399
197400 }) ( jQuery );

Status & tagging log