resourceloader: Restore anticipated loader states for hardcoded module requests
authorTimo Tijhof <krinklemail@gmail.com>
Fri, 7 Aug 2015 00:44:38 +0000 (17:44 -0700)
committerTimo Tijhof <krinklemail@gmail.com>
Fri, 7 Aug 2015 00:56:18 +0000 (17:56 -0700)
Follows-up Icba6d7a87b2 which removed this code in the
assumption that they're now taken care of by mw.loader.load.

While that is the case, they are still in the HTML and when earlier
modules require these modules the loader should not initiate a separate
request.

This was especially problematic for the 'user' module which mw.loader
was requesting with a version from the startup module which is
not associated with the current user. This would've caused edits
to a user's personal scripts post-Icba6d7a87b2 to not propagate
correctly. The second request would be ignored by mw.loader since
it implements a module that is already implemented.

This only affected wikis that were manually depending on the 'user'
module from Common.js or a default-loaded gadget.

Bug: T108275
Change-Id: I1b863a3ee23191adaf34f66b58973618487118b2

includes/OutputPage.php

index dd7b90a..72d8a7c 100644 (file)
@@ -2923,6 +2923,15 @@ class OutputPage extends ContextSource {
                                                        Xml::encodeJsCall( 'mw.loader.load', array( $url ) )
                                                );
                                        }
+
+                                       // For modules requested directly in the html via <script> or mw.loader.load
+                                       // tell mw.loader they are being loading to prevent duplicate requests.
+                                       foreach ( $grpModules as $key => $module ) {
+                                               // Don't output state=loading for the startup module.
+                                               if ( $key !== 'startup' ) {
+                                                       $links['states'][$key] = 'loading';
+                                               }
+                                       }
                                }
 
                                if ( $group == 'noscript' ) {