X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=resources%2Fsrc%2Fstartup%2Fmediawiki.js;h=bbe503dbcbeda7a02e7003d5c1c099b9c4264525;hb=9f516f1d3b6ab6a4f1bb7e385c93e4d9bccb46d7;hp=ad05c6f6c0f46e1312399948b18f89541942d520;hpb=0f80b077fc5a0c1618076fcec6bcd824d093aa79;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/src/startup/mediawiki.js b/resources/src/startup/mediawiki.js index ad05c6f6c0..bbe503dbcb 100644 --- a/resources/src/startup/mediawiki.js +++ b/resources/src/startup/mediawiki.js @@ -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 */ @@ -506,7 +506,7 @@ * // 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 @@ -1211,15 +1211,9 @@ 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 ); } } ); @@ -1606,15 +1600,15 @@ // 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. @@ -1732,7 +1726,7 @@ 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 @@ -2102,9 +2096,8 @@ // 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. @@ -2123,7 +2116,13 @@ * @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 ) + }; }, /** @@ -2181,7 +2180,14 @@ 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; } @@ -2277,8 +2283,8 @@ 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,