From: Alexia E. Smith Date: Tue, 10 Apr 2018 22:35:49 +0000 (-0500) Subject: resourceloader: Include global LESS variables in LESS cache key X-Git-Tag: 1.34.0-rc.0~5275^2 X-Git-Url: https://git.cyclocoop.org/admin/?a=commitdiff_plain;h=8a1da0a43b5853abd5ab22f5e5368e5cf4aca172;p=lhc%2Fweb%2Fwiklou.git resourceloader: Include global LESS variables in LESS cache key This prevents cache churn when the wiki-global LESS variables vary between wikis because the cache key is used as a "global" instead of db-local. This is good for the common case, but should still explicitly vary if the vars differ between wikis. Bug: T191937 Change-Id: If12fd07a7062792205384150d6f5fd9a83f996cc --- diff --git a/includes/resourceloader/ResourceLoader.php b/includes/resourceloader/ResourceLoader.php index 227479336b..1cbd8781ae 100644 --- a/includes/resourceloader/ResourceLoader.php +++ b/includes/resourceloader/ResourceLoader.php @@ -1704,12 +1704,13 @@ MESSAGE; * Returns LESS compiler set up for use with MediaWiki * * @since 1.27 - * @param array $extraVars Associative array of extra (i.e., other than the - * globally-configured ones) that should be used for compilation. + * @param array $vars Associative array of variables that should be used + * for compilation. Since 1.32, this method no longer automatically includes + * global LESS vars from ResourceLoader::getLessVars (T191937). * @throws MWException * @return Less_Parser */ - public function getLessCompiler( $extraVars = [] ) { + public function getLessCompiler( $vars = [] ) { // When called from the installer, it is possible that a required PHP extension // is missing (at least for now; see T49564). If this is the case, throw an // exception (caught by the installer) to prevent a fatal error later on. @@ -1718,7 +1719,7 @@ MESSAGE; } $parser = new Less_Parser; - $parser->ModifyVars( array_merge( $this->getLessVars(), $extraVars ) ); + $parser->ModifyVars( $vars ); $parser->SetImportDirs( array_fill_keys( $this->config->get( 'ResourceLoaderLESSImportPaths' ), '' ) ); diff --git a/includes/resourceloader/ResourceLoaderFileModule.php b/includes/resourceloader/ResourceLoaderFileModule.php index f2f3383f41..7f8c7f53ce 100644 --- a/includes/resourceloader/ResourceLoaderFileModule.php +++ b/includes/resourceloader/ResourceLoaderFileModule.php @@ -959,9 +959,12 @@ class ResourceLoaderFileModule extends ResourceLoaderModule { $cache = ObjectCache::getLocalServerInstance( CACHE_ANYTHING ); } - // Construct a cache key from the LESS file name and a hash digest + $vars = array_merge( + $context->getResourceLoader()->getLessVars(), + $this->getLessVars( $context ) + ); + // Construct a cache key from the LESS file name, and a hash digest // of the LESS variables used for compilation. - $vars = $this->getLessVars( $context ); ksort( $vars ); $varsHash = hash( 'md4', serialize( $vars ) ); $cacheKey = $cache->makeGlobalKey( 'LESS', $fileName, $varsHash ); diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php index 95006aa923..7c2476f9cf 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php @@ -267,7 +267,7 @@ class ResourceLoaderTest extends ResourceLoaderTestCase { */ public function testLessImportDirs() { $rl = new EmptyResourceLoader(); - $lc = $rl->getLessCompiler(); + $lc = $rl->getLessCompiler( $rl->getLessVars() ); $basePath = dirname( dirname( __DIR__ ) ) . '/data/less'; $lc->SetImportDirs( [ "$basePath/common" => '',