Inject service UserOptionsManager into Hooks

Change-Id: I39f7e113a74fa9e15259638ee1900da98eaa4a3a
This commit is contained in:
Fomafix 2024-07-26 06:02:26 +00:00
parent 5f0100872d
commit 62a8ce1d48
2 changed files with 13 additions and 4 deletions

View file

@ -60,7 +60,10 @@
]
},
"main": {
"class": "MediaWiki\\Extension\\Math\\Hooks"
"class": "MediaWiki\\Extension\\Math\\Hooks",
"services": [
"UserOptionsManager"
]
},
"schema": {
"class": "MediaWiki\\Extension\\Math\\HookHandlers\\SchemaHooksHandler"

View file

@ -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 );
}
/**