From ca510f742f942411b8678f8b4cb2cb30bce0e2e3 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Thu, 9 Aug 2018 16:09:56 +0100 Subject: [PATCH] resourceloader: Remove $wgResourceLoaderLESSVars support The use of global variables was deprecated in favour of ResourceLoaderModule::getLessVars() on a per-module basis. Also moved testLessFileCompilation case to the appropiate file as it covers ResourceLoaderFileModule.php, not ResourceLoader.php. Bug: T140804 Depends-On: Ib1b2808df2384473bfac47f53a5d25d7c9bbca2b Depends-On: I96047f69d01c4736306df2719267e6347daf556f Change-Id: If708087c85c80355c7e78f1768529b5f2e16ed07 --- RELEASE-NOTES-1.32 | 3 ++ docs/extension.schema.v1.json | 4 --- docs/extension.schema.v2.json | 4 --- includes/DefaultSettings.php | 32 ------------------- includes/registration/ExtensionProcessor.php | 1 - includes/resourceloader/ResourceLoader.php | 9 ++---- .../ResourceLoaderFileModule.php | 5 +-- .../ResourceLoaderFileModuleTest.php | 17 ++++++++++ .../resourceloader/ResourceLoaderTest.php | 26 +-------------- 9 files changed, 24 insertions(+), 77 deletions(-) diff --git a/RELEASE-NOTES-1.32 b/RELEASE-NOTES-1.32 index 92d7b9ee9d..901233456c 100644 --- a/RELEASE-NOTES-1.32 +++ b/RELEASE-NOTES-1.32 @@ -206,6 +206,9 @@ because of Phabricator reports. * (T140807) The wgResourceLoaderLESSImportPaths configuration option was removed from ResourceLoader. Instead, use `@import` statements in LESS to import files directly from nearby directories within the same project. +* (T140804) The wgResourceLoaderLESSVars configuration option, deprecated + since 1.30, was removed. Instead, to expose variables from PHP to LESS, use + the ResourceLoaderModule::getLessVars() method. * The protected methods PHPSessionHandler::returnSuccess() and returnFailure(), only needed for PHP5 compatibility, have been removed. It now uses the boolean values `true` and `false` respectively. diff --git a/docs/extension.schema.v1.json b/docs/extension.schema.v1.json index a8f66c95ca..c9a887dd9c 100644 --- a/docs/extension.schema.v1.json +++ b/docs/extension.schema.v1.json @@ -342,10 +342,6 @@ "type": "object", "description": "ResourceLoader sources to register" }, - "ResourceLoaderLESSVars": { - "type": "object", - "description": "ResourceLoader LESS variables" - }, "ConfigRegistry": { "type": "object", "description": "Registry of factory functions to create Config objects" diff --git a/docs/extension.schema.v2.json b/docs/extension.schema.v2.json index c9d33e1898..24212a9a54 100644 --- a/docs/extension.schema.v2.json +++ b/docs/extension.schema.v2.json @@ -355,10 +355,6 @@ "type": "object", "description": "ResourceLoader sources to register" }, - "ResourceLoaderLESSVars": { - "type": "object", - "description": "ResourceLoader LESS variables" - }, "ConfigRegistry": { "type": "object", "description": "Registry of factory functions to create Config objects" diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 27769f973d..738065ea93 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -3809,38 +3809,6 @@ $wgResourceLoaderValidateJS = true; */ $wgResourceLoaderValidateStaticJS = false; -/** - * Global LESS variables. An associative array binding variable names to - * LESS code snippets representing their values. - * - * Adding an item here is equivalent to writing `@variable: value;` - * at the beginning of all your .less files, with all the consequences. - * In particular, string values must be escaped and quoted. - * - * Changes to this configuration do NOT trigger cache invalidation. - * - * @par Example: - * @code - * $wgResourceLoaderLESSVars = [ - * 'exampleFontSize' => '1em', - * 'exampleBlue' => '#36c', - * ]; - * @endcode - * @since 1.22 - * @deprecated since 1.30 Use ResourceLoaderModule::getLessVars() instead to - * add variables to individual modules that need them. - */ -$wgResourceLoaderLESSVars = [ - /** - * Minimum available screen width at which a device can be considered a tablet - * The number is currently based on the device width of a Samsung Galaxy S5 mini and is low - * enough to cover iPad (768px). Number is prone to change with new information. - * @since 1.27 - * @deprecated 1.31 Use mediawiki.ui/variables instead - */ - 'deviceWidthTablet' => '720px', -]; - /** * Whether ResourceLoader should attempt to persist modules in localStorage on * browsers that support the Web Storage API. diff --git a/includes/registration/ExtensionProcessor.php b/includes/registration/ExtensionProcessor.php index d0a987116d..bf617792a9 100644 --- a/includes/registration/ExtensionProcessor.php +++ b/includes/registration/ExtensionProcessor.php @@ -48,7 +48,6 @@ class ExtensionProcessor implements Processor { 'RecentChangesFlags', 'RemoveCredentialsBlacklist', 'RemoveGroups', - 'ResourceLoaderLESSVars', 'ResourceLoaderSources', 'RevokePermissions', 'SessionProviders', diff --git a/includes/resourceloader/ResourceLoader.php b/includes/resourceloader/ResourceLoader.php index 637bae640a..585c69cffa 100644 --- a/includes/resourceloader/ResourceLoader.php +++ b/includes/resourceloader/ResourceLoader.php @@ -42,9 +42,6 @@ class ResourceLoader implements LoggerAwareInterface { /** @var bool */ protected static $debugMode = null; - /** @var array */ - private $lessVars = null; - /** * Module name/ResourceLoaderModule object pairs * @var array @@ -1749,12 +1746,10 @@ MESSAGE; * Get global LESS variables. * * @since 1.27 + * @deprecated since 1.32 Use ResourceLoderModule::getLessVars() instead. * @return array Map of variable names to string CSS values. */ public function getLessVars() { - if ( $this->lessVars === null ) { - $this->lessVars = $this->config->get( 'ResourceLoaderLESSVars' ); - } - return $this->lessVars; + return []; } } diff --git a/includes/resourceloader/ResourceLoaderFileModule.php b/includes/resourceloader/ResourceLoaderFileModule.php index b2ca2911b0..6ee030e0e8 100644 --- a/includes/resourceloader/ResourceLoaderFileModule.php +++ b/includes/resourceloader/ResourceLoaderFileModule.php @@ -959,10 +959,7 @@ class ResourceLoaderFileModule extends ResourceLoaderModule { $cache = ObjectCache::getLocalServerInstance( CACHE_ANYTHING ); } - $vars = array_merge( - $context->getResourceLoader()->getLessVars(), - $this->getLessVars( $context ) - ); + $vars = $this->getLessVars( $context ); // Construct a cache key from the LESS file name, and a hash digest // of the LESS variables used for compilation. ksort( $vars ); diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php index 71966b7570..20d4b54cd4 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php @@ -336,6 +336,23 @@ class ResourceLoaderFileModuleTest extends ResourceLoaderTestCase { ); } + /** + * @covers ResourceLoaderFileModule::compileLessFile + */ + public function testLessFileCompilation() { + $context = $this->getResourceLoaderContext(); + $basePath = __DIR__ . '/../../data/less/module'; + $module = new ResourceLoaderFileTestModule( [ + 'localBasePath' => $basePath, + 'styles' => [ 'styles.less' ], + ], [ + 'lessVars' => [ 'foo' => '2px', 'Foo' => '#eeeeee' ] + ] ); + $module->setName( 'test.less' ); + $styles = $module->getStyles( $context ); + $this->assertStringEqualsFile( $basePath . '/styles.css', $styles['all'] ); + } + /** * @covers ResourceLoaderFileModule::getDefinitionSummary * @covers ResourceLoaderFileModule::getFileHashes diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php index c15eb2ce44..d9ad711190 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php @@ -8,15 +8,6 @@ class ResourceLoaderTest extends ResourceLoaderTestCase { parent::setUp(); $this->setMwGlobals( [ - 'wgResourceLoaderLESSVars' => [ - 'foo' => '2px', - 'Foo' => '#eeeeee', - 'bar' => 5, - ], - // Clear ResourceLoaderGetConfigVars hooks (called by StartupModule) - // to avoid notices during testMakeModuleResponse for missing - // wgResourceLoaderLESSVars keys in extension hooks. - 'wgHooks' => [], 'wgShowExceptionDetails' => true, ] ); } @@ -246,27 +237,12 @@ class ResourceLoaderTest extends ResourceLoaderTestCase { ); } - /** - * @covers ResourceLoaderFileModule::compileLessFile - */ - public function testLessFileCompilation() { - $context = $this->getResourceLoaderContext(); - $basePath = __DIR__ . '/../../data/less/module'; - $module = new ResourceLoaderFileModule( [ - 'localBasePath' => $basePath, - 'styles' => [ 'styles.less' ], - ] ); - $module->setName( 'test.less' ); - $styles = $module->getStyles( $context ); - $this->assertStringEqualsFile( $basePath . '/styles.css', $styles['all'] ); - } - /** * @covers ResourceLoader::getLessCompiler */ public function testLessImportDirs() { $rl = new EmptyResourceLoader(); - $lc = $rl->getLessCompiler( $rl->getLessVars() ); + $lc = $rl->getLessCompiler( [ 'foo' => '2px', 'Foo' => '#eeeeee' ] ); $basePath = dirname( dirname( __DIR__ ) ) . '/data/less'; $lc->SetImportDirs( [ "$basePath/common" => '', -- 2.20.1