X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=resources%2Fsrc%2Fstartup%2Fmediawiki.js;h=21d95dfb444898dd8cdac8c8d4e4eb2ad9fffdeb;hb=a9252abb1cf0ad52ee25dc8c56d76a29a71d7045;hp=a3249de6f1eee390c3ff723bdc9b99ea72fafc29;hpb=38190f6608f3d2807cb93b1bae7edb770af36ef8;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/src/startup/mediawiki.js b/resources/src/startup/mediawiki.js index a3249de6f1..21d95dfb44 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 */ @@ -1606,9 +1606,9 @@ // 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. @@ -2096,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. @@ -2117,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 ) + }; }, /** @@ -2175,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; } @@ -2441,24 +2453,7 @@ }() ) } }; - }() ), - - // 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