resourceloader: Set the request base parameters on server-side
[lhc/web/wiklou.git] / resources / src / startup / mediawiki.js
index 0a8dfb8..2976dca 100644 (file)
                         * Utility function for execute()
                         *
                         * @ignore
-                        * @param {string} [media] Media attribute
                         * @param {string} url URL
+                        * @param {string} [media] Media attribute
+                        * @param {Node|null} [nextNode]
                         */
-                       function addLink( media, url ) {
+                       function addLink( url, media, nextNode ) {
                                var el = document.createElement( 'link' );
 
                                el.rel = 'stylesheet';
                                // see #addEmbeddedCSS, T33676, T43331, and T49277 for details.
                                el.href = url;
 
-                               if ( marker && marker.parentNode ) {
-                                       marker.parentNode.insertBefore( el, marker );
+                               if ( nextNode && nextNode.parentNode ) {
+                                       nextNode.parentNode.insertBefore( el, nextNode );
                                } else {
                                        document.head.appendChild( el );
                                }
                                                        for ( i = 0; i < value.length; i++ ) {
                                                                if ( key === 'bc-url' ) {
                                                                        // back-compat: { <media>: [url, ..] }
-                                                                       addLink( media, value[ i ] );
+                                                                       addLink( value[ i ], media, marker );
                                                                } else if ( key === 'css' ) {
                                                                        // { "css": [css, ..] }
                                                                        addEmbeddedCSS( value[ i ], cssHandle() );
                                                        for ( media in value ) {
                                                                urls = value[ media ];
                                                                for ( i = 0; i < urls.length; i++ ) {
-                                                                       addLink( media, urls[ i ] );
+                                                                       addLink( urls[ i ], media, marker );
                                                                }
                                                        }
                                                }
                         * to a query string of the form `foo.bar,baz|bar.baz,quux`.
                         *
                         * See `ResourceLoader::makePackedModulesString()` in PHP, of which this is a port.
-                        * On the server, unpacking is done by `ResourceLoaderContext::expandModuleNames()`.
+                        * On the server, unpacking is done by `ResourceLoader::expandModuleNames()`.
                         *
                         * Note: This is only half of the logic, the other half has to be in #batchRequest(),
                         * because its implementation needs to keep track of potential string size in order
                                batch.sort();
 
                                // Query parameters common to all requests
-                               reqBase = {
-                                       skin: mw.config.get( 'skin' ),
-                                       lang: mw.config.get( 'wgUserLanguage' ),
-                                       debug: mw.config.get( 'debug' )
-                               };
+                               reqBase = $VARS.reqBase;
 
                                // Split module list by source and by group.
                                splits = Object.create( null );
                                 *  "text/javascript"; if no type is provided, text/javascript is assumed.
                                 */
                                load: function ( modules, type ) {
-                                       var l;
-
-                                       // Allow calling with a url or single dependency as a string
-                                       if ( typeof modules === 'string' ) {
-                                               // "https://example.org/x.js", "http://example.org/x.js", "//example.org/x.js", "/x.js"
-                                               if ( /^(https?:)?\/?\//.test( modules ) ) {
-                                                       if ( type === 'text/css' ) {
-                                                               l = document.createElement( 'link' );
-                                                               l.rel = 'stylesheet';
-                                                               l.href = modules;
-                                                               document.head.appendChild( l );
-                                                               return;
-                                                       }
-                                                       if ( type === 'text/javascript' || type === undefined ) {
-                                                               addScript( modules );
-                                                               return;
-                                                       }
+                                       if ( typeof modules === 'string' && /^(https?:)?\/?\//.test( modules ) ) {
+                                               // Called with a url like so:
+                                               // - "https://example.org/x.js"
+                                               // - "http://example.org/x.js"
+                                               // - "//example.org/x.js"
+                                               // - "/x.js"
+                                               if ( type === 'text/css' ) {
+                                                       addLink( modules );
+                                               } else if ( type === 'text/javascript' || type === undefined ) {
+                                                       addScript( modules );
+                                               } else {
                                                        // Unknown type
                                                        throw new Error( 'type must be text/css or text/javascript, found ' + type );
                                                }
-                                               // Called with single module
-                                               modules = [ modules ];
+                                       } else {
+                                               // One or more modules
+                                               modules = typeof modules === 'string' ? [ modules ] : modules;
+                                               // Resolve modules into flat list for internal queuing.
+                                               // This also filters out unknown modules and modules with
+                                               // unknown dependencies, allowing the rest to continue. (T36853)
+                                               enqueue( resolveStubbornly( modules ), undefined, undefined );
                                        }
-
-                                       // Resolve modules into flat list for internal queuing.
-                                       // This also filters out unknown modules and modules with
-                                       // unknown dependencies, allowing the rest to continue. (T36853)
-                                       enqueue( resolveStubbornly( modules ), undefined, undefined );
                                },
 
                                /**