Inject services into Mcr(Undo|Restore)Action

Bug: T253078
Change-Id: I7519f41df37a47a56bfb2d4419b52860ca1bb732
This commit is contained in:
DannyS712 2021-08-02 01:48:46 +00:00
parent 0450da0f52
commit b8b44a6de9
3 changed files with 49 additions and 17 deletions

View file

@ -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' => [

View file

@ -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,

View file

@ -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() );