From ba0419fcbf09f95a30f845adab92f282153146c7 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Tue, 3 Apr 2018 00:16:39 +0100 Subject: [PATCH] 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 --- includes/Minerva.hooks.php | 15 --------------- includes/ResourceLoaderLessVarFileModule.php | 19 +++++++++++++++++++ skin.json | 6 +++--- 3 files changed, 22 insertions(+), 18 deletions(-) create mode 100644 includes/ResourceLoaderLessVarFileModule.php diff --git a/includes/Minerva.hooks.php b/includes/Minerva.hooks.php index 61b19953e..240040d0e 100644 --- a/includes/Minerva.hooks.php +++ b/includes/Minerva.hooks.php @@ -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/ diff --git a/includes/ResourceLoaderLessVarFileModule.php b/includes/ResourceLoaderLessVarFileModule.php new file mode 100644 index 000000000..58eeea1fc --- /dev/null +++ b/includes/ResourceLoaderLessVarFileModule.php @@ -0,0 +1,19 @@ + + $this->getConfig()->get( 'MinervaApplyKnownTemplateHacks' ), + ]; + } +} diff --git a/skin.json b/skin.json index 0d6b76861..de1ab3b1d 100644 --- a/skin.json +++ b/skin.json @@ -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"