*/
use MediaWiki\MediaWikiServices;
-use MediaWiki\Storage\MutableRevisionRecord;
-use MediaWiki\Storage\RevisionRecord;
-use MediaWiki\Storage\SlotRecord;
+use MediaWiki\Revision\MutableRevisionRecord;
+use MediaWiki\Revision\RevisionRecord;
+use MediaWiki\Revision\SlotRecord;
/**
* Temporary action for MCR undos
*/
class McrUndoAction extends FormAction {
- private $undo = 0, $undoafter = 0, $cur = 0;
+ protected $undo = 0, $undoafter = 0, $cur = 0;
/** @param RevisionRecord|null */
- private $curRev = null;
+ protected $curRev = null;
public function getName() {
return 'mcrundo';
parent::show();
}
- protected function checkCanExecute( User $user ) {
- parent::checkCanExecute( $user );
-
+ protected function initFromParameters() {
$this->undoafter = $this->getRequest()->getInt( 'undoafter' );
$this->undo = $this->getRequest()->getInt( 'undo' );
}
$this->curRev = $curRev->getRevisionRecord();
$this->cur = $this->getRequest()->getInt( 'cur', $this->curRev->getId() );
+ }
+
+ protected function checkCanExecute( User $user ) {
+ parent::checkCanExecute( $user );
+
+ $this->initFromParameters();
$revisionLookup = MediaWikiServices::getInstance()->getRevisionLookup();
return $newRev;
}
- private function generateDiff() {
+ private function generateDiffOrPreview() {
$newRev = $this->getNewRevision();
if ( $newRev->hasSameContent( $this->curRev ) ) {
throw new ErrorPageError( 'mcrundofailed', 'undo-nochange' );
$newtitle = $this->context->msg( 'yourtext' )->parse();
if ( $this->getRequest()->getCheck( 'wpPreview' ) ) {
- $diffEngine->renderNewRevision();
+ $this->showPreview( $newRev );
return '';
} else {
$diffText = $diffEngine->getDiff( $oldtitle, $newtitle );
}
}
+ private function showPreview( RevisionRecord $rev ) {
+ // Mostly copied from EditPage::getPreviewText()
+ $out = $this->getOutput();
+
+ try {
+ $previewHTML = '';
+
+ # provide a anchor link to the form
+ $continueEditing = '<span class="mw-continue-editing">' .
+ '[[#mw-mcrundo-form|' .
+ $this->context->getLanguage()->getArrow() . ' ' .
+ $this->context->msg( 'continue-editing' )->text() . ']]</span>';
+
+ $note = $this->context->msg( 'previewnote' )->plain() . ' ' . $continueEditing;
+
+ $parserOptions = $this->page->makeParserOptions( $this->context );
+ $parserOptions->setIsPreview( true );
+ $parserOptions->setIsSectionPreview( false );
+ $parserOptions->enableLimitReport();
+
+ $parserOutput = MediaWikiServices::getInstance()->getRevisionRenderer()
+ ->getRenderedRevision( $rev, $parserOptions, $this->context->getUser() )
+ ->getRevisionParserOutput();
+ $previewHTML = $parserOutput->getText( [ 'enableSectionEditLinks' => false ] );
+
+ $out->addParserOutputMetadata( $parserOutput );
+ if ( count( $parserOutput->getWarnings() ) ) {
+ $note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() );
+ }
+ } catch ( MWContentSerializationException $ex ) {
+ $m = $this->context->msg(
+ 'content-failed-to-parse',
+ $ex->getMessage()
+ );
+ $note .= "\n\n" . $m->parse();
+ $previewHTML = '';
+ }
+
+ $previewhead = Html::rawElement(
+ 'div', [ 'class' => 'previewnote' ],
+ Html::element(
+ 'h2', [ 'id' => 'mw-previewheader' ],
+ $this->context->msg( 'preview' )->text()
+ ) .
+ $out->parseAsInterface( $note ) .
+ "<hr />"
+ );
+
+ $pageViewLang = $this->getTitle()->getPageViewLanguage();
+ $attribs = [ 'lang' => $pageViewLang->getHtmlCode(), 'dir' => $pageViewLang->getDir(),
+ 'class' => 'mw-content-' . $pageViewLang->getDir() ];
+ $previewHTML = Html::rawElement( 'div', $attribs, $previewHTML );
+
+ $out->addHtml( $previewhead . $previewHTML );
+ }
+
public function onSubmit( $data ) {
global $wgUseRCPatrol;
'vertical-label' => true,
'raw' => true,
'default' => function () {
- return $this->generateDiff();
+ return $this->generateDiffOrPreview();
}
],
'summary' => [
$labelAsPublish = $this->context->getConfig()->get( 'EditSubmitButtonLabelPublish' );
+ $form->setId( 'mw-mcrundo-form' );
$form->setSubmitName( 'wpSave' );
$form->setSubmitTooltip( $labelAsPublish ? 'publish' : 'save' );
$form->setSubmitTextMsg( $labelAsPublish ? 'publishchanges' : 'savechanges' );
'attribs' => Linker::tooltipAndAccesskeyAttribs( 'diff' ),
] );
+ $this->addStatePropagationFields( $form );
+ }
+
+ protected function addStatePropagationFields( HTMLForm $form ) {
$form->addHiddenField( 'undo', $this->undo );
$form->addHiddenField( 'undoafter', $this->undoafter );
$form->addHiddenField( 'cur', $this->curRev->getId() );