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 usesOOUI() {
42 protected function getDescription() {
46 public function doesWrites() {
50 public function onSuccess() {
54 public function onSubmit( $data ) {
58 protected function alterForm( HTMLForm
$form ) {
59 $form->setWrapperLegendMsg( 'confirm-rollback-top' );
60 $form->setSubmitTextMsg( 'confirm-rollback-button' );
61 $form->setTokenSalt( 'rollback' );
63 $from = $this->getRequest()->getVal( 'from' );
64 if ( $from === null ) {
65 throw new BadRequestError( 'rollbackfailed', 'rollback-missingparam' );
67 foreach ( [ 'from', 'bot', 'hidediff', 'summary', 'token' ] as $param ) {
68 $val = $this->getRequest()->getVal( $param );
69 if ( $val !== null ) {
70 $form->addHiddenField( $param, $val );
76 * @throws ConfigException
77 * @throws ErrorPageError
78 * @throws ReadOnlyError
79 * @throws ThrottledError
81 public function show() {
84 * Remove temporary check of DisableRollbackConfirmationFeature
85 * after release of rollback feature. See T199534
87 $config = \MediaWiki\MediaWikiServices
::getInstance()->getMainConfig();
88 if ( $config->get( 'DisableRollbackConfirmationFeature' ) == true ||
89 $this->getUser()->getOption( 'showrollbackconfirmation' ) == false ||
90 $this->getRequest()->wasPosted() ) {
91 $this->handleRollbackRequest();
93 $this->showRollbackConfirmationForm();
97 public function handleRollbackRequest() {
98 $this->enableTransactionalTimelimit();
100 $request = $this->getRequest();
101 $user = $this->getUser();
102 $from = $request->getVal( 'from' );
103 $rev = $this->page
->getRevision();
104 if ( $from === null ) {
105 throw new ErrorPageError( 'rollbackfailed', 'rollback-missingparam' );
108 throw new ErrorPageError( 'rollbackfailed', 'rollback-missingrevision' );
110 if ( $from !== $rev->getUserText() ) {
111 throw new ErrorPageError( 'rollbackfailed', 'alreadyrolled', [
112 $this->getTitle()->getPrefixedText(),
119 $errors = $this->page
->doRollback(
121 $request->getText( 'summary' ),
122 $request->getVal( 'token' ),
123 $request->getBool( 'bot' ),
128 if ( in_array( [ 'actionthrottledtext' ], $errors ) ) {
129 throw new ThrottledError
;
132 if ( $this->hasRollbackRelatedErrors( $errors ) ) {
133 $this->getOutput()->setPageTitle( $this->msg( 'rollbackfailed' ) );
134 $errArray = $errors[0];
135 $errMsg = array_shift( $errArray );
136 $this->getOutput()->addWikiMsgArray( $errMsg, $errArray );
138 if ( isset( $data['current'] ) ) {
139 /** @var Revision $current */
140 $current = $data['current'];
142 if ( $current->getComment() != '' ) {
143 $this->getOutput()->addWikiMsg(
146 Linker
::formatComment( $current->getComment() )
155 # NOTE: Permission errors already handled by Action::checkExecute.
156 if ( $errors == [ [ 'readonlytext' ] ] ) {
157 throw new ReadOnlyError
;
160 # XXX: Would be nice if ErrorPageError could take multiple errors, and/or a status object.
161 # Right now, we only show the first error
162 foreach ( $errors as $error ) {
163 throw new ErrorPageError( 'rollbackfailed', $error[0], array_slice( $error, 1 ) );
166 /** @var Revision $current */
167 $current = $data['current'];
168 $target = $data['target'];
169 $newId = $data['newid'];
170 $this->getOutput()->setPageTitle( $this->msg( 'actioncomplete' ) );
171 $this->getOutput()->setRobotPolicy( 'noindex,nofollow' );
173 $old = Linker
::revUserTools( $current );
174 $new = Linker
::revUserTools( $target );
175 $this->getOutput()->addHTML(
176 $this->msg( 'rollback-success' )
177 ->rawParams( $old, $new )
178 ->params( $current->getUserText( Revision
::FOR_THIS_USER
, $user ) )
179 ->params( $target->getUserText( Revision
::FOR_THIS_USER
, $user ) )
183 if ( $user->getBoolOption( 'watchrollback' ) ) {
184 $user->addWatch( $this->page
->getTitle(), User
::IGNORE_USER_RIGHTS
);
187 $this->getOutput()->returnToMain( false, $this->getTitle() );
189 if ( !$request->getBool( 'hidediff', false ) &&
190 !$this->getUser()->getBoolOption( 'norollbackdiff' )
192 $contentHandler = $current->getContentHandler();
193 $de = $contentHandler->createDifferenceEngine(
200 $de->showDiff( '', '' );
205 * Enables transactional time limit for POST and GET requests to RollbackAction
206 * @throws ConfigException
208 private function enableTransactionalTimelimit() {
209 // If Rollbacks are made POST-only, use $this->useTransactionalTimeLimit()
210 wfTransactionalTimeLimit();
211 if ( !$this->getRequest()->wasPosted() ) {
213 * We apply the higher POST limits on GET requests
214 * to prevent logstash.wikimedia.org from being spammed
217 $trxLimits = $this->context
->getConfig()->get( 'TrxProfilerLimits' );
218 $trxProfiler = Profiler
::instance()->getTransactionProfiler();
219 $trxProfiler->redefineExpectations( $trxLimits['POST'], $fname );
220 DeferredUpdates
::addCallableUpdate( function () use ( $trxProfiler, $trxLimits, $fname
222 $trxProfiler->redefineExpectations( $trxLimits['PostSend-POST'], $fname );
227 private function showRollbackConfirmationForm() {
228 $form = $this->getForm();
229 if ( $form->show() ) {
234 protected function getFormFields() {
238 'vertical-label' => true,
240 'default' => $this->msg( 'confirm-rollback-bottom' )->parse()
245 private function hasRollbackRelatedErrors( array $errors ) {
246 return isset( $errors[0][0] ) &&
247 ( $errors[0][0] == 'alreadyrolled' ||
248 $errors[0][0] == 'cantrollback'