Avoid using User::getOption() method

Replace User::getOption() with UserOptionsLookup::getOption() since this method will be hard-deprecated.

Bug: T296083
Change-Id: I405251092fd94fa70a33319d313c5140c8cebc21
This commit is contained in:
vladshapik 2021-11-29 19:49:29 +01:00 committed by Thiemo Kreuz (WMDE)
parent 0acb7475bd
commit 60b14d1aa0
2 changed files with 8 additions and 3 deletions

View file

@ -16,8 +16,9 @@ class CodeMirrorHooks {
if ( in_array( 'ext.codeEditor', $out->getModules() ) ) {
return false;
}
$userOptionsLookup = MediaWikiServices::getInstance()->getUserOptionsLookup();
// Disable CodeMirror when the WikiEditor toolbar is not enabled in preferences
if ( !$out->getUser()->getOption( 'usebetatoolbar' ) ) {
if ( !$userOptionsLookup->getOption( $out->getUser(), 'usebetatoolbar' ) ) {
return false;
}
$context = $out->getContext();
@ -38,7 +39,8 @@ class CodeMirrorHooks {
if ( self::isCodeMirrorOnPage( $out ) ) {
$out->addModules( 'ext.CodeMirror' );
if ( $out->getUser()->getOption( 'usecodemirror' ) ) {
$userOptionsLookup = MediaWikiServices::getInstance()->getUserOptionsLookup();
if ( $userOptionsLookup->getOption( $out->getUser(), 'usecodemirror' ) ) {
// These modules are predelivered for performance when needed
// keep these modules in sync with ext.CodeMirror.js
$out->addModules( [ 'ext.CodeMirror.lib', 'ext.CodeMirror.mode.mediawiki' ] );

View file

@ -4,6 +4,7 @@ namespace CodeMirror\Tests;
use CodeMirrorHooks;
use MediaWiki\MediaWikiServices;
use MediaWiki\User\UserOptionsLookup;
use MediaWikiIntegrationTestCase;
use RequestContext;
@ -25,7 +26,9 @@ class HookTest extends MediaWikiIntegrationTestCase {
$context->method( 'getTitle' )->willReturn( $wikiPage->getTitle() );
$user = $this->createMock( \User::class );
$user->method( 'getOption' )->willReturn( true );
$userOptionsLookup = $this->createMock( UserOptionsLookup::class );
$userOptionsLookup->method( 'getOption' )->willReturn( true );
$this->setService( 'UserOptionsLookup', $userOptionsLookup );
$out = $this->createMock( \OutputPage::class );
$out->method( 'getModules' )->willReturn( [] );