X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=resources%2Fsrc%2Fmediawiki%2Fmediawiki.js;h=cfdb5a712bf71745e3cd0fc4f0a6f3453c71fd81;hb=fb0965860546f868b5654c3c41e7e891be8ad9ac;hp=e29c734d9b20dca2830528727a4858b5b134f409;hpb=523c6c0e41159c073b6b44dd550878f42cbc847e;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/src/mediawiki/mediawiki.js b/resources/src/mediawiki/mediawiki.js index e29c734d9b..cfdb5a712b 100644 --- a/resources/src/mediawiki/mediawiki.js +++ b/resources/src/mediawiki/mediawiki.js @@ -483,6 +483,12 @@ */ messages: new Map(), + /** + * Templates associated with a module + * @property {mw.Map} + */ + templates: new Map(), + /* Public Methods */ /** @@ -1170,6 +1176,11 @@ mw.messages.set( registry[module].messages ); } + // Initialise templates + if ( registry[module].templates ) { + mw.templates.set( module, registry[module].templates ); + } + if ( $.isReady || registry[module].async ) { // Make sure we don't run the scripts until all (potentially asynchronous) // stylesheet insertions have completed. @@ -1660,8 +1671,9 @@ * whether it's safe to extend the stylesheet (see #canExpandStylesheetWith). * * @param {Object} msgs List of key/value pairs to be added to mw#messages. + * @param {Object} [templates] List of key/value pairs to be added to mw#templates. */ - implement: function ( module, script, style, msgs ) { + implement: function ( module, script, style, msgs, templates ) { // Validate input if ( typeof module !== 'string' ) { throw new Error( 'module must be a string, not a ' + typeof module ); @@ -1675,6 +1687,9 @@ if ( !$.isPlainObject( msgs ) ) { throw new Error( 'msgs must be an object, not a ' + typeof msgs ); } + if ( templates !== undefined && !$.isPlainObject( templates ) ) { + throw new Error( 'templates must be an object, not a ' + typeof templates ); + } // Automatically register module if ( registry[module] === undefined ) { mw.loader.register( module ); @@ -1687,6 +1702,8 @@ registry[module].script = script; registry[module].style = style; registry[module].messages = msgs; + // Templates are optional (for back-compat) + registry[module].templates = templates || {}; // The module may already have been marked as erroneous if ( $.inArray( registry[module].state, ['error', 'missing'] ) === -1 ) { registry[module].state = 'loaded'; @@ -1710,6 +1727,7 @@ * @param {Function} [ready] Callback to execute when all dependencies are ready * @param {Function} [error] Callback to execute if one or more dependencies failed * @return {jQuery.Promise} + * @since 1.23 this returns a promise */ using: function ( dependencies, ready, error ) { var deferred = $.Deferred(); @@ -2057,7 +2075,8 @@ // Unversioned, private, or site-/user-specific ( !descriptor.version || $.inArray( descriptor.group, [ 'private', 'user', 'site' ] ) !== -1 ) || // Partial descriptor - $.inArray( undefined, [ descriptor.script, descriptor.style, descriptor.messages ] ) !== -1 + $.inArray( undefined, [ descriptor.script, descriptor.style, + descriptor.messages, descriptor.templates ] ) !== -1 ) { // Decline to store return false; @@ -2070,7 +2089,8 @@ String( descriptor.script ) : JSON.stringify( descriptor.script ), JSON.stringify( descriptor.style ), - JSON.stringify( descriptor.messages ) + JSON.stringify( descriptor.messages ), + JSON.stringify( descriptor.templates ) ]; // Attempted workaround for a possible Opera bug (bug 57567). // This regex should never match under sane conditions.