From 6e6635bdbb86155ecb7e4316ab8eb367719271df Mon Sep 17 00:00:00 2001 From: Abijeet Date: Thu, 20 Jan 2022 14:06:57 +0530 Subject: [PATCH] Move version check inside PersonalUrls hook Stop additional conditional hook if MW < 1.37, and move the check to inside the hook itself Bug: T299305 Change-Id: Ied1c5c0beee015d7b0a8d6bd750346f4a8a5aaa1 --- extension.json | 1 + includes/Hooks.php | 22 ++++++++++------------ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/extension.json b/extension.json index e36d8eeb..ea4b8dbe 100644 --- a/extension.json +++ b/extension.json @@ -25,6 +25,7 @@ "GetBetaFeaturePreferences": "main", "GetPreferences": "main", "MakeGlobalVariablesScript": "main", + "PersonalUrls": "main", "ResourceLoaderGetConfigVars": "main", "SkinAfterPortlet": "main", "SkinTemplateNavigation::Universal": "main", diff --git a/includes/Hooks.php b/includes/Hooks.php index f3aaf4cd..da9a58bc 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -88,19 +88,7 @@ class Hooks implements } public static function setVersionConstant() { - global $wgHooks; - define( 'ULS_VERSION', '2020-07-20' ); - - // For MediaWiki < 1.37, there is no `user-interface-preferences` menu. We use - // the PersonalUrls hook to make sure the language button is added. - // In MediaWiki > 1.37, the personal urls was split out into multiple new menus, - // In the new format, the `user-interface-preferences` is the most relevant place to put - // this button. Using the SkinTemplateNavigation::Universal hook will ensure the button is - // added to the correct menu. - if ( version_compare( MW_VERSION, '1.37', '<' ) ) { - $wgHooks['PersonalUrls'][] = "UniversalLanguageSelector\\Hooks::onPersonalUrls"; - } } /** @@ -233,6 +221,16 @@ class Hooks implements * @param SkinTemplate $skin */ public function onPersonalUrls( &$personal_urls, &$title, $skin ): void { + // For MediaWiki < 1.37, there is no `user-interface-preferences` menu. We use + // the PersonalUrls hook to make sure the language button is added. + // In MediaWiki >= 1.37, the personal urls was split out into multiple new menus, + // In the new format, the `user-interface-preferences` is the most relevant place to put + // this button. Using the SkinTemplateNavigation::Universal hook will ensure the button is + // added to the correct menu. + if ( version_compare( MW_VERSION, '1.37', '>=' ) ) { + return; + } + $personal_urls = $this->addPersonalBarTrigger( $personal_urls, $skin