X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=resources%2Fsrc%2Fmediawiki%2Fmediawiki.js;h=aa93ca2b755a7c41c4ebfe4ad4aedc2a2dfa23d5;hb=e015b76a6927391f25f4123780869452e855da2c;hp=6a218e3d25c0280d71d5b6ce686d17786cfb94ea;hpb=9c478b51e3b038b66d3825e6f112c158bea95b9e;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/src/mediawiki/mediawiki.js b/resources/src/mediawiki/mediawiki.js index 6a218e3d25..aa93ca2b75 100644 --- a/resources/src/mediawiki/mediawiki.js +++ b/resources/src/mediawiki/mediawiki.js @@ -53,7 +53,7 @@ } function defineFallbacks() { - // + // StringSet = window.Set || ( function () { /** * @private @@ -1511,8 +1511,15 @@ } /** - * Converts a module map of the form { foo: [ 'bar', 'baz' ], bar: [ 'baz, 'quux' ] } - * to a query string of the form foo.bar,baz|bar.baz,quux + * Converts a module map of the form `{ foo: [ 'bar', 'baz' ], bar: [ 'baz, 'quux' ] }` + * 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()`. + * + * 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 + * to decide when to split the requests due to url size. * * @private * @param {Object} moduleMap Module map @@ -1533,14 +1540,14 @@ * Make a network request to load modules from the server. * * @private - * @param {Object} moduleMap Module map, see #buildModulesString + * @param {string} moduleStr Module list for load.php `module` query parameter * @param {Object} currReqBase Object with other parameters (other than 'modules') to use in the request * @param {string} sourceLoadScript URL of load.php */ - function doRequest( moduleMap, currReqBase, sourceLoadScript ) { + function doRequest( moduleStr, currReqBase, sourceLoadScript ) { // Optimisation: Inherit (Object.create), not copy ($.extend) var query = Object.create( currReqBase ); - query.modules = buildModulesString( moduleMap ); + query.modules = moduleStr; query = sortQuery( query ); addScript( sourceLoadScript + '?' + $.param( query ) ); } @@ -1660,7 +1667,7 @@ // but don't create empty requests if ( maxQueryLength > 0 && !$.isEmptyObject( moduleMap ) && l + bytesAdded > maxQueryLength ) { // This url would become too long, create a new one, and start the old one - doRequest( moduleMap, currReqBase, sourceLoadScript ); + doRequest( buildModulesString( moduleMap ), currReqBase, sourceLoadScript ); moduleMap = {}; l = currReqBaseLength + 9; mw.track( 'resourceloader.splitRequest', { maxQueryLength: maxQueryLength } ); @@ -1673,7 +1680,7 @@ } // If there's anything left in moduleMap, request that too if ( !$.isEmptyObject( moduleMap ) ) { - doRequest( moduleMap, currReqBase, sourceLoadScript ); + doRequest( buildModulesString( moduleMap ), currReqBase, sourceLoadScript ); } } } @@ -1982,6 +1989,12 @@ * OO.compare( [ 1 ], [ 1 ] ); * } ); * + * Example of inline dependency obtained via `require()`: + * + * mw.loader.using( [ 'mediawiki.util' ], function ( require ) { + * var util = require( 'mediawiki.util' ); + * } ); + * * Since MediaWiki 1.23 this also returns a promise. * * Since MediaWiki 1.28 the promise is resolved with a `require` function. @@ -2154,9 +2167,14 @@ /** * Get the exported value of a module. * - * Modules may provide this via their local `module.exports`. + * This static method is publicly exposed for debugging purposes + * only and must not be used in production code. In production code, + * please use the dynamically provided `require()` function instead. * - * @protected + * In case of lazy-loaded modules via mw.loader#using(), the returned + * Promise provides the function, see #using() for examples. + * + * @private * @since 1.27 * @param {string} moduleName Module name * @return {Mixed} Exported value @@ -2780,9 +2798,9 @@ // We only need a callback, not any actual module. First try a single using() // for all loading modules. If one fails, fall back to tracking each module // separately via $.when(), this is expensive. - loading = mw.loader.using( modules ).then( null, function () { + loading = mw.loader.using( modules ).catch( function () { var all = modules.map( function ( module ) { - return mw.loader.using( module ).then( null, function () { + return mw.loader.using( module ).catch( function () { return $.Deferred().resolve(); } ); } );