foreach ( array_keys( $modulesWithoutMessages ) as $name ) {
$module = $this->getModule( $name );
if ( $module ) {
- $module->setMsgBlobMtime( $lang, 0 );
+ $module->setMsgBlobMtime( $lang, 1 );
}
}
}
ResourceLoader::inDebugMode()
);
} else {
- $version = (int)$version > 1 ? (int)$version : 1;
+ $version = (int) $version;
return Xml::encodeJsCall(
'mw.loader.register',
array( $name, $version, $dependencies, $group, $source, $skip ),
* Get the last modification timestamp of the message blob for this
* module in a given language.
* @param string $lang Language code
- * @return int UNIX timestamp, or 0 if the module doesn't have messages
+ * @return int UNIX timestamp
*/
public function getMsgBlobMtime( $lang ) {
if ( !isset( $this->msgBlobMtime[$lang] ) ) {
if ( !count( $this->getMessages() ) ) {
- return 0;
+ return 1;
}
$dbr = wfGetDB( DB_SLAVE );
* Set a preloaded message blob last modification timestamp. Used so we
* can load this information for all modules at once.
* @param string $lang Language code
- * @param int $mtime UNIX timestamp or 0 if there is no such blob
+ * @param int $mtime UNIX timestamp
*/
public function setMsgBlobMtime( $lang, $mtime ) {
$this->msgBlobMtime[$lang] = $mtime;
* @return int UNIX timestamp
*/
public function getModifiedTime( ResourceLoaderContext $context ) {
- // 0 would mean now
return 1;
}
* Helper method for calculating when the module's hash (if it has one) changed.
*
* @param ResourceLoaderContext $context
- * @return int UNIX timestamp or 0 if no hash was provided
- * by getModifiedHash()
+ * @return int UNIX timestamp
*/
public function getHashMtime( ResourceLoaderContext $context ) {
$hash = $this->getModifiedHash( $context );
if ( !is_string( $hash ) ) {
- return 0;
+ return 1;
}
$cache = wfGetCache( CACHE_ANYTHING );
return $data['timestamp'];
}
- $timestamp = wfTimestamp();
+ $timestamp = time();
$cache->set( $key, array(
'hash' => $hash,
'timestamp' => $timestamp,
* @since 1.23
*
* @param ResourceLoaderContext $context
- * @return int UNIX timestamp or 0 if no definition summary was provided
- * by getDefinitionSummary()
+ * @return int UNIX timestamp
*/
public function getDefinitionMtime( ResourceLoaderContext $context ) {
wfProfileIn( __METHOD__ );
$summary = $this->getDefinitionSummary( $context );
if ( $summary === null ) {
wfProfileOut( __METHOD__ );
- return 0;
+ return 1;
}
$hash = md5( json_encode( $summary ) );
* Safe version of filemtime(), which doesn't throw a PHP warning if the file doesn't exist
* but returns 1 instead.
* @param string $filename File name
- * @return int UNIX timestamp, or 1 if the file doesn't exist
+ * @return int UNIX timestamp
*/
protected static function safeFilemtime( $filename ) {
- if ( file_exists( $filename ) ) {
- return filemtime( $filename );
- } else {
- // We only ever map this function on an array if we're gonna call max() after,
- // so return our standard minimum timestamps here. This is 1, not 0, because
- // wfTimestamp(0) == NOW
+ if ( !file_exists( $filename ) ) {
return 1;
}
+ return filemtime( $filename );
}
}
continue;
}
- // getModifiedTime() is supposed to return a UNIX timestamp, but it doesn't always
- // seem to do that, and custom implementations might forget. Coerce it to TS_UNIX
+ // Coerce module timestamp to UNIX timestamp.
+ // getModifiedTime() is supposed to return a UNIX timestamp, but custom implementations
+ // might forget. TODO: Maybe emit warning?
$moduleMtime = wfTimestamp( TS_UNIX, $module->getModifiedTime( $context ) );
- $mtime = max( $moduleMtime, wfTimestamp( TS_UNIX, $this->getConfig()->get( 'CacheEpoch' ) ) );
-
- // FIXME: Convert to numbers, wfTimestamp always gives us stings, even for TS_UNIX
$skipFunction = $module->getSkipFunction();
if ( $skipFunction !== null && !ResourceLoader::inDebugMode() ) {
);
}
+ $mtime = max(
+ $moduleMtime,
+ wfTimestamp( TS_UNIX, $this->getConfig()->get( 'CacheEpoch' ) )
+ );
+
$registryData[$name] = array(
- 'version' => $mtime,
+ // Convert to numbers as wfTimestamp always returns a string, even for TS_UNIX
+ 'version' => (int) $mtime,
'dependencies' => $module->getDependencies(),
'group' => $module->getGroup(),
'source' => $module->getSource(),
// Get the latest version
$loader = $context->getResourceLoader();
- $version = 0;
+ $version = 1;
foreach ( $moduleNames as $moduleName ) {
$version = max( $version,
$loader->getModule( $moduleName )->getModifiedTime( $context )
/**
* @param ResourceLoaderContext $context
- * @return array|int|mixed
+ * @return int
*/
public function getModifiedTime( ResourceLoaderContext $context ) {
return $this->getHashMtime( $context );
/**
* @param ResourceLoaderContext $context
- * @return array|int|mixed
+ * @return int
*/
public function getModifiedTime( ResourceLoaderContext $context ) {
$hash = $context->getHash();
/**
* @param ResourceLoaderContext $context
- * @return int|mixed
+ * @return int
*/
public function getModifiedTime( ResourceLoaderContext $context ) {
- $modifiedTime = 1; // wfTimestamp() interprets 0 as "now"
+ $modifiedTime = 1;
$titleInfo = $this->getTitleInfo( $context );
if ( count( $titleInfo ) ) {
$mtimes = array_map( function ( $value ) {
* Get the modification times of all titles that would be loaded for
* a given context.
* @param ResourceLoaderContext $context Context object
- * @return array keyed by page dbkey, with value is an array with 'length' and 'timestamp'
- * keys, where the timestamp is a unix one
+ * @return array Keyed by page dbkey. Value is an array with 'length' and 'timestamp'
+ * keys, where the timestamp is a UNIX timestamp
*/
protected function getTitleInfo( ResourceLoaderContext $context ) {
$dbr = $this->getDB();
}
/**
- * Generates an ISO8601 "basic" string from a UNIX timestamp
+ * Convert UNIX timestamp to ISO8601 format
+ * @param {number} timestamp UNIX timestamp
* @private
*/
function formatVersionNumber( timestamp ) {
/**
* 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;
},
/**
} );mw.loader.register( [
[
"test.blank",
- "1388534400"
+ 1388534400
]
] );',
) ),
} );mw.loader.register( [
[
"test.blank",
- "1388534400"
+ 1388534400
],
[
"test.group.foo",
- "1388534400",
+ 1388534400,
[],
"x-foo"
],
[
"test.group.bar",
- "1388534400",
+ 1388534400,
[],
"x-bar"
]
} );mw.loader.register( [
[
"test.blank",
- "1388534400"
+ 1388534400
]
] );'
) ),
} );mw.loader.register( [
[
"test.blank",
- "1388534400",
+ 1388534400,
[],
null,
"example"
} );mw.loader.register( [
[
"test.x.core",
- "1388534400"
+ 1388534400
],
[
"test.x.polyfill",
- "1388534400",
+ 1388534400,
[],
null,
"local",
],
[
"test.y.polyfill",
- "1388534400",
+ 1388534400,
[],
null,
"local",
],
[
"test.z.foo",
- "1388534400",
+ 1388534400,
[
"test.x.core",
"test.x.polyfil",
} );mw.loader.register( [
[
"test.blank",
- "1388534400"
+ 1388534400
],
[
"test.x.core",
- "1388534400"
+ 1388534400
],
[
"test.x.util",
- "1388534400",
+ 1388534400,
[
"test.x.core"
]
],
[
"test.x.foo",
- "1388534400",
+ 1388534400,
[
"test.x.core"
]
],
[
"test.x.bar",
- "1388534400",
+ 1388534400,
[
"test.x.util"
]
],
[
"test.x.quux",
- "1388534400",
+ 1388534400,
[
"test.x.foo",
"test.x.bar",
],
[
"test.group.foo.1",
- "1388534400",
+ 1388534400,
[],
"x-foo"
],
[
"test.group.foo.2",
- "1388534400",
+ 1388534400,
[],
"x-foo"
],
[
"test.group.bar.1",
- "1388534400",
+ 1388534400,
[],
"x-bar"
],
[
"test.group.bar.2",
- "1388534400",
+ 1388534400,
[],
"x-bar",
"example"
$this->assertEquals(
'mw.loader.addSource({"local":"/w/load.php"});'
. 'mw.loader.register(['
-. '["test.blank","1388534400"],'
-. '["test.min","1388534400",["test.blank"],null,"local",'
+. '["test.blank",1388534400],'
+. '["test.min",1388534400,["test.blank"],null,"local",'
. '"return!!(window.JSON\u0026\u0026JSON.parse\u0026\u0026JSON.stringify);"'
. ']]);',
$module->getModuleRegistrations( $context ),
} );mw.loader.register( [
[
"test.blank",
- "1388534400"
+ 1388534400
],
[
"test.min",
- "1388534400",
+ 1388534400,
[
"test.blank"
],