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
This commit is contained in:
Timo Tijhof 2018-08-09 16:09:56 +01:00 committed by Krinkle
parent 8f8851325e
commit ca510f742f
9 changed files with 24 additions and 77 deletions

View 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.

View file

@ -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"

View file

@ -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"

View 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.

View file

@ -48,7 +48,6 @@ class ExtensionProcessor implements Processor {
'RecentChangesFlags',
'RemoveCredentialsBlacklist',
'RemoveGroups',
'ResourceLoaderLESSVars',
'ResourceLoaderSources',
'RevokePermissions',
'SessionProviders',

View 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 [];
}
}

View 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 );

View 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

View 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" => '',