aboutsummaryrefslogtreecommitdiffstats
path: root/includes/actions/McrRestoreAction.php
blob: 2348565bb50dcd1cc0710e813c5f4d099c9d5b66 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
 * Temporary action for restoring multi-content revisions
 * @file
 * @ingroup Actions
 */

use MediaWiki\HTMLForm\HTMLForm;

/**
 * Temporary action for restoring multi-content revisions.
 *
 * This is intended to go away when real MCR support is added to EditPage and
 * the standard revert-by-edit behavior can be implemented there instead.
 *
 * @ingroup Actions
 * @since 1.32
 */
class McrRestoreAction extends McrUndoAction {

	public function getName() {
		return 'mcrrestore';
	}

	public function getDescription() {
		return '';
	}

	protected function initFromParameters() {
		$curRev = $this->getWikiPage()->getRevisionRecord();
		if ( !$curRev ) {
			throw new ErrorPageError( 'mcrundofailed', 'nopagetext' );
		}
		$this->curRev = $curRev;
		$this->cur = $this->getRequest()->getInt( 'cur', $this->curRev->getId() );

		$this->undo = $this->cur;
		$this->undoafter = $this->getRequest()->getInt( 'restore' );

		if ( $this->undo == 0 || $this->undoafter == 0 ) {
			throw new ErrorPageError( 'mcrundofailed', 'mcrundo-missingparam' );
		}
	}

	protected function addStatePropagationFields( HTMLForm $form ) {
		$form->addHiddenField( 'restore', $this->undoafter );
		$form->addHiddenField( 'cur', $this->curRev->getId() );
	}

	protected function alterForm( HTMLForm $form ) {
		parent::alterForm( $form );

		$form->setWrapperLegendMsg( 'confirm-mcrrestore-title' );
	}

}