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/ResourceLoaderFileModule.php | |
parent | 6ca0c5e0a943b64b4e3d0a11a80c5679f7252e64 (diff) |
Update to MediaWiki 1.17.1
Diffstat (limited to 'includes/resourceloader/ResourceLoaderFileModule.php')
-rw-r--r-- | includes/resourceloader/ResourceLoaderFileModule.php | 46 |
1 files changed, 40 insertions, 6 deletions
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'; + } } |