resourceloader: Use FileContentsHasher in safeFileHash()
authorOri Livneh <ori@wikimedia.org>
Wed, 23 Sep 2015 08:11:58 +0000 (01:11 -0700)
committerKrinkle <krinklemail@gmail.com>
Thu, 24 Sep 2015 00:49:59 +0000 (00:49 +0000)
Replace the one-off code for APC-assisted file content hashing from I5ceb8537c
with a call to the FileContentsHasher class introduced in I1ff61153.

Change-Id: I8e4c3d5a5e7cdf6455a43769261d742b0255622c

includes/resourceloader/ResourceLoaderModule.php

index 1d3ffb5..376b62c 100644 (file)
@@ -857,35 +857,6 @@ abstract class ResourceLoaderModule {
         * @return string Hash
         */
        protected static function safeFileHash( $filePath ) {
-               static $cache;
-
-               if ( !$cache ) {
-                       $cache = ObjectCache::newAccelerator( CACHE_NONE );
-               }
-
-               MediaWiki\suppressWarnings();
-               $mtime = filemtime( $filePath );
-               MediaWiki\restoreWarnings();
-               if ( !$mtime ) {
-                       return '';
-               }
-
-               $cacheKey = wfGlobalCacheKey( 'resourceloader', __METHOD__, $filePath );
-               $cachedHash = $cache->get( $cacheKey );
-               if ( isset( $cachedHash['mtime'] ) && $cachedHash['mtime'] === $mtime ) {
-                       return $cachedHash['hash'];
-               }
-
-               MediaWiki\suppressWarnings();
-               $contents = file_get_contents( $filePath );
-               MediaWiki\restoreWarnings();
-               if ( !$contents ) {
-                       return '';
-               }
-
-               $hash = hash( 'md4', $contents );
-               $cache->set( $cacheKey, array( 'mtime' => $mtime, 'hash' => $hash ), 60 * 60 * 24 );
-
-               return $hash;
+               return FileContentsHasher::getFileContentsHash( $filePath );
        }
 }