resourceloader: Remove redundant closure of some startup and base files
[lhc/web/wiklou.git] / resources / src / startup / mediawiki.js
index ad05c6f..6a6aa3d 100644 (file)
@@ -13,7 +13,7 @@
        'use strict';
 
        var mw, StringSet, log,
-               hasOwn = Object.prototype.hasOwnProperty;
+               hasOwn = Object.hasOwnProperty;
 
        /**
         * FNV132 hash function
@@ -37,8 +37,8 @@
                        hash ^= str.charCodeAt( i );
                }
 
-               hash = ( hash >>> 0 ).toString( 36 );
-               while ( hash.length < 7 ) {
+               hash = ( hash >>> 0 ).toString( 36 ).slice( 0, 5 );
+               while ( hash.length < 5 ) {
                        hash = '0' + hash;
                }
                /* eslint-enable no-bitwise */
                         *             // From mw.loader.register()
                         *             'version': '########' (hash)
                         *             'dependencies': ['required.foo', 'bar.also', ...]
-                        *             'group': 'somegroup', (or) null
+                        *             'group': string, integer, (or) null
                         *             'source': 'local', (or) 'anotherwiki'
                         *             'skip': 'return !!window.Example', (or) null, (or) boolean result of skip
                         *             'module': export Object
 
                                dependencies.forEach( function ( module ) {
                                        // Only queue modules that are still in the initial 'registered' state
-                                       // (not ones already loading, ready or error).
+                                       // (e.g. not ones already loading or loaded etc.).
                                        if ( registry[ module ].state === 'registered' && queue.indexOf( module ) === -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' ) {
-                                                       setAndPropagate( module, 'error' );
-                                               } else {
-                                                       queue.push( module );
-                                               }
+                                               queue.push( module );
                                        }
                                } );
 
                                                // Optimisation: Inherit (Object.create), not copy ($.extend)
                                                currReqBase = Object.create( reqBase );
                                                // User modules require a user name in the query string.
-                                               if ( group === 'user' && mw.config.get( 'wgUserName' ) !== null ) {
+                                               if ( group === $VARS.groupUser && mw.config.get( 'wgUserName' ) !== null ) {
                                                        currReqBase.user = mw.config.get( 'wgUserName' );
                                                }
 
                                                // In addition to currReqBase, doRequest() will also add 'modules' and 'version'.
                                                // > '&modules='.length === 9
-                                               // > '&version=1234567'.length === 16
-                                               // > 9 + 16 = 25
-                                               currReqBaseLength = makeQueryString( currReqBase ).length + 25;
+                                               // > '&version=12345'.length === 14
+                                               // > 9 + 14 = 23
+                                               currReqBaseLength = makeQueryString( currReqBase ).length + 23;
 
                                                // We may need to split up the request to honor the query string length limit,
                                                // so build it piece by piece.
                                        packageExports: {},
                                        version: String( version || '' ),
                                        dependencies: dependencies || [],
-                                       group: typeof group === 'string' ? group : null,
+                                       group: typeof group === 'undefined' ? null : group,
                                        source: typeof source === 'string' ? source : 'local',
                                        state: 'registered',
                                        skip: typeof skip === 'string' ? skip : null
                                        // Whether the store is in use on this page.
                                        enabled: null,
 
-                                       // Modules whose string representation exceeds 100 kB are
-                                       // ineligible for storage. See bug T66721.
-                                       MODULE_SIZE_MAX: 100 * 1000,
+                                       // Modules whose serialised form exceeds 100 kB won't be stored (T66721).
+                                       MODULE_SIZE_MAX: 1e5,
 
                                        // The contents of the store, mapping '[name]@[version]' keys
                                        // to module implementations.
                                         * @return {Object} Module store contents.
                                         */
                                        toJSON: function () {
-                                               return { items: mw.loader.store.items, vary: mw.loader.store.vary };
+                                               return {
+                                                       items: mw.loader.store.items,
+                                                       vary: mw.loader.store.vary,
+                                                       // Store with 1e7 ms accuracy (1e4 seconds, or ~ 2.7 hours),
+                                                       // which is enough for the purpose of expiring after ~ 30 days.
+                                                       asOf: Math.ceil( Date.now() / 1e7 )
+                                               };
                                        },
 
                                        /**
                                                        this.enabled = true;
                                                        // If null, JSON.parse() will cast to string and re-parse, still null.
                                                        data = JSON.parse( raw );
-                                                       if ( data && typeof data.items === 'object' && data.vary === this.vary ) {
+                                                       if ( data &&
+                                                               typeof data.items === 'object' &&
+                                                               data.vary === this.vary &&
+                                                               // Only use if it's been less than 30 days since the data was written
+                                                               // 30 days = 2,592,000 s = 2,592,000,000 ms = ± 259e7 ms
+                                                               Date.now() < ( data.asOf * 1e7 ) + 259e7
+                                                       ) {
+                                                               // The data is not corrupt, matches our vary context, and has not expired.
                                                                this.items = data.items;
                                                                return;
                                                        }
                                                        descriptor.state !== 'ready' ||
                                                        // Unversioned, private, or site-/user-specific
                                                        !descriptor.version ||
-                                                       descriptor.group === 'private' ||
-                                                       descriptor.group === 'user' ||
+                                                       descriptor.group === $VARS.groupPrivate ||
+                                                       descriptor.group === $VARS.groupUser ||
                                                        // Partial descriptor
                                                        // (e.g. skipped module, or style module with state=ready)
                                                        [ descriptor.script, descriptor.style, descriptor.messages,
                                        }() )
                                }
                        };
-               }() ),
-
-               // Skeleton user object, extended by the 'mediawiki.user' module.
-               /**
-                * @class mw.user
-                * @singleton
-                */
-               user: {
-                       /**
-                        * @property {mw.Map}
-                        */
-                       options: new Map(),
-                       /**
-                        * @property {mw.Map}
-                        */
-                       tokens: new Map()
-               }
-
+               }() )
        };
 
        // Attach to window and globally alias