diff --git a/includes/actions/ActionFactory.php b/includes/actions/ActionFactory.php index 7a32510df78..e66e143411e 100644 --- a/includes/actions/ActionFactory.php +++ b/includes/actions/ActionFactory.php @@ -74,8 +74,6 @@ class ActionFactory { 'delete' => true, 'edit' => true, 'history' => true, - 'mcrundo' => McrUndoAction::class, - 'mcrrestore' => McrRestoreAction::class, 'protect' => true, 'purge' => true, 'render' => true, @@ -127,6 +125,20 @@ class ActionFactory { 'LinkRenderer', ], ], + 'mcrundo' => [ + 'class' => McrUndoAction::class, + 'services' => [ + 'RevisionLookup', + 'RevisionRenderer', + ], + ], + 'mcrrestore' => [ + 'class' => McrRestoreAction::class, + 'services' => [ + 'RevisionLookup', + 'RevisionRenderer', + ], + ], 'raw' => [ 'class' => RawAction::class, 'services' => [ diff --git a/includes/actions/McrUndoAction.php b/includes/actions/McrUndoAction.php index a98bd65c3e1..abe5a4ce30c 100644 --- a/includes/actions/McrUndoAction.php +++ b/includes/actions/McrUndoAction.php @@ -5,9 +5,10 @@ * @ingroup Actions */ -use MediaWiki\MediaWikiServices; use MediaWiki\Revision\MutableRevisionRecord; +use MediaWiki\Revision\RevisionLookup; use MediaWiki\Revision\RevisionRecord; +use MediaWiki\Revision\RevisionRenderer; use MediaWiki\Revision\SlotRecord; use MediaWiki\Storage\EditResult; @@ -34,6 +35,29 @@ class McrUndoAction extends FormAction { /** @var RevisionRecord|null */ protected $curRev = null; + /** @var RevisionLookup */ + private $revisionLookup; + + /** @var RevisionRenderer */ + private $revisionRenderer; + + /** + * @param Page $page + * @param IContextSource $context + * @param RevisionLookup $revisionLookup + * @param RevisionRenderer $revisionRenderer + */ + public function __construct( + Page $page, + IContextSource $context, + RevisionLookup $revisionLookup, + RevisionRenderer $revisionRenderer + ) { + parent::__construct( $page, $context ); + $this->revisionLookup = $revisionLookup; + $this->revisionRenderer = $revisionRenderer; + } + public function getName() { return 'mcrundo'; } @@ -112,10 +136,8 @@ class McrUndoAction extends FormAction { $this->initFromParameters(); - $revisionLookup = MediaWikiServices::getInstance()->getRevisionLookup(); - - $undoRev = $revisionLookup->getRevisionById( $this->undo ); - $oldRev = $revisionLookup->getRevisionById( $this->undoafter ); + $undoRev = $this->revisionLookup->getRevisionById( $this->undo ); + $oldRev = $this->revisionLookup->getRevisionById( $this->undoafter ); if ( $undoRev === null || $oldRev === null || $undoRev->isDeleted( RevisionRecord::DELETED_TEXT ) || @@ -131,10 +153,8 @@ class McrUndoAction extends FormAction { * @return MutableRevisionRecord */ private function getNewRevision() { - $revisionLookup = MediaWikiServices::getInstance()->getRevisionLookup(); - - $undoRev = $revisionLookup->getRevisionById( $this->undo ); - $oldRev = $revisionLookup->getRevisionById( $this->undoafter ); + $undoRev = $this->revisionLookup->getRevisionById( $this->undo ); + $oldRev = $this->revisionLookup->getRevisionById( $this->undoafter ); $curRev = $this->curRev; $isLatest = $curRev->getId() === $undoRev->getId(); @@ -266,7 +286,7 @@ class McrUndoAction extends FormAction { $parserOptions->setIsSectionPreview( false ); $parserOptions->enableLimitReport(); - $parserOutput = MediaWikiServices::getInstance()->getRevisionRenderer() + $parserOutput = $this->revisionRenderer ->getRenderedRevision( $rev, $parserOptions, $this->context->getUser() ) ->getRevisionParserOutput(); $previewHTML = $parserOutput->getText( [ 'enableSectionEditLinks' => false ] ); @@ -323,8 +343,6 @@ class McrUndoAction extends FormAction { $newRev = $this->getNewRevision(); if ( !$newRev->hasSameContent( $curRev ) ) { - $revisionStore = MediaWikiServices::getInstance()->getRevisionStore(); - // Copy new slots into the PageUpdater, and remove any removed slots. // TODO: This interface is awful, there should be a way to just pass $newRev. // TODO: MCR: test this once we can store multiple slots @@ -339,8 +357,8 @@ class McrUndoAction extends FormAction { // The revision we revert to is specified by the undoafter param. // $oldRev is not null, we check this and more in getNewRevision() - $oldRev = $revisionStore->getRevisionById( $this->undoafter ); - $oldestRevertedRev = $revisionStore->getNextRevision( $oldRev ); + $oldRev = $this->revisionLookup->getRevisionById( $this->undoafter ); + $oldestRevertedRev = $this->revisionLookup->getNextRevision( $oldRev ); if ( $oldestRevertedRev ) { $updater->markAsRevert( EditResult::REVERT_UNDO, diff --git a/tests/phpunit/integration/includes/Storage/UndoIntegrationTest.php b/tests/phpunit/integration/includes/Storage/UndoIntegrationTest.php index 1f40f9dab35..06878fbd860 100644 --- a/tests/phpunit/integration/includes/Storage/UndoIntegrationTest.php +++ b/tests/phpunit/integration/includes/Storage/UndoIntegrationTest.php @@ -68,7 +68,9 @@ class UndoIntegrationTest extends MediaWikiIntegrationTestCase { $context->setOutput( $outputPage ); $context->setUser( $this->getTestSysop()->getUser() ); - return new class( $article, $context ) extends McrUndoAction { + $revisionRenderer = $this->getServiceContainer()->getRevisionRenderer(); + $revisionLookup = $this->getServiceContainer()->getRevisionLookup(); + return new class( $article, $context, $revisionLookup, $revisionRenderer ) extends McrUndoAction { public function show() { // Instead of trying to actually display anything, just initialize the class. $this->checkCanExecute( $this->getUser() );