(bug 31895) Fix bug in mediawiki.js with early domready handlers.
authorTimo Tijhof <ttijhof@wikimedia.org>
Sat, 23 Jun 2012 14:48:09 +0000 (16:48 +0200)
committerCatrope <roan.kattouw@gmail.com>
Wed, 4 Jul 2012 06:16:45 +0000 (23:16 -0700)
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

RELEASE-NOTES-1.20
resources/mediawiki/mediawiki.js

index c1a25e1..890eb6a 100644 (file)
@@ -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.
index f29a9bd..deb7795 100644 (file)
@@ -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.