diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2011-12-03 09:20:55 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2011-12-03 09:20:55 +0100 |
commit | a22fbfc60f36f5f7ee10d5ae6fe347340c2ee67c (patch) | |
tree | 31882fdc36540fecfd62e5011fc38515e504a3db /includes/resourceloader | |
parent | 6ca0c5e0a943b64b4e3d0a11a80c5679f7252e64 (diff) |
Update to MediaWiki 1.17.1
Diffstat (limited to 'includes/resourceloader')
4 files changed, 47 insertions, 9 deletions
diff --git a/includes/resourceloader/ResourceLoader.php b/includes/resourceloader/ResourceLoader.php index c18022a4..191bc9f0 100644 --- a/includes/resourceloader/ResourceLoader.php +++ b/includes/resourceloader/ResourceLoader.php @@ -96,7 +96,8 @@ class ResourceLoader { ), __METHOD__ ); foreach ( $res as $row ) { - $this->getModule( $row->mr_resource )->setMsgBlobMtime( $lang, $row->mr_timestamp ); + $this->getModule( $row->mr_resource )->setMsgBlobMtime( $lang, + wfTimestamp( TS_UNIX, $row->mr_timestamp ) ); unset( $modulesWithoutMessages[$row->mr_resource] ); } } diff --git a/includes/resourceloader/ResourceLoaderFileModule.php b/includes/resourceloader/ResourceLoaderFileModule.php index 44967a2e..1c37eb07 100644 --- a/includes/resourceloader/ResourceLoaderFileModule.php +++ b/includes/resourceloader/ResourceLoaderFileModule.php @@ -360,7 +360,7 @@ class ResourceLoaderFileModule extends ResourceLoaderModule { } wfProfileIn( __METHOD__.'-filemtime' ); - $filesMtime = max( array_map( 'filemtime', $files ) ); + $filesMtime = max( array_map( array( __CLASS__, 'safeFilemtime' ), $files ) ); wfProfileOut( __METHOD__.'-filemtime' ); $this->modifiedTime[$context->getHash()] = max( $filesMtime, @@ -441,13 +441,20 @@ class ResourceLoaderFileModule extends ResourceLoaderModule { if ( empty( $scripts ) ) { return ''; } + global $wgResourceLoaderValidateStaticJS; $js = ''; foreach ( array_unique( $scripts ) as $fileName ) { $localPath = $this->getLocalPath( $fileName ); - $contents = file_get_contents( $localPath ); - if ( $contents === false ) { + if ( !file_exists( $localPath ) ) { throw new MWException( __METHOD__.": script file not found: \"$localPath\"" ); } + $contents = file_get_contents( $localPath ); + if ( $wgResourceLoaderValidateStaticJS ) { + // Static files don't really need to be checked as often; unlike + // on-wiki module they shouldn't change unexpectedly without + // admin interference. + $contents = $this->validateScriptFile( $fileName, $contents ); + } $js .= $contents . "\n"; } return $js; @@ -484,15 +491,16 @@ class ResourceLoaderFileModule extends ResourceLoaderModule { * * This method can be used as a callback for array_map() * - * @param $path String: File path of script file to read + * @param $path String: File path of style file to read * @return String: CSS data in script file + * @throws MWException if the file doesn't exist */ protected function readStyleFile( $path, $flip ) { $localPath = $this->getLocalPath( $path ); - $style = file_get_contents( $localPath ); - if ( $style === false ) { + if ( !file_exists( $localPath ) ) { throw new MWException( __METHOD__.": style file not found: \"$localPath\"" ); } + $style = file_get_contents( $localPath ); if ( $flip ) { $style = CSSJanus::transform( $style, true, false ); } @@ -506,4 +514,30 @@ class ResourceLoaderFileModule extends ResourceLoaderModule { $style, $dir, $remoteDir, true ); } + + /** + * Safe version of filemtime(), which doesn't throw a PHP warning if the file doesn't exist + * but returns 1 instead. + * @param $filename string File name + * @return int UNIX timestamp, or 1 if the file doesn't exist + */ + protected static function safeFilemtime( $filename ) { + if ( file_exists( $filename ) ) { + return filemtime( $filename ); + } else { + // We only ever map this function on an array if we're gonna call max() after, + // so return our standard minimum timestamps here. This is 1, not 0, because + // wfTimestamp(0) == NOW + return 1; + } + } + + /** + * Get whether CSS for this module should be flipped + * @param $context ResourceLoaderContext + * @return bool + */ + public function getFlip( $context ) { + return $context->getDirection() === 'rtl'; + } } diff --git a/includes/resourceloader/ResourceLoaderStartUpModule.php b/includes/resourceloader/ResourceLoaderStartUpModule.php index 2a3ba343..f3117378 100644 --- a/includes/resourceloader/ResourceLoaderStartUpModule.php +++ b/includes/resourceloader/ResourceLoaderStartUpModule.php @@ -119,7 +119,10 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule { } // Automatically register module else { - $mtime = max( $module->getModifiedTime( $context ), wfTimestamp( TS_UNIX, $wgCacheEpoch ) ); + // getModifiedTime() is supposed to return a UNIX timestamp, but it doesn't always + // seem to do that, and custom implementations might forget. Coerce it to TS_UNIX + $moduleMtime = wfTimestamp( TS_UNIX, $module->getModifiedTime( $context ) ); + $mtime = max( $moduleMtime, wfTimestamp( TS_UNIX, $wgCacheEpoch ) ); // Modules without dependencies or a group pass two arguments (name, timestamp) to // mediaWiki.loader.register() if ( !count( $module->getDependencies() && $module->getGroup() === null ) ) { diff --git a/includes/resourceloader/ResourceLoaderUserOptionsModule.php b/includes/resourceloader/ResourceLoaderUserOptionsModule.php index ae654b8f..61c76940 100644 --- a/includes/resourceloader/ResourceLoaderUserOptionsModule.php +++ b/includes/resourceloader/ResourceLoaderUserOptionsModule.php @@ -40,7 +40,7 @@ class ResourceLoaderUserOptionsModule extends ResourceLoaderModule { global $wgUser; if ( $context->getUser() === $wgUser->getName() ) { - return $this->modifiedTime[$hash] = $wgUser->getTouched(); + return $this->modifiedTime[$hash] = wfTimestamp( TS_UNIX, $wgUser->getTouched() ); } else { return 1; } |