Merge "Convert article delete to use OOUI"
[lhc/web/wiklou.git] / includes / utils / FileContentsHasher.php
index 655c1d0..afe9c0a 100644 (file)
@@ -27,11 +27,8 @@ class FileContentsHasher {
        /** @var FileContentsHasher */
        private static $instance;
 
-       /**
-        * Constructor.
-        */
        public function __construct() {
-               $this->cache = ObjectCache::newAccelerator( 'hash' );
+               $this->cache = ObjectCache::getLocalServerInstance( 'hash' );
        }
 
        /**
@@ -57,19 +54,19 @@ class FileContentsHasher {
         * @return string|bool Hash of file contents, or false if the file could not be read.
         */
        public function getFileContentsHashInternal( $filePath, $algo = 'md4' ) {
-               $mtime = MediaWiki\quietCall( 'filemtime', $filePath );
+               $mtime = filemtime( $filePath );
                if ( $mtime === false ) {
                        return false;
                }
 
-               $cacheKey = wfGlobalCacheKey( __CLASS__, $filePath, $mtime, $algo );
+               $cacheKey = $this->cache->makeGlobalKey( __CLASS__, $filePath, $mtime, $algo );
                $hash = $this->cache->get( $cacheKey );
 
                if ( $hash ) {
                        return $hash;
                }
 
-               $contents = MediaWiki\quietCall( 'file_get_contents', $filePath );
+               $contents = file_get_contents( $filePath );
                if ( $contents === false ) {
                        return false;
                }
@@ -96,8 +93,12 @@ class FileContentsHasher {
                        $filePaths = (array)$filePaths;
                }
 
+               MediaWiki\suppressWarnings();
+
                if ( count( $filePaths ) === 1 ) {
-                       return $instance->getFileContentsHashInternal( $filePaths[0], $algo );
+                       $hash = $instance->getFileContentsHashInternal( $filePaths[0], $algo );
+                       MediaWiki\restoreWarnings();
+                       return $hash;
                }
 
                sort( $filePaths );
@@ -105,6 +106,8 @@ class FileContentsHasher {
                        return $instance->getFileContentsHashInternal( $filePath, $algo ) ?: '';
                }, $filePaths );
 
+               MediaWiki\restoreWarnings();
+
                $hashes = implode( '', $hashes );
                return $hashes ? hash( $algo, $hashes ) : false;
        }