* @return array Array mapping module names to blobs
*/
private static function getFromDB( ResourceLoader $resourceLoader, $modules, $lang ) {
+ global $wgCacheEpoch;
$retval = array();
$dbr = wfGetDB( DB_SLAVE );
$res = $dbr->select( 'msg_resource',
// This shouldn't be possible
throw new MWException( __METHOD__ . ' passed an invalid module name' );
}
- if ( array_keys( FormatJson::decode( $row->mr_blob, true ) ) !== $module->getMessages() ) {
+ // Update the module's blobs if the set of messages changed or if the blob is
+ // older than $wgCacheEpoch
+ if ( array_keys( FormatJson::decode( $row->mr_blob, true ) ) !== $module->getMessages() ||
+ wfTimestamp( TS_MW, $row->mr_timestamp ) <= $wgCacheEpoch ) {
$retval[$row->mr_resource] = self::updateModule( $row->mr_resource, $lang );
} else {
$retval[$row->mr_resource] = $row->mr_blob;
* @param $context ResourceLoaderContext object
*/
public function respond( ResourceLoaderContext $context ) {
- global $wgResourceLoaderMaxage;
+ global $wgResourceLoaderMaxage, $wgCacheEpoch;
wfProfileIn( __METHOD__ );
// To send Last-Modified and support If-Modified-Since, we need to detect
// the last modified time
wfProfileIn( __METHOD__.'-getModifiedTime' );
- $mtime = 1;
+ $mtime = $wgCacheEpoch;
foreach ( $modules as $module ) {
// Bypass squid cache if the request includes any private modules
if ( $module->getGroup() === 'private' ) {
* @return String: JavaScript code for registering all modules with the client loader
*/
public static function getModuleRegistrations( ResourceLoaderContext $context ) {
+ global $wgCacheEpoch;
wfProfileIn( __METHOD__ );
$out = '';
}
// Automatically register module
else {
+ $mtime = max( $module->getModifiedTime( $context ), $wgCacheEpoch );
// Modules without dependencies or a group pass two arguments (name, timestamp) to
// mediaWiki.loader.register()
if ( !count( $module->getDependencies() && $module->getGroup() === null ) ) {
- $registrations[] = array( $name, $module->getModifiedTime( $context ) );
+ $registrations[] = array( $name, $mtime );
}
// Modules with dependencies but no group pass three arguments (name, timestamp, dependencies)
// to mediaWiki.loader.register()
else if ( $module->getGroup() === null ) {
$registrations[] = array(
- $name, $module->getModifiedTime( $context ), $module->getDependencies() );
+ $name, $mtime, $module->getDependencies() );
}
// Modules with dependencies pass four arguments (name, timestamp, dependencies, group)
// to mediaWiki.loader.register()
else {
$registrations[] = array(
- $name, $module->getModifiedTime( $context ), $module->getDependencies(), $module->getGroup() );
+ $name, $mtime, $module->getDependencies(), $module->getGroup() );
}
}
}
}
public function getModifiedTime( ResourceLoaderContext $context ) {
- global $IP;
+ global $IP, $wgCacheEpoch;
$hash = $context->getHash();
if ( isset( $this->modifiedTime[$hash] ) ) {
// ATTENTION!: Because of the line above, this is not going to cause infinite recursion - think carefully
// before making changes to this code!
- $time = 1; // wfTimestamp() treats 0 as 'now', so that's not a suitable choice
+ $time = $wgCacheEpoch;
foreach ( $context->getResourceLoader()->getModules() as $module ) {
$time = max( $time, $module->getModifiedTime( $context ) );
}