mw.loader: Omit private modules from the request queue
authorTimo Tijhof <krinklemail@gmail.com>
Wed, 17 Jun 2015 15:12:31 +0000 (16:12 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Wed, 17 Jun 2015 15:17:21 +0000 (16:17 +0100)
The server will just deny these modules with an error. We can
save that roundtrip by just assuming that state directly.

A fair number of these requests hit the server logs primarily from
two sources:

* Third parties that cache screen-scraped pages from before 2013.
  The private module wouldn't have existed in the HTML yet. Some scripts
  aren't cached by them and as such they get a really stretched hybrid.
  These sometimes end up making requests for modules that no longer exist
  or indeed modules that have since become private.

* Web browsers and proxies that add or modify code on the page which can
  cause some inline scripts to break. There is no recovery from that in
  the current system. But falling back to the server is no solution for
  private modules. (Per T36907; bug 34907)

Bug: T101806
Change-Id: If8780db1410dd9ca31b3c1c19a6381a58663edab

resources/src/mediawiki/mediawiki.js

index ec3c0c3..a815c99 100644 (file)
 
                                $.each( dependencies, function ( idx, module ) {
                                        var state = mw.loader.getState( module );
+                                       // Only queue modules that are still in the initial 'registered' state
+                                       // (not ones already loading, ready or error).
                                        if ( state === 'registered' && $.inArray( module, queue ) === -1 ) {
+                                               // Private modules must be embedded in the page. Don't bother queuing
+                                               // these as the server will deny them anyway (T101806).
+                                               if ( registry[module].group === 'private' ) {
+                                                       registry[module].state = 'error';
+                                                       handlePending( module );
+                                                       return;
+                                               }
                                                queue.push( module );
                                                if ( async ) {
                                                        registry[module].async = true;