Replace usage of deprecated global function wfReadOnly()

The global function wfReadOnly() has been deprecated in favor of the
new ReadOnlyMode service. Its usages should be replaced.

Bug: T283978
Change-Id: I26a878f19be5c90dab04e28ce395cb8f6dddebef
This commit is contained in:
Alexander Vorwerk 2021-12-26 14:23:42 +01:00
parent 63dfd2492a
commit 61e0094574
3 changed files with 15 additions and 7 deletions

View file

@ -204,7 +204,8 @@
"LinkRenderer",
"UserOptionsLookup",
"WatchlistManager",
"ContentTransformer"
"ContentTransformer",
"ReadOnlyMode"
]
},
"visualeditoredit": {

View file

@ -41,6 +41,9 @@ class ApiVisualEditor extends ApiBase {
/** @var ContentTransformer */
private $contentTransformer;
/** @var ReadOnlyMode */
private $readOnlyMode;
/**
* @param ApiMain $main
* @param string $name
@ -50,6 +53,7 @@ class ApiVisualEditor extends ApiBase {
* @param UserOptionsLookup $userOptionsLookup
* @param WatchlistManager $watchlistManager
* @param ContentTransformer $contentTransformer
* @param ReadOnlyMode $readOnlyMode
*/
public function __construct(
ApiMain $main,
@ -59,7 +63,8 @@ class ApiVisualEditor extends ApiBase {
LinkRenderer $linkRenderer,
UserOptionsLookup $userOptionsLookup,
WatchlistManager $watchlistManager,
ContentTransformer $contentTransformer
ContentTransformer $contentTransformer,
ReadOnlyMode $readOnlyMode
) {
parent::__construct( $main, $name );
$this->setLogger( LoggerFactory::getInstance( 'VisualEditor' ) );
@ -69,6 +74,7 @@ class ApiVisualEditor extends ApiBase {
$this->userOptionsLookup = $userOptionsLookup;
$this->watchlistManager = $watchlistManager;
$this->contentTransformer = $contentTransformer;
$this->readOnlyMode = $readOnlyMode;
}
/**
@ -322,8 +328,8 @@ class ApiVisualEditor extends ApiBase {
$notices['editingold'] = $this->msg( 'editingold' )->parseAsBlock();
}
if ( wfReadOnly() ) {
$notices['readonlywarning'] = $this->msg( 'readonlywarning', wfReadOnlyReason() );
if ( $this->readOnlyMode->isReadOnly() ) {
$notices['readonlywarning'] = $this->msg( 'readonlywarning', $this->readOnlyMode->getReason() );
}
// Edit notices about the page being protected (only used when we're allowed to edit it;

View file

@ -313,7 +313,7 @@ class VisualEditorHooks {
if ( $req->getVal( 'venoscript' ) ) {
$req->response()->setCookie( 'VEE', 'wikitext', 0, [ 'prefix' => '' ] );
$services->getUserOptionsManager()->setOption( $user, 'visualeditor-editor', 'wikitext' );
if ( !wfReadOnly() && $user->isRegistered() ) {
if ( !$services->getReadOnlyMode()->isReadOnly() && $user->isRegistered() ) {
DeferredUpdates::addCallableUpdate( static function () use ( $user ) {
$user->saveSettings();
} );
@ -1166,12 +1166,13 @@ class VisualEditorHooks {
$lb->getLazyConnectionRef( DB_PRIMARY ),
__METHOD__,
static function () use ( $user, $cookie ) {
if ( wfReadOnly() ) {
$services = MediaWikiServices::getInstance();
if ( $services->getReadOnlyMode()->isReadOnly() ) {
return;
}
$uLatest = $user->getInstanceForUpdate();
MediaWikiServices::getInstance()->getUserOptionsManager()
$services->getUserOptionsManager()
->setOption( $uLatest, 'visualeditor-editor', $cookie );
$uLatest->saveSettings();
}