Convert custom LESS var from global to local

Avoid the 'ResourceLoaderGetLessVars' hook, which registers a
global LESS variable exposed to all modules (inc. core/extensions).

Instead, use a FileModule subclass to provide the variable only
to the modules that need it.

Using this approach, also has the benefit of being tracked by
the version hasher, so that changes to the configuration actually
result in timely invalidation of module caches.

Bug: T171367
Change-Id: I7c7d13c83004edfc852a9b7dbfc4169617ab9f64
This commit is contained in:
Timo Tijhof 2018-04-03 00:16:39 +01:00 committed by Krinkle
parent 4419975fb0
commit ba0419fcbf
3 changed files with 22 additions and 18 deletions

View file

@ -12,21 +12,6 @@
use MediaWiki\MediaWikiServices;
class MinervaHooks {
/**
* ResourceLoaderGetLessVars hook handler
*
* Add the context-based less variables.
*
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderGetLessVars
* @param array &$lessVars Variables already added
*/
public static function onResourceLoaderGetLessVars( &$lessVars ) {
$config = MediaWikiServices::getInstance()->getConfigFactory()
->makeConfig( 'minerva' );
$lessVars['wgMinervaApplyKnownTemplateHacks'] = $config->get( 'MinervaApplyKnownTemplateHacks' );
}
/**
* Register mobile web beta features
* @see https://www.mediawiki.org/wiki/

View file

@ -0,0 +1,19 @@
<?php
namespace MediaWiki\Minerva;
/**
* Subclass with extra LESS variables for Minerva configuration.
*/
class ResourceLoaderLessVarFileModule extends \ResourceLoaderFileModule {
/**
* @param \ResourceLoaderContext $context
* @return array LESS variables
*/
protected function getLessVars( \ResourceLoaderContext $context ) {
return [
'wgMinervaApplyKnownTemplateHacks' =>
$this->getConfig()->get( 'MinervaApplyKnownTemplateHacks' ),
];
}
}

View file

@ -9,6 +9,7 @@
"ICustomizableSkin": "includes/skins/ICustomizableSkin.php",
"MediaWiki\\Minerva\\MenuBuilder": "includes/skins/MenuBuilder.php",
"MediaWiki\\Minerva\\MenuEntry": "includes/skins/MenuBuilder.php",
"MediaWiki\\Minerva\\ResourceLoaderLessVarFileModule": "includes/ResourceLoaderLessVarFileModule.php",
"MediaWiki\\Minerva\\SkinUserPageHelper": "includes/skins/SkinUserPageHelper.php"
},
"ConfigRegistry": {
@ -26,9 +27,6 @@
],
"SpecialPageBeforeExecute": [
"MinervaHooks::onSpecialPageBeforeExecute"
],
"ResourceLoaderGetLessVars": [
"MinervaHooks::onResourceLoaderGetLessVars"
]
},
"MessagesDirs": {
@ -117,6 +115,7 @@
]
},
"skins.minerva.content.styles": {
"class": "MediaWiki\\Minerva\\ResourceLoaderLessVarFileModule",
"targets": [
"mobile",
"desktop"
@ -126,6 +125,7 @@
]
},
"skins.minerva.tablet.styles": {
"class": "MediaWiki\\Minerva\\ResourceLoaderLessVarFileModule",
"targets": [
"mobile",
"desktop"