From: Timo Tijhof Date: Sat, 23 Jun 2012 14:48:09 +0000 (+0200) Subject: (bug 31895) Fix bug in mediawiki.js with early domready handlers. X-Git-Tag: 1.31.0-rc.0~23152^2 X-Git-Url: http://git.cyclocoop.org/%22.%24redirect_annul.%22?a=commitdiff_plain;h=a9aaa39fae4f2ef81fe12b3433e515a89e2b7bef;p=lhc%2Fweb%2Fwiklou.git (bug 31895) Fix bug in mediawiki.js with early domready handlers. Previously it used a local `ready` variable set to false, that is set to true from a $.fn.ready callback. Sounds good, except that we're not the only one in that callback list. And, more importantly, not always the first one. Thus if an earlier domready callback calls mw.loader, the value is still false, and the wrong load method could be used (bug 31895). Fixing by using $.isReady directly, which is set to true right before the domready callback list is fired. This is bug is impossible to hit within a MediaWiki environment since mediawiki.js is the first script loaded from the startup module and is blocking as well. But browser-userscripts, greasemonkey and/or browse extensions can sometimes get in an odd position in between or before. Change-Id: I146c1d2245aae71c538ce84daee30b4ec490b874 --- diff --git a/RELEASE-NOTES-1.20 b/RELEASE-NOTES-1.20 index c1a25e1db1..890eb6a431 100644 --- a/RELEASE-NOTES-1.20 +++ b/RELEASE-NOTES-1.20 @@ -145,6 +145,9 @@ upgrade PHP if you have not done so prior to upgrading MediaWiki. * (bug 36991) jquery.tablesorter should extract date sort format from date string instead of global config. Dates like "April 1 2012" and "1 April 2012" now sort correctly regardless of the content language's DefaultDateFormat. +* (bug 31895) mw.loader mode now correct when triggered from a $.fn.ready + handler that is bound before mediawiki.js's handler (e.g. browser-userscripts + like greasemonkey). === API changes in 1.20 === * (bug 34316) Add ability to retrieve maximum upload size from MediaWiki API. diff --git a/resources/mediawiki/mediawiki.js b/resources/mediawiki/mediawiki.js index f29a9bd377..deb779594a 100644 --- a/resources/mediawiki/mediawiki.js +++ b/resources/mediawiki/mediawiki.js @@ -351,7 +351,7 @@ var mw = ( function ( $, undefined ) { * } * } */ - var registry = {}, + var registry = {}, /** * Mapping of sources, keyed by source-id, values are objects. * Format: @@ -368,17 +368,9 @@ var mw = ( function ( $, undefined ) { queue = [], // List of callback functions waiting for modules to be ready to be called jobs = [], - // Flag indicating that document ready has occured - ready = false, // Selector cache for the marker element. Use getMarker() to get/use the marker! $marker = null; - /* Cache document ready status */ - - $(document).ready( function () { - ready = true; - } ); - /* Private methods */ function getMarker() { @@ -725,8 +717,12 @@ var mw = ( function ( $, undefined ) { * @param callback Function: Optional callback which will be run when the script is done */ function addScript( src, callback, async ) { - var done = false, script, head; - if ( ready || async ) { + var script, head, + done = false; + + // Using isReady directly instead of storing it locally from + // a $.fn.ready callback (bug 31895). + if ( $.isReady || async ) { // jQuery's getScript method is NOT better than doing this the old-fashioned way // because jQuery will eval the script's code, and errors will not have sane // line numbers.