Avoid using User::getOption and inject service UserOptionsLookup

Remove using of User:getOption since this method will be hard-deprecated. Now it is soft-deprecated

Bug: T296083
Change-Id: Iae0c0cd3ab4ffdfd6cfce5e7ced81dfae3d4a359
This commit is contained in:
Roman Stolar 2021-11-23 16:47:50 +02:00 committed by Fomafix
parent ad1930d255
commit 51cd95fac9
2 changed files with 18 additions and 2 deletions

View file

@ -22,7 +22,10 @@
},
"HookHandlers": {
"CodeEditorHooks": {
"class": "MediaWiki\\Extension\\CodeEditor\\Hooks"
"class": "MediaWiki\\Extension\\CodeEditor\\Hooks",
"services": [
"UserOptionsLookup"
]
}
},
"MessagesDirs": {

View file

@ -8,6 +8,7 @@ use ExtensionRegistry;
use MediaWiki\Hook\EditPage__showEditForm_initialHook;
use MediaWiki\Hook\EditPage__showReadOnlyForm_initialHook;
use MediaWiki\Preferences\Hook\GetPreferencesHook;
use MediaWiki\User\UserOptionsLookup;
use OutputPage;
use Title;
use User;
@ -20,6 +21,18 @@ class Hooks implements
EditPage__showEditForm_initialHook,
EditPage__showReadOnlyForm_initialHook
{
/** @var UserOptionsLookup */
private $userOptionsLookup;
/**
* @param UserOptionsLookup $userOptionsLookup
*/
public function __construct(
UserOptionsLookup $userOptionsLookup
) {
$this->userOptionsLookup = $userOptionsLookup;
}
/**
* @param Title $title
* @param string $model
@ -65,7 +78,7 @@ class Hooks implements
$format = $editpage->contentFormat;
$lang = self::getPageLanguage( $title, $model, $format );
if ( $lang && $output->getUser()->getOption( 'usebetatoolbar' ) ) {
if ( $lang && $this->userOptionsLookup->getOption( $output->getUser(), 'usebetatoolbar' ) ) {
$output->addModules( 'ext.codeEditor' );
$output->addJsConfigVars( 'wgCodeEditorCurrentLanguage', $lang );
// Needed because ACE adds a blob: url web-worker.