Add a note when the return value was added to mediawiki.loader.using
[lhc/web/wiklou.git] / resources / src / mediawiki / mediawiki.js
index e29c734..cfdb5a7 100644 (file)
                 */
                messages: new Map(),
 
+               /**
+                * Templates associated with a module
+                * @property {mw.Map}
+                */
+               templates: new Map(),
+
                /* Public Methods */
 
                /**
                                        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.
                                 * 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 );
                                        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 );
                                        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';
                                 * @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();
                                                        // 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;
                                                                        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.