Index: branches/resourceloader/phase3/includes/ResourceLoader.php |
— | — | @@ -224,7 +224,9 @@ |
225 | 225 | // Calculate the mtime of this request. We need this, 304 or no 304 |
226 | 226 | $mtime = 1; |
227 | 227 | foreach ( $modules as $name ) { |
228 | | - $mtime = max( $mtime, self::getModule( $name )->getmtime() ); |
| 228 | + $mtime = max( $mtime, self::getModule( $name )->getmtime( |
| 229 | + $parameters['lang'], $parameters['skin'], $parameters['debug'] |
| 230 | + ) ); |
229 | 231 | } |
230 | 232 | header( 'Last-Modified: ' . wfTimestamp( TS_RFC2822, $mtime ) ); |
231 | 233 | |
Index: branches/resourceloader/phase3/includes/ResourceLoaderModule.php |
— | — | @@ -70,13 +70,13 @@ |
71 | 71 | $this->scripts = (array)$value; |
72 | 72 | break; |
73 | 73 | case 'styles': |
74 | | - $this->styles = $value; |
| 74 | + $this->styles = (array)$value; |
75 | 75 | break; |
76 | 76 | case 'messages': |
77 | | - $this->messages = $value; |
| 77 | + $this->messages = (array)$value; |
78 | 78 | break; |
79 | 79 | case 'dependencies': |
80 | | - $this->dependencies = $value; |
| 80 | + $this->dependencies = (array)$value; |
81 | 81 | break; |
82 | 82 | case 'debugScripts': |
83 | 83 | $this->debugScripts = (array)$value; |
— | — | @@ -269,13 +269,7 @@ |
270 | 270 | * @return string JS |
271 | 271 | */ |
272 | 272 | public function getSkinScript( $skin ) { |
273 | | - $scripts = array(); |
274 | | - if ( isset( $this->skinScripts[$skin] ) && count( $this->skinScripts[$skin] ) ) { |
275 | | - $scripts = $this->skinScripts[$skin]; |
276 | | - } else if ( isset( $this->skinScripts['default'] ) ) { |
277 | | - $scripts = $this->skinScripts['default']; |
278 | | - } |
279 | | - return self::concatScripts( $scripts ); |
| 273 | + return self::concatScripts( self::getSkinFiles( $skin, $this->skinScripts ) ); |
280 | 274 | } |
281 | 275 | |
282 | 276 | /** |
— | — | @@ -284,13 +278,23 @@ |
285 | 279 | * @return string CSS |
286 | 280 | */ |
287 | 281 | public function getSkinStyle( $skin ) { |
288 | | - $styles = array(); |
289 | | - if ( isset( $this->skinStyles[$skin] ) && count( $this->skinStyles[$skin] ) ) { |
290 | | - $styles = $this->skinStyles[$skin]; |
291 | | - } else if ( isset( $this->skinStyles['default'] ) ) { |
292 | | - $styles = $this->skinStyles['default']; |
| 282 | + return self::concatStyles( self::getSkinFiles( $skin, $this->skinStyles ) ); |
| 283 | + } |
| 284 | + |
| 285 | + /** |
| 286 | + * Helper function to get skin-specific data from an array. |
| 287 | + * @param $skin string Skin name |
| 288 | + * @param $map array Map of skin names to arrays |
| 289 | + * @return $map[$skin] if set and non-empty, or $map['default'] if set, or an empty array |
| 290 | + */ |
| 291 | + protected static function getSkinFiles( $skin, $map ) { |
| 292 | + $retval = array(); |
| 293 | + if ( isset( $map[$skin] ) && $map[$skin] ) { |
| 294 | + $retval = $map[$skin]; |
| 295 | + } else if ( isset( $map['default'] ) ) { |
| 296 | + $retval = $map['default']; |
293 | 297 | } |
294 | | - return self::concatStyles( $styles ); |
| 298 | + return $retval; |
295 | 299 | } |
296 | 300 | |
297 | 301 | /** |
— | — | @@ -305,25 +309,17 @@ |
306 | 310 | return self::concatScripts( $this->loaders ); |
307 | 311 | } |
308 | 312 | |
309 | | - public function getmtime() { |
310 | | - $fields = array( $this->scripts, $this->styles, $this->debugScripts, |
311 | | - $this->languageScripts, $this->skinScripts, $this->skinStyles, |
| 313 | + public function getmtime( $lang, $skin, $debug ) { |
| 314 | + $files = array_merge( $this->scripts, $this->styles, |
| 315 | + $debug ? $this->debugScripts : array(), |
| 316 | + isset( $this->languageScripts[$lang] ) ? (array)$this->languageScripts[$lang] : array(), |
| 317 | + (array)self::getSkinFiles( $skin, $this->skinScripts ), |
| 318 | + (array)self::getSkinFiles( $skin, $this->skinStyles ), |
312 | 319 | $this->loaders |
313 | 320 | ); |
314 | | - return self::getMaxMtime( $fields ); |
| 321 | + return max( array_map( 'filemtime', $files ) ); |
315 | 322 | } |
316 | 323 | |
317 | | - protected static function getMaxMtime( $arr ) { |
318 | | - if ( is_array( $arr ) ) { |
319 | | - if ( $arr ) { |
320 | | - return max( array_map( array( 'ResourceLoaderModule', 'getMaxMtime' ), $arr ) ); |
321 | | - } else { |
322 | | - return 1; // wfTimestamp() interprets 0 as "now" |
323 | | - } |
324 | | - } |
325 | | - return filemtime( $arr ); |
326 | | - } |
327 | | - |
328 | 324 | /** |
329 | 325 | * Get the contents of a set of files and concatenate them, with |
330 | 326 | * newlines in between. Each file is used only once. |
— | — | @@ -348,14 +344,13 @@ |
349 | 345 | return Skin::newFromKey( $skin )->generateUserJs(); |
350 | 346 | } |
351 | 347 | |
352 | | - public function getmtime() { |
| 348 | + public function getmtime( $lang, $skin, $debug ) { |
353 | 349 | // HACK: We duplicate the message names from generateUserJs() |
354 | 350 | // here and weird things (i.e. mtime moving backwards) can happen |
355 | 351 | // when a MediaWiki:Something.js page is deleted |
356 | | - $jsPages = array( Title::makeTitle( NS_MEDIAWIKI, 'Common.js' ) ); |
357 | | - foreach ( Skin::getSkinNames() as $skinname ) { |
358 | | - $jsPages[] = Title::makeTitleSafe( NS_MEDIAWIKI, ucfirst( $skinname) . '.js' ); |
359 | | - } |
| 352 | + $jsPages = array( Title::makeTitle( NS_MEDIAWIKI, 'Common.js' ), |
| 353 | + Title::makeTitle( NS_MEDIAWIKI, ucfirst( $skin ) . '.js' ) |
| 354 | + ); |
360 | 355 | |
361 | 356 | // Do batch existence check |
362 | 357 | // TODO: This would work better if page_touched were loaded by this as well |