Merge "ActiveUsersPager: Fix ordering and return 0-action users"
[lhc/web/wiklou.git] / resources / src / startup / mediawiki.js
index 967c529..28f57db 100644 (file)
                         * @param {Function} [callback] Callback to run after request resolution
                         */
                        function addScript( src, callback ) {
+                               // Use a <script> element rather than XHR. Using XHR changes the request
+                               // headers (potentially missing a cache hit), and reduces caching in general
+                               // since browsers cache XHR much less (if at all). And XHR means we retrieve
+                               // text, so we'd need to eval, which then messes up line numbers.
+                               // The drawback is that <script> does not offer progress events, feedback is
+                               // only given after downloading, parsing, and execution have completed.
                                var script = document.createElement( 'script' );
                                script.src = src;
                                script.onload = script.onerror = function () {
                         * @param {string[]} batch
                         */
                        function batchRequest( batch ) {
-                               var reqBase, splits, maxQueryLength, b, bSource, bGroup,
+                               var reqBase, splits, b, bSource, bGroup,
                                        source, group, i, modules, sourceLoadScript,
                                        currReqBase, currReqBaseLength, moduleMap, currReqModules, l,
                                        lastDotIndex, prefix, suffix, bytesAdded;
                                        lang: mw.config.get( 'wgUserLanguage' ),
                                        debug: mw.config.get( 'debug' )
                                };
-                               maxQueryLength = mw.config.get( 'wgResourceLoaderMaxQueryLength', 2000 );
 
                                // Split module list by source and by group.
                                splits = Object.create( null );
                                                                modules[ i ].length + 3; // '%7C'.length == 3
 
                                                        // If the url would become too long, create a new one, but don't create empty requests
-                                                       if ( maxQueryLength > 0 && currReqModules.length && l + bytesAdded > maxQueryLength ) {
+                                                       if ( currReqModules.length && l + bytesAdded > mw.loader.maxQueryLength ) {
                                                                // Dispatch what we've got...
                                                                doRequest();
                                                                // .. and start again.
                                                                moduleMap = Object.create( null );
                                                                currReqModules = [];
 
-                                                               mw.track( 'resourceloader.splitRequest', { maxQueryLength: maxQueryLength } );
+                                                               mw.track( 'resourceloader.splitRequest', { maxQueryLength: mw.loader.maxQueryLength } );
                                                        }
                                                        if ( !moduleMap[ prefix ] ) {
                                                                moduleMap[ prefix ] = [];
                                 */
                                moduleRegistry: registry,
 
+                               /**
+                                * Exposed for testing and debugging only.
+                                *
+                                * @see #batchRequest
+                                * @property
+                                * @private
+                                */
+                               maxQueryLength: $VARS.maxQueryLength,
+
                                /**
                                 * @inheritdoc #newStyleTag
                                 * @method
                                                                return;
                                                        }
                                                } catch ( e ) {
-                                                       mw.trackError( 'resourceloader.exception', {
-                                                               exception: e,
-                                                               source: 'store-localstorage-init'
-                                                       } );
+                                                       // Perhaps localStorage was disabled by the user, or got corrupted.
+                                                       // See point 3 and 4 below. (T195647)
                                                }
 
                                                // If we get here, one of four things happened:
 
                                                try {
                                                        if ( typeof descriptor.script === 'function' ) {
+                                                               // Function literal: cast to string
                                                                encodedScript = String( descriptor.script );
                                                        } else if (
-                                                               // Plain object: an object that is not null and is not an array
+                                                               // Plain object: serialise as object literal (not JSON),
+                                                               // making sure to preserve the functions.
                                                                typeof descriptor.script === 'object' &&
                                                                descriptor.script &&
                                                                !Array.isArray( descriptor.script )
                                                                        } ).join( ',' ) +
                                                                        '}}';
                                                        } else {
+                                                               // Array of urls, or null.
                                                                encodedScript = JSON.stringify( descriptor.script );
                                                        }
                                                        args = [