From 62a8ce1d487bb28582f8bf683f62243c40c9595f Mon Sep 17 00:00:00 2001 From: Fomafix Date: Fri, 26 Jul 2024 06:02:26 +0000 Subject: [PATCH] Inject service UserOptionsManager into Hooks Change-Id: I39f7e113a74fa9e15259638ee1900da98eaa4a3a --- extension.json | 5 ++++- src/Hooks.php | 12 +++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/extension.json b/extension.json index 7c25efdbc..17b0502b4 100644 --- a/extension.json +++ b/extension.json @@ -60,7 +60,10 @@ ] }, "main": { - "class": "MediaWiki\\Extension\\Math\\Hooks" + "class": "MediaWiki\\Extension\\Math\\Hooks", + "services": [ + "UserOptionsManager" + ] }, "schema": { "class": "MediaWiki\\Extension\\Math\\HookHandlers\\SchemaHooksHandler" diff --git a/src/Hooks.php b/src/Hooks.php index 8da9a60e6..9c5ddd4e8 100644 --- a/src/Hooks.php +++ b/src/Hooks.php @@ -15,14 +15,21 @@ use Maintenance; use MediaWiki\Config\ConfigException; use MediaWiki\Context\RequestContext; use MediaWiki\Hook\MaintenanceRefreshLinksInitHook; -use MediaWiki\MediaWikiServices; use MediaWiki\Settings\SettingsBuilder; use MediaWiki\SpecialPage\Hook\SpecialPage_initListHook; +use MediaWiki\User\Options\UserOptionsManager; class Hooks implements SpecialPage_initListHook, MaintenanceRefreshLinksInitHook { + private UserOptionsManager $userOptionsManager; + + public function __construct( + UserOptionsManager $userOptionsManager + ) { + $this->userOptionsManager = $userOptionsManager; + } /** * Extension registration callback, used to apply dynamic defaults for configuration variables. @@ -97,8 +104,7 @@ class Hooks implements $user = RequestContext::getMain()->getUser(); // Don't parse LaTeX to improve performance - MediaWikiServices::getInstance()->getUserOptionsManager() - ->setOption( $user, 'math', MathConfig::MODE_SOURCE ); + $this->userOptionsManager->setOption( $user, 'math', MathConfig::MODE_SOURCE ); } /**