r71824 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71823‎ | r71824 | r71825 >
Date:23:31, 27 August 2010
Author:catrope
Status:deferred
Tags:
Comment:
resourceloader: When calculating mtimes, be more restrictive and only include the files actually used for a given request, based on language, skin and debug/non-debug mode.
Modified paths:
  • /branches/resourceloader/phase3/includes/ResourceLoader.php (modified) (history)
  • /branches/resourceloader/phase3/includes/ResourceLoaderModule.php (modified) (history)

Diff [purge]

Index: branches/resourceloader/phase3/includes/ResourceLoader.php
@@ -224,7 +224,9 @@
225225 // Calculate the mtime of this request. We need this, 304 or no 304
226226 $mtime = 1;
227227 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+ ) );
229231 }
230232 header( 'Last-Modified: ' . wfTimestamp( TS_RFC2822, $mtime ) );
231233
Index: branches/resourceloader/phase3/includes/ResourceLoaderModule.php
@@ -70,13 +70,13 @@
7171 $this->scripts = (array)$value;
7272 break;
7373 case 'styles':
74 - $this->styles = $value;
 74+ $this->styles = (array)$value;
7575 break;
7676 case 'messages':
77 - $this->messages = $value;
 77+ $this->messages = (array)$value;
7878 break;
7979 case 'dependencies':
80 - $this->dependencies = $value;
 80+ $this->dependencies = (array)$value;
8181 break;
8282 case 'debugScripts':
8383 $this->debugScripts = (array)$value;
@@ -269,13 +269,7 @@
270270 * @return string JS
271271 */
272272 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 ) );
280274 }
281275
282276 /**
@@ -284,13 +278,23 @@
285279 * @return string CSS
286280 */
287281 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'];
293297 }
294 - return self::concatStyles( $styles );
 298+ return $retval;
295299 }
296300
297301 /**
@@ -305,25 +309,17 @@
306310 return self::concatScripts( $this->loaders );
307311 }
308312
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 ),
312319 $this->loaders
313320 );
314 - return self::getMaxMtime( $fields );
 321+ return max( array_map( 'filemtime', $files ) );
315322 }
316323
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 -
328324 /**
329325 * Get the contents of a set of files and concatenate them, with
330326 * newlines in between. Each file is used only once.
@@ -348,14 +344,13 @@
349345 return Skin::newFromKey( $skin )->generateUserJs();
350346 }
351347
352 - public function getmtime() {
 348+ public function getmtime( $lang, $skin, $debug ) {
353349 // HACK: We duplicate the message names from generateUserJs()
354350 // here and weird things (i.e. mtime moving backwards) can happen
355351 // 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+ );
360355
361356 // Do batch existence check
362357 // TODO: This would work better if page_touched were loaded by this as well

Status & tagging log