resourceloader: Remove $wgResourceLoaderLESSVars support
authorTimo Tijhof <krinklemail@gmail.com>
Thu, 9 Aug 2018 15:09:56 +0000 (16:09 +0100)
committerKrinkle <krinklemail@gmail.com>
Tue, 14 Aug 2018 18:57:45 +0000 (18:57 +0000)
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
docs/extension.schema.v1.json
docs/extension.schema.v2.json
includes/DefaultSettings.php
includes/registration/ExtensionProcessor.php
includes/resourceloader/ResourceLoader.php
includes/resourceloader/ResourceLoaderFileModule.php
tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php
tests/phpunit/includes/resourceloader/ResourceLoaderTest.php

index 92d7b9e..9012334 100644 (file)
@@ -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.
index a8f66c9..c9a887d 100644 (file)
                        "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"
index c9d33e1..24212a9 100644 (file)
                        "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"
index 27769f9..738065e 100644 (file)
@@ -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.
index d0a9871..bf61779 100644 (file)
@@ -48,7 +48,6 @@ class ExtensionProcessor implements Processor {
                'RecentChangesFlags',
                'RemoveCredentialsBlacklist',
                'RemoveGroups',
-               'ResourceLoaderLESSVars',
                'ResourceLoaderSources',
                'RevokePermissions',
                'SessionProviders',
index 637bae6..585c69c 100644 (file)
@@ -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 [];
        }
 }
index b2ca291..6ee030e 100644 (file)
@@ -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 );
index 71966b7..20d4b54 100644 (file)
@@ -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
index c15eb2c..d9ad711 100644 (file)
@@ -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" => '',