Inject service ReadOnlyMode

Also reuse local variable $services for
MediaWikiServices::getInstance() in Job.php.

Change-Id: I0364c64aaf52e229f3e2a2c73c7d4716ec566fae
This commit is contained in:
Fomafix 2023-06-16 22:24:49 +00:00
parent 986b51e5a2
commit 772a4f5642
3 changed files with 11 additions and 5 deletions

View file

@ -31,6 +31,7 @@
"LinkRenderer", "LinkRenderer",
"MovePageFactory", "MovePageFactory",
"NamespaceInfo", "NamespaceInfo",
"ReadOnlyMode",
"SearchEngineConfig", "SearchEngineConfig",
"SlotRoleStore", "SlotRoleStore",
"UserFactory", "UserFactory",

View file

@ -101,7 +101,7 @@ class Job extends JobParent {
$services->getWatchlistManager()->addWatch( $current_user, $new_title ); $services->getWatchlistManager()->addWatch( $current_user, $new_title );
} }
} else { } else {
$wikiPage = MediaWikiServices::getInstance()->getWikiPageFactory()->newFromTitle( $this->title ); $wikiPage = $services->getWikiPageFactory()->newFromTitle( $this->title );
$latestRevision = $wikiPage->getRevisionRecord(); $latestRevision = $wikiPage->getRevisionRecord();
if ( $latestRevision === null ) { if ( $latestRevision === null ) {

View file

@ -25,7 +25,6 @@ use JobQueueGroup;
use Language; use Language;
use MediaWiki\HookContainer\HookContainer; use MediaWiki\HookContainer\HookContainer;
use MediaWiki\Linker\LinkRenderer; use MediaWiki\Linker\LinkRenderer;
use MediaWiki\MediaWikiServices;
use MediaWiki\Page\MovePageFactory; use MediaWiki\Page\MovePageFactory;
use MediaWiki\Revision\SlotRecord; use MediaWiki\Revision\SlotRecord;
use MediaWiki\Storage\NameTableStore; use MediaWiki\Storage\NameTableStore;
@ -37,6 +36,7 @@ use PermissionsError;
use SearchEngineConfig; use SearchEngineConfig;
use SpecialPage; use SpecialPage;
use Title; use Title;
use Wikimedia\Rdbms\ReadOnlyMode;
use Xml; use Xml;
class SpecialReplaceText extends SpecialPage { class SpecialReplaceText extends SpecialPage {
@ -69,6 +69,9 @@ class SpecialReplaceText extends SpecialPage {
/** @var NamespaceInfo */ /** @var NamespaceInfo */
private $namespaceInfo; private $namespaceInfo;
/** @var ReadOnlyMode */
private $readOnlyMode;
/** @var SearchEngineConfig */ /** @var SearchEngineConfig */
private $searchEngineConfig; private $searchEngineConfig;
@ -88,6 +91,7 @@ class SpecialReplaceText extends SpecialPage {
* @param LinkRenderer $linkRenderer * @param LinkRenderer $linkRenderer
* @param MovePageFactory $movePageFactory * @param MovePageFactory $movePageFactory
* @param NamespaceInfo $namespaceInfo * @param NamespaceInfo $namespaceInfo
* @param ReadOnlyMode $readOnlyMode
* @param SearchEngineConfig $searchEngineConfig * @param SearchEngineConfig $searchEngineConfig
* @param NameTableStore $slotRoleStore * @param NameTableStore $slotRoleStore
* @param UserFactory $userFactory * @param UserFactory $userFactory
@ -100,6 +104,7 @@ class SpecialReplaceText extends SpecialPage {
LinkRenderer $linkRenderer, LinkRenderer $linkRenderer,
MovePageFactory $movePageFactory, MovePageFactory $movePageFactory,
NamespaceInfo $namespaceInfo, NamespaceInfo $namespaceInfo,
ReadOnlyMode $readOnlyMode,
SearchEngineConfig $searchEngineConfig, SearchEngineConfig $searchEngineConfig,
NameTableStore $slotRoleStore, NameTableStore $slotRoleStore,
UserFactory $userFactory, UserFactory $userFactory,
@ -112,6 +117,7 @@ class SpecialReplaceText extends SpecialPage {
$this->linkRenderer = $linkRenderer; $this->linkRenderer = $linkRenderer;
$this->movePageFactory = $movePageFactory; $this->movePageFactory = $movePageFactory;
$this->namespaceInfo = $namespaceInfo; $this->namespaceInfo = $namespaceInfo;
$this->readOnlyMode = $readOnlyMode;
$this->searchEngineConfig = $searchEngineConfig; $this->searchEngineConfig = $searchEngineConfig;
$this->slotRoleStore = $slotRoleStore; $this->slotRoleStore = $slotRoleStore;
$this->userFactory = $userFactory; $this->userFactory = $userFactory;
@ -144,9 +150,8 @@ class SpecialReplaceText extends SpecialPage {
$out = $this->getOutput(); $out = $this->getOutput();
$readOnlyMode = MediaWikiServices::getInstance()->getReadOnlyMode(); if ( $this->readOnlyMode->isReadOnly() ) {
if ( $readOnlyMode->isReadOnly() ) { $permissionErrors = [ [ 'readonlytext', [ $this->readOnlyMode->getReason() ] ] ];
$permissionErrors = [ [ 'readonlytext', [ $readOnlyMode->getReason() ] ] ];
$out->setPageTitle( $this->msg( 'badaccess' )->text() ); $out->setPageTitle( $this->msg( 'badaccess' )->text() );
$out->addWikiTextAsInterface( $out->formatPermissionsErrorMessage( $permissionErrors, 'replacetext' ) ); $out->addWikiTextAsInterface( $out->formatPermissionsErrorMessage( $permissionErrors, 'replacetext' ) );
return; return;