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
44 * - rollback-success-notify
48 * @throws ErrorPageError
50 public function onView() {
51 // TODO: use $this->useTransactionalTimeLimit(); when POST only
52 wfTransactionalTimeLimit();
54 $request = $this->getRequest();
55 $user = $this->getUser();
56 $from = $request->getVal( 'from' );
57 $rev = $this->page
->getRevision();
58 if ( $from === null ) {
59 throw new ErrorPageError( 'rollbackfailed', 'rollback-missingparam' );
62 throw new ErrorPageError( 'rollbackfailed', 'rollback-missingrevision' );
64 if ( $from !== $rev->getUserText() ) {
65 throw new ErrorPageError( 'rollbackfailed', 'alreadyrolled', [
66 $this->getTitle()->getPrefixedText(),
72 // @TODO: remove this hack once rollback uses POST (T88044)
73 $trxLimits = $this->context
->getConfig()->get( 'TrxProfilerLimits' );
74 $trxProfiler = Profiler
::instance()->getTransactionProfiler();
75 $trxProfiler->setExpectations( $trxLimits['POST'], __METHOD__
);
76 DeferredUpdates
::addCallableUpdate( function () use ( $trxProfiler, $trxLimits ) {
77 $trxProfiler->setExpectations( $trxLimits['PostSend-POST'], __METHOD__
);
81 $errors = $this->page
->doRollback(
83 $request->getText( 'summary' ),
84 $request->getVal( 'token' ),
85 $request->getBool( 'bot' ),
90 if ( in_array( [ 'actionthrottledtext' ], $errors ) ) {
91 throw new ThrottledError
;
94 if ( isset( $errors[0][0] ) &&
95 ( $errors[0][0] == 'alreadyrolled' ||
$errors[0][0] == 'cantrollback' )
97 $this->getOutput()->setPageTitle( $this->msg( 'rollbackfailed' ) );
98 $errArray = $errors[0];
99 $errMsg = array_shift( $errArray );
100 $this->getOutput()->addWikiMsgArray( $errMsg, $errArray );
102 if ( isset( $data['current'] ) ) {
103 /** @var Revision $current */
104 $current = $data['current'];
106 if ( $current->getComment() != '' ) {
107 $this->getOutput()->addWikiMsg(
110 Linker
::formatComment( $current->getComment() )
119 # NOTE: Permission errors already handled by Action::checkExecute.
120 if ( $errors == [ [ 'readonlytext' ] ] ) {
121 throw new ReadOnlyError
;
124 # XXX: Would be nice if ErrorPageError could take multiple errors, and/or a status object.
125 # Right now, we only show the first error
126 foreach ( $errors as $error ) {
127 throw new ErrorPageError( 'rollbackfailed', $error[0], array_slice( $error, 1 ) );
130 /** @var Revision $current */
131 $current = $data['current'];
132 $target = $data['target'];
133 $newId = $data['newid'];
134 $this->getOutput()->setPageTitle( $this->msg( 'actioncomplete' ) );
135 $this->getOutput()->setRobotPolicy( 'noindex,nofollow' );
137 $old = Linker
::revUserTools( $current );
138 $new = Linker
::revUserTools( $target );
139 $this->getOutput()->addHTML(
140 $this->msg( 'rollback-success' )
141 ->rawParams( $old, $new )
142 ->params( $current->getUserText( Revision
::FOR_THIS_USER
, $user ) )
143 ->params( $target->getUserText( Revision
::FOR_THIS_USER
, $user ) )
147 if ( $user->getBoolOption( 'watchrollback' ) ) {
148 $user->addWatch( $this->page
->getTitle(), User
::IGNORE_USER_RIGHTS
);
151 $this->getOutput()->returnToMain( false, $this->getTitle() );
153 if ( !$request->getBool( 'hidediff', false ) &&
154 !$this->getUser()->getBoolOption( 'norollbackdiff' )
156 $contentHandler = $current->getContentHandler();
157 $de = $contentHandler->createDifferenceEngine(
164 $de->showDiff( '', '' );
168 protected function getDescription() {
172 public function doesWrites() {