Index: trunk/phase3/includes/ResourceLoader.php |
— | — | @@ -240,7 +240,7 @@ |
241 | 241 | * @param $context ResourceLoaderContext object |
242 | 242 | */ |
243 | 243 | public function respond( ResourceLoaderContext $context ) { |
244 | | - global $wgResourceLoaderMaxage; |
| 244 | + global $wgResourceLoaderMaxage, $wgCacheEpoch; |
245 | 245 | |
246 | 246 | wfProfileIn( __METHOD__ ); |
247 | 247 | |
— | — | @@ -275,7 +275,7 @@ |
276 | 276 | // To send Last-Modified and support If-Modified-Since, we need to detect |
277 | 277 | // the last modified time |
278 | 278 | wfProfileIn( __METHOD__.'-getModifiedTime' ); |
279 | | - $mtime = 1; |
| 279 | + $mtime = $wgCacheEpoch; |
280 | 280 | foreach ( $modules as $module ) { |
281 | 281 | // Bypass squid cache if the request includes any private modules |
282 | 282 | if ( $module->getGroup() === 'private' ) { |
Index: trunk/phase3/includes/MessageBlobStore.php |
— | — | @@ -311,6 +311,7 @@ |
312 | 312 | * @return array Array mapping module names to blobs |
313 | 313 | */ |
314 | 314 | private static function getFromDB( ResourceLoader $resourceLoader, $modules, $lang ) { |
| 315 | + global $wgCacheEpoch; |
315 | 316 | $retval = array(); |
316 | 317 | $dbr = wfGetDB( DB_SLAVE ); |
317 | 318 | $res = $dbr->select( 'msg_resource', |
— | — | @@ -325,7 +326,10 @@ |
326 | 327 | // This shouldn't be possible |
327 | 328 | throw new MWException( __METHOD__ . ' passed an invalid module name' ); |
328 | 329 | } |
329 | | - if ( array_keys( FormatJson::decode( $row->mr_blob, true ) ) !== $module->getMessages() ) { |
| 330 | + // Update the module's blobs if the set of messages changed or if the blob is |
| 331 | + // older than $wgCacheEpoch |
| 332 | + if ( array_keys( FormatJson::decode( $row->mr_blob, true ) ) !== $module->getMessages() || |
| 333 | + wfTimestamp( TS_MW, $row->mr_timestamp ) <= $wgCacheEpoch ) { |
330 | 334 | $retval[$row->mr_resource] = self::updateModule( $row->mr_resource, $lang ); |
331 | 335 | } else { |
332 | 336 | $retval[$row->mr_resource] = $row->mr_blob; |
Index: trunk/phase3/includes/ResourceLoaderModule.php |
— | — | @@ -1059,6 +1059,7 @@ |
1060 | 1060 | * @return String: JavaScript code for registering all modules with the client loader |
1061 | 1061 | */ |
1062 | 1062 | public static function getModuleRegistrations( ResourceLoaderContext $context ) { |
| 1063 | + global $wgCacheEpoch; |
1063 | 1064 | wfProfileIn( __METHOD__ ); |
1064 | 1065 | |
1065 | 1066 | $out = ''; |
— | — | @@ -1073,22 +1074,23 @@ |
1074 | 1075 | } |
1075 | 1076 | // Automatically register module |
1076 | 1077 | else { |
| 1078 | + $mtime = max( $module->getModifiedTime( $context ), $wgCacheEpoch ); |
1077 | 1079 | // Modules without dependencies or a group pass two arguments (name, timestamp) to |
1078 | 1080 | // mediaWiki.loader.register() |
1079 | 1081 | if ( !count( $module->getDependencies() && $module->getGroup() === null ) ) { |
1080 | | - $registrations[] = array( $name, $module->getModifiedTime( $context ) ); |
| 1082 | + $registrations[] = array( $name, $mtime ); |
1081 | 1083 | } |
1082 | 1084 | // Modules with dependencies but no group pass three arguments (name, timestamp, dependencies) |
1083 | 1085 | // to mediaWiki.loader.register() |
1084 | 1086 | else if ( $module->getGroup() === null ) { |
1085 | 1087 | $registrations[] = array( |
1086 | | - $name, $module->getModifiedTime( $context ), $module->getDependencies() ); |
| 1088 | + $name, $mtime, $module->getDependencies() ); |
1087 | 1089 | } |
1088 | 1090 | // Modules with dependencies pass four arguments (name, timestamp, dependencies, group) |
1089 | 1091 | // to mediaWiki.loader.register() |
1090 | 1092 | else { |
1091 | 1093 | $registrations[] = array( |
1092 | | - $name, $module->getModifiedTime( $context ), $module->getDependencies(), $module->getGroup() ); |
| 1094 | + $name, $mtime, $module->getDependencies(), $module->getGroup() ); |
1093 | 1095 | } |
1094 | 1096 | } |
1095 | 1097 | } |
— | — | @@ -1134,7 +1136,7 @@ |
1135 | 1137 | } |
1136 | 1138 | |
1137 | 1139 | public function getModifiedTime( ResourceLoaderContext $context ) { |
1138 | | - global $IP; |
| 1140 | + global $IP, $wgCacheEpoch; |
1139 | 1141 | |
1140 | 1142 | $hash = $context->getHash(); |
1141 | 1143 | if ( isset( $this->modifiedTime[$hash] ) ) { |
— | — | @@ -1144,7 +1146,7 @@ |
1145 | 1147 | |
1146 | 1148 | // ATTENTION!: Because of the line above, this is not going to cause infinite recursion - think carefully |
1147 | 1149 | // before making changes to this code! |
1148 | | - $time = 1; // wfTimestamp() treats 0 as 'now', so that's not a suitable choice |
| 1150 | + $time = $wgCacheEpoch; |
1149 | 1151 | foreach ( $context->getResourceLoader()->getModules() as $module ) { |
1150 | 1152 | $time = max( $time, $module->getModifiedTime( $context ) ); |
1151 | 1153 | } |