r71703 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71702‎ | r71703 | r71704 >
Date:15:36, 26 August 2010
Author:catrope
Status:deferred
Tags:
Comment:
resourceloader: Implement getmtime(), will document later
Modified paths:
  • /branches/resourceloader/phase3/includes/ResourceLoaderModule.php (modified) (history)

Diff [purge]

Index: branches/resourceloader/phase3/includes/ResourceLoaderModule.php
@@ -305,6 +305,25 @@
306306 return self::concatScripts( $this->loaders );
307307 }
308308
 309+ public function getmtime() {
 310+ $fields = array( $this->scripts, $this->styles, $this->debugScripts,
 311+ $this->languageScripts, $this->skinScripts, $this->skinStyles,
 312+ $this->loaders
 313+ );
 314+ return self::getMaxMtime( $fields );
 315+ }
 316+
 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+
309328 /**
310329 * Get the contents of a set of files and concatenate them, with
311330 * newlines in between. Each file is used only once.
@@ -329,6 +348,29 @@
330349 return Skin::newFromKey( $skin )->generateUserJs();
331350 }
332351
 352+ public function getmtime() {
 353+ // HACK: We duplicate the message names from generateUserJs()
 354+ // here and weird things (i.e. mtime moving backwards) can happen
 355+ // 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+ }
 360+
 361+ // Do batch existence check
 362+ // TODO: This would work better if page_touched were loaded by this as well
 363+ $lb = new LinkBatch( $jsPages );
 364+ $lb->execute();
 365+
 366+ $retval = 1; // wfTimestamp() interprets 0 as "now"
 367+ foreach ( $jsPages as $jsPage ) {
 368+ if ( $jsPage->exists() ) {
 369+ $retval = max( $retval, $jsPage->getTouched() );
 370+ }
 371+ }
 372+ return $retval;
 373+ }
 374+
333375 // Dummy overrides to return emptyness
334376 public function getScript() { return ''; }
335377 public function getStyle() { return ''; }

Status & tagging log