From: jdlrobson Date: Fri, 8 Jan 2016 22:09:36 +0000 (-0800) Subject: resourceloader: Change getLessCompiler() to not be static X-Git-Tag: 1.31.0-rc.0~8270^2 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmes_infos.php?a=commitdiff_plain;h=4d0a36f333ffa3ca45f6446c1c9367ba54c05ea8;p=lhc%2Fweb%2Fwiklou.git resourceloader: Change getLessCompiler() to not be static Cache Less variables in the instance instead of statically. This allows tests to populate their own less variabless via ResourceLoaderLESSVars. Make getLessCompiler() and getLessVars() regular public methods and update callers. Change-Id: I95506b8bb20a4b2b3f82014a7b0fcee5f28973e6 --- diff --git a/includes/resourceloader/ResourceLoader.php b/includes/resourceloader/ResourceLoader.php index 1f3085aa9f..74ee6ab7bd 100644 --- a/includes/resourceloader/ResourceLoader.php +++ b/includes/resourceloader/ResourceLoader.php @@ -41,7 +41,7 @@ class ResourceLoader implements LoggerAwareInterface { protected static $debugMode = null; /** @var array */ - private static $lessVars = null; + private $lessVars = null; /** * Module name/ResourceLoaderModule object pairs @@ -1589,15 +1589,13 @@ MESSAGE; /** * Returns LESS compiler set up for use with MediaWiki * - * @since 1.22 - * @since 1.27 added $extraVars parameter - * @param Config $config + * @since 1.27 * @param array $extraVars Associative array of extra (i.e., other than the * globally-configured ones) that should be used for compilation. * @throws MWException * @return Less_Parser */ - public static function getLessCompiler( Config $config, $extraVars = array() ) { + public function getLessCompiler( $extraVars = array() ) { // When called from the installer, it is possible that a required PHP extension // is missing (at least for now; see bug 47564). If this is the case, throw an // exception (caught by the installer) to prevent a fatal error later on. @@ -1606,10 +1604,12 @@ MESSAGE; } $parser = new Less_Parser; - $parser->ModifyVars( array_merge( self::getLessVars( $config ), $extraVars ) ); - $parser->SetImportDirs( array_fill_keys( $config->get( 'ResourceLoaderLESSImportPaths' ), '' ) ); + $parser->ModifyVars( array_merge( $this->getLessVars(), $extraVars ) ); + $parser->SetImportDirs( + array_fill_keys( $this->config->get( 'ResourceLoaderLESSImportPaths' ), '' ) + ); $parser->SetOption( 'relativeUrls', false ); - $parser->SetCacheDir( $config->get( 'CacheDirectory' ) ?: wfTempDir() ); + $parser->SetCacheDir( $this->config->get( 'CacheDirectory' ) ?: wfTempDir() ); return $parser; } @@ -1617,16 +1617,15 @@ MESSAGE; /** * Get global LESS variables. * - * @param Config $config - * @since 1.22 + * @since 1.27 * @return array Map of variable names to string CSS values. */ - public static function getLessVars( Config $config ) { - if ( !self::$lessVars ) { - $lessVars = $config->get( 'ResourceLoaderLESSVars' ); + public function getLessVars() { + if ( !$this->lessVars ) { + $lessVars = $this->config->get( 'ResourceLoaderLESSVars' ); Hooks::run( 'ResourceLoaderGetLessVars', array( &$lessVars ) ); - self::$lessVars = $lessVars; + $this->lessVars = $lessVars; } - return self::$lessVars; + return $this->lessVars; } } diff --git a/includes/resourceloader/ResourceLoaderFileModule.php b/includes/resourceloader/ResourceLoaderFileModule.php index f5b3bad5c3..98269aeda0 100644 --- a/includes/resourceloader/ResourceLoaderFileModule.php +++ b/includes/resourceloader/ResourceLoaderFileModule.php @@ -957,7 +957,7 @@ class ResourceLoaderFileModule extends ResourceLoaderModule { } } - $compiler = ResourceLoader::getLessCompiler( $this->getConfig(), $vars ); + $compiler = $context->getResourceLoader()->getLessCompiler( $vars ); $css = $compiler->parseFile( $fileName )->getCss(); $files = $compiler->AllParsedFiles(); $this->localFileRefs = array_merge( $this->localFileRefs, $files );