diff --git a/includes/resourceloader/ResourceLoaderFileModule.php b/includes/resourceloader/ResourceLoaderFileModule.php index bed2d56e125..fe1f27aa4af 100644 --- a/includes/resourceloader/ResourceLoaderFileModule.php +++ b/includes/resourceloader/ResourceLoaderFileModule.php @@ -530,7 +530,7 @@ class ResourceLoaderFileModule extends ResourceLoaderModule { * * @see ResourceLoaderModule::getFileDependencies * @param ResourceLoaderContext $context - * @return array + * @return string */ private function getFileHashes( ResourceLoaderContext $context ) { $files = []; @@ -590,15 +590,11 @@ class ResourceLoaderFileModule extends ResourceLoaderModule { // includes the entry point LESS file that we already have as a master file. $files = array_unique( $files ); - $hashes = []; - foreach ( $files as $file ) { - // Don't include array keys or any other form of file path here, only the hashes. - // Including file paths would needlessly cause global cache invalidation when files - // move on disk or if e.g. the MediaWiki directory name changes. - // Anything where order is significant is already detected by the definition summary. - $hashes[] = ResourceLoaderModule::safeFileHash( $file ); - } - return $hashes; + // Don't return array keys or any other form of file path here, only the hashes. + // Including file paths would needlessly cause global cache invalidation when files + // move on disk or if e.g. the MediaWiki directory name changes. + // Anything where order is significant is already detected by the definition summary. + return FileContentsHasher::getFileContentsHash( $files ); } /** @@ -640,9 +636,9 @@ class ResourceLoaderFileModule extends ResourceLoaderModule { // - The 'files' array, simplied to only which files exist (the keys of // this array), and something that represents their non-file content. // For packaged files that reflect files directly from disk, the - // 'getFileHashes' method tracks this already. - // It is important that the keys of the 'files' array are preserved, - // as they affect the module output. + // 'getFileHashes' method tracks their content already. + // It is important that the keys of the $packageFiles['files'] array + // are preserved, as they do affect the module output. $packageFiles['files'] = array_map( function ( $fileInfo ) { return $fileInfo['definitionSummary'] ?? ( $fileInfo['content'] ?? null ); }, $packageFiles['files'] ); diff --git a/includes/utils/FileContentsHasher.php b/includes/utils/FileContentsHasher.php index e390f217c74..5343bcb54b5 100644 --- a/includes/utils/FileContentsHasher.php +++ b/includes/utils/FileContentsHasher.php @@ -48,12 +48,11 @@ class FileContentsHasher { * Get a hash of a file's contents, either by retrieving a previously- * computed hash from the cache, or by computing a hash from the file. * - * @private * @param string $filePath Full path to the file. * @param string $algo Name of selected hashing algorithm. * @return string|bool Hash of file contents, or false if the file could not be read. */ - public function getFileContentsHashInternal( $filePath, $algo = 'md4' ) { + private function getFileContentsHashInternal( $filePath, $algo = 'md4' ) { $mtime = filemtime( $filePath ); if ( $mtime === false ) { return false; @@ -102,9 +101,10 @@ class FileContentsHasher { } sort( $filePaths ); - $hashes = array_map( function ( $filePath ) use ( $instance, $algo ) { - return $instance->getFileContentsHashInternal( $filePath, $algo ) ?: ''; - }, $filePaths ); + $hashes = []; + foreach ( $filePaths as $filePath ) { + $hashes[] = $instance->getFileContentsHashInternal( $filePath, $algo ) ?: ''; + } Wikimedia\restoreWarnings();