diff --git a/extension.json b/extension.json index fb6f36d6..dc70f2c3 100644 --- a/extension.json +++ b/extension.json @@ -22,7 +22,10 @@ }, "HookHandlers": { "CodeEditorHooks": { - "class": "MediaWiki\\Extension\\CodeEditor\\Hooks" + "class": "MediaWiki\\Extension\\CodeEditor\\Hooks", + "services": [ + "UserOptionsLookup" + ] } }, "MessagesDirs": { diff --git a/includes/Hooks.php b/includes/Hooks.php index 54d230ba..f136a6ae 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -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.