r87697 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87696‎ | r87697 | r87698 >
Date:20:48, 8 May 2011
Author:krinkle
Status:ok
Tags:
Comment:
Fix exception thrown in mw.util.addPortletLink
* As of jQuery 1.4.4, Sizzle's query must be a string (it does a query.replace call before everything else). It fails otherwise.
* In REL1_17 and 1.17wmf1 this isn't a problem since jQuery 1.4.2 is there, in which Sizzle didn't fail on non-strings yet.
* Nonetheless this is undocumented support, we should make sure that the variable passed is a string on our side
* Adding a check for it in mw.util.addPortletLink's nextnode argument.
* Adding a test to mw.util.test that calls addPortletLink with three arguments, making nextnode implied undefined/null. This test returned "ERROR" before I made the fix in mw.util.addPortletLink.


Exact error: TypeError: Result of expression 'query' [undefined] is not an object.
Origin: line 4085 of jQuery/mediaWiki module load.
Line 4081: Sizzle = function( query, context, extra, seed ) {
Line 4085: query = query.replace(/\=\s*([^'"\]]*)\s*\]/g, "='$1']");
Modified paths:
  • /trunk/phase3/resources/mediawiki.util/mediawiki.util.js (modified) (history)
  • /trunk/phase3/resources/mediawiki.util/mediawiki.util.test.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/mediawiki.util/mediawiki.util.test.js
@@ -326,6 +326,9 @@
327327 mw.test.addTest( 'var a = mw.util.addPortletLink( "p-tb", "http://mediawiki.org/", "MediaWiki.org", "t-mworg", "Go to MediaWiki.org ", "m", "#t-rl" ); $(a).text();',
328328 'MediaWiki.org (string)' );
329329
 330+ mw.test.addTest( 'typeof mw.util.addPortletLink( "p-tb", "http://www.mediawiki.org/wiki/ResourceLoader/Default_modules", "Default modules", "t-rl", "All default modules present in MediaWiki" )',
 331+ 'object (string)' );
 332+
330333 mw.test.addTest( 'typeof mw.util.jsMessage',
331334 'function (string)' );
332335
Index: trunk/phase3/resources/mediawiki.util/mediawiki.util.js
@@ -375,19 +375,23 @@
376376 this.updateTooltipAccessKeys( $link );
377377 }
378378
379 - // Append using DOM-element passing
380 - if ( nextnode && nextnode.parentNode == $ul[0] ) {
 379+ // Where to put our node ?
 380+ // - nextnode is a DOM element (before MW 1.17, in wikibits.js, this was the only option)
 381+ if ( nextnode && nextnode.parentNode == $ul[0] ) {
381382 $(nextnode).before( $item );
 383+
 384+ // - nextnode is a CSS selector for jQuery
 385+ } else if ( typeof nextnode == 'string' && $ul.find( nextnode ).length !== 0 ) {
 386+ $ul.find( nextnode ).eq( 0 ).before( $item );
 387+
 388+
 389+ // If the jQuery selector isn't found within the <ul>,
 390+ // or if nextnode was invalid or not passed at all,
 391+ // then just append it at the end of the <ul> (this is the default behaviour)
382392 } else {
383 - // If the jQuery selector isn't found within the <ul>, just
384 - // append it at the end
385 - if ( $ul.find( nextnode ).length === 0 ) {
386 - $ul.append( $item );
387 - } else {
388 - // Append using jQuery CSS selector
389 - $ul.find( nextnode ).eq( 0 ).before( $item );
390 - }
 393+ $ul.append( $item );
391394 }
 395+
392396
393397 return $item[0];
394398 }

Status & tagging log