mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CodeMirror
synced 2024-11-27 15:40:00 +00:00
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:
parent
0acb7475bd
commit
60b14d1aa0
|
@ -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' ] );
|
||||
|
|
|
@ -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( [] );
|
||||
|
|
Loading…
Reference in a new issue