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 FormlessAction
{
30 public function getName() {
34 public function getRestriction() {
39 * Temporarily unused message keys due to T88044/T136375:
40 * - confirm-rollback-top
41 * - confirm-rollback-button
43 * - rollback-missingparam
47 * @throws ErrorPageError
49 public function onView() {
50 // TODO: use $this->useTransactionalTimeLimit(); when POST only
51 wfTransactionalTimeLimit();
53 $request = $this->getRequest();
54 $user = $this->getUser();
55 $from = $request->getVal( 'from' );
56 $rev = $this->page
->getRevision();
57 if ( $from === null ) {
58 throw new ErrorPageError( 'rollbackfailed', 'rollback-missingparam' );
61 throw new ErrorPageError( 'rollbackfailed', 'rollback-missingrevision' );
63 if ( $from !== $rev->getUserText() ) {
64 throw new ErrorPageError( 'rollbackfailed', 'alreadyrolled', [
65 $this->getTitle()->getPrefixedText(),
72 $errors = $this->page
->doRollback(
74 $request->getText( 'summary' ),
75 $request->getVal( 'token' ),
76 $request->getBool( 'bot' ),
81 if ( in_array( [ 'actionthrottledtext' ], $errors ) ) {
82 throw new ThrottledError
;
85 if ( isset( $errors[0][0] ) &&
86 ( $errors[0][0] == 'alreadyrolled' ||
$errors[0][0] == 'cantrollback' )
88 $this->getOutput()->setPageTitle( $this->msg( 'rollbackfailed' ) );
89 $errArray = $errors[0];
90 $errMsg = array_shift( $errArray );
91 $this->getOutput()->addWikiMsgArray( $errMsg, $errArray );
93 if ( isset( $data['current'] ) ) {
94 /** @var Revision $current */
95 $current = $data['current'];
97 if ( $current->getComment() != '' ) {
98 $this->getOutput()->addHTML( $this->msg( 'editcomment' )->rawParams(
99 Linker
::formatComment( $current->getComment() ) )->parse() );
106 # NOTE: Permission errors already handled by Action::checkExecute.
107 if ( $errors == [ [ 'readonlytext' ] ] ) {
108 throw new ReadOnlyError
;
111 # XXX: Would be nice if ErrorPageError could take multiple errors, and/or a status object.
112 # Right now, we only show the first error
113 foreach ( $errors as $error ) {
114 throw new ErrorPageError( 'rollbackfailed', $error[0], array_slice( $error, 1 ) );
117 /** @var Revision $current */
118 $current = $data['current'];
119 $target = $data['target'];
120 $newId = $data['newid'];
121 $this->getOutput()->setPageTitle( $this->msg( 'actioncomplete' ) );
122 $this->getOutput()->setRobotPolicy( 'noindex,nofollow' );
124 $old = Linker
::revUserTools( $current );
125 $new = Linker
::revUserTools( $target );
126 $this->getOutput()->addHTML( $this->msg( 'rollback-success' )->rawParams( $old, $new )
129 if ( $user->getBoolOption( 'watchrollback' ) ) {
130 $user->addWatch( $this->page
->getTitle(), User
::IGNORE_USER_RIGHTS
);
133 $this->getOutput()->returnToMain( false, $this->getTitle() );
135 if ( !$request->getBool( 'hidediff', false ) &&
136 !$this->getUser()->getBoolOption( 'norollbackdiff' )
138 $contentHandler = $current->getContentHandler();
139 $de = $contentHandler->createDifferenceEngine(
146 $de->showDiff( '', '' );
151 protected function getDescription() {
155 public function doesWrites() {