3 * Edit rollback user interface
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 * User interface for the rollback action
28 class RollbackAction
extends FormAction
{
30 public function getName() {
34 public function getRestriction() {
38 protected function preText() {
39 return $this->msg( 'confirm-rollback-top' )->parse();
42 protected function alterForm( HTMLForm
$form ) {
43 $form->setSubmitTextMsg( 'confirm-rollback-button' );
44 $form->setTokenSalt( 'rollback' );
46 // Copy parameters from GET to confirmation form
47 $from = $this->getRequest()->getVal( 'from' );
48 if ( $from === null ) {
49 throw new BadRequestError( 'rollbackfailed', 'rollback-missingparam' );
51 foreach ( [ 'from', 'bot', 'hidediff', 'summary' ] as $param ) {
52 $val = $this->getRequest()->getVal( $param );
53 if ( $val !== null ) {
54 $form->addHiddenField( $param, $val );
60 * This must return true so that HTMLForm::show() will not display the form again after
61 * submission. For rollback, display either the form or the result (success/error)
65 * @throws ErrorPageError
67 public function onSubmit( $data ) {
68 $this->useTransactionalTimeLimit();
70 $request = $this->getRequest();
71 $user = $this->getUser();
72 $from = $request->getVal( 'from' );
73 $rev = $this->page
->getRevision();
74 if ( $from === null ||
$from === '' ) {
75 throw new ErrorPageError( 'rollbackfailed', 'rollback-missingparam' );
77 if ( $from !== $rev->getUserText() ) {
78 throw new ErrorPageError( 'rollbackfailed', 'alreadyrolled', [
79 $this->getTitle()->getPrefixedText(),
86 $errors = $this->page
->doRollback(
88 $request->getText( 'summary' ),
89 // Provided by HTMLForm
90 $request->getVal( 'wpEditToken' ),
91 $request->getBool( 'bot' ),
96 if ( in_array( [ 'actionthrottledtext' ], $errors ) ) {
97 throw new ThrottledError
;
100 if ( isset( $errors[0][0] ) &&
101 ( $errors[0][0] == 'alreadyrolled' ||
$errors[0][0] == 'cantrollback' )
103 $this->getOutput()->setPageTitle( $this->msg( 'rollbackfailed' ) );
104 $errArray = $errors[0];
105 $errMsg = array_shift( $errArray );
106 $this->getOutput()->addWikiMsgArray( $errMsg, $errArray );
108 if ( isset( $data['current'] ) ) {
109 /** @var Revision $current */
110 $current = $data['current'];
112 if ( $current->getComment() != '' ) {
113 $this->getOutput()->addHTML( $this->msg( 'editcomment' )->rawParams(
114 Linker
::formatComment( $current->getComment() ) )->parse() );
121 # NOTE: Permission errors already handled by Action::checkExecute.
122 if ( $errors == [ [ 'readonlytext' ] ] ) {
123 throw new ReadOnlyError
;
126 # XXX: Would be nice if ErrorPageError could take multiple errors, and/or a status object.
127 # Right now, we only show the first error
128 foreach ( $errors as $error ) {
129 throw new ErrorPageError( 'rollbackfailed', $error[0], array_slice( $error, 1 ) );
132 /** @var Revision $current */
133 $current = $data['current'];
134 $target = $data['target'];
135 $newId = $data['newid'];
136 $this->getOutput()->setPageTitle( $this->msg( 'actioncomplete' ) );
137 $this->getOutput()->setRobotPolicy( 'noindex,nofollow' );
139 $old = Linker
::revUserTools( $current );
140 $new = Linker
::revUserTools( $target );
141 $this->getOutput()->addHTML( $this->msg( 'rollback-success' )->rawParams( $old, $new )
144 if ( $user->getBoolOption( 'watchrollback' ) ) {
145 $user->addWatch( $this->page
->getTitle(), User
::IGNORE_USER_RIGHTS
);
148 $this->getOutput()->returnToMain( false, $this->getTitle() );
150 if ( !$request->getBool( 'hidediff', false ) &&
151 !$this->getUser()->getBoolOption( 'norollbackdiff' )
153 $contentHandler = $current->getContentHandler();
154 $de = $contentHandler->createDifferenceEngine(
161 $de->showDiff( '', '' );
166 public function onSuccess() {
167 // Required by parent class, but redundant because onSubmit already shows
168 // the success message when needed.
171 protected function getDescription() {
175 public function doesWrites() {