}
/**
- * Generates an ISO8601 "basic" string from a UNIX timestamp
+ * Convert UNIX timestamp to ISO8601 format
+ * @param {number} timestamp UNIX timestamp
* @private
*/
function formatVersionNumber( timestamp ) {
*/
function execute( module ) {
var key, value, media, i, urls, cssHandle, checkCssHandles,
- templates = {},
cssHandlesRegistered = false;
if ( registry[module] === undefined ) {
}
// Initialise templates
- if ( !$.isEmptyObject( registry[module].templates ) ) {
- templates[module] = registry[module].templates;
- mw.templates.set( templates );
+ if ( registry[module].templates ) {
+ mw.templates.set( module, registry[module].templates );
}
if ( $.isReady || registry[module].async ) {
* 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 (optional)
+ * @param {Object} [templates] List of key/value pairs to be added to mw#templates.
*/
implement: function ( module, script, style, msgs, templates ) {
// Validate input
if ( !$.isPlainObject( msgs ) ) {
throw new Error( 'msgs must be an object, not a ' + typeof msgs );
}
- if ( templates && !$.isPlainObject( templates ) ) {
+ if ( templates !== undefined && !$.isPlainObject( templates ) ) {
throw new Error( 'templates must be an object, not a ' + typeof templates );
}
// Automatically register module
registry[module].script = script;
registry[module].style = style;
registry[module].messages = msgs;
- registry[module].templates = templates;
+ // 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();
/**
* Get the version of a module.
*
- * @param {string} module Name of module to get version for
+ * @param {string} module Name of module
* @return {string|null} The version, or null if the module (or its version) is not
* in the registry.
*/
getVersion: function ( module ) {
- if ( registry[module] !== undefined && registry[module].version !== undefined ) {
- return formatVersionNumber( registry[module].version );
+ if ( !registry[module] || registry[module].version === undefined ) {
+ return null;
}
- return null;
+ return formatVersionNumber( registry[module].version );
},
/**
* Get the state of a module.
*
- * @param {string} module Name of module to get state for
+ * @param {string} module Name of module
+ * @return {string|null} The state, or null if the module (or its version) is not
+ * in the registry.
*/
getState: function ( module ) {
- if ( registry[module] !== undefined && registry[module].state !== undefined ) {
- return registry[module].state;
+ if ( !registry[module] || registry[module].state === undefined ) {
+ return null;
}
- return null;
+ return registry[module].state;
},
/**
return;
}
- if ( !mw.config.get( 'wgResourceLoaderStorageEnabled' ) || mw.config.get( 'debug' ) ) {
- // Disabled by configuration, or because debug mode is set
+ if ( !mw.config.get( 'wgResourceLoaderStorageEnabled' ) ) {
+ // Disabled by configuration.
+ // Clear any previous store to free up space. (T66721)
+ mw.loader.store.clear();
+ mw.loader.store.enabled = false;
+ return;
+ }
+ if ( mw.config.get( 'debug' ) ) {
+ // Disable module store in debug mode
mw.loader.store.enabled = false;
return;
}
// 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.