Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / actions / RollbackAction.php
blob76d70d70aff16929c1566641139296c11a2def42
1 <?php
2 /**
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
19 * @file
20 * @ingroup Actions
23 /**
24 * User interface for the rollback action
26 * @ingroup Actions
28 class RollbackAction extends FormlessAction {
30 public function getName() {
31 return 'rollback';
34 public function getRestriction() {
35 return 'rollback';
38 public function onView() {
39 $details = null;
41 $request = $this->getRequest();
42 $user = $this->getUser();
44 $result = $this->page->doRollback(
45 $request->getVal( 'from' ),
46 $request->getText( 'summary' ),
47 $request->getVal( 'token' ),
48 $request->getBool( 'bot' ),
49 $details,
50 $this->getUser()
53 if ( in_array( array( 'actionthrottledtext' ), $result ) ) {
54 throw new ThrottledError;
57 if ( isset( $result[0][0] ) &&
58 ( $result[0][0] == 'alreadyrolled' || $result[0][0] == 'cantrollback' )
59 ) {
60 $this->getOutput()->setPageTitle( $this->msg( 'rollbackfailed' ) );
61 $errArray = $result[0];
62 $errMsg = array_shift( $errArray );
63 $this->getOutput()->addWikiMsgArray( $errMsg, $errArray );
65 if ( isset( $details['current'] ) ) {
66 /** @var Revision $current */
67 $current = $details['current'];
69 if ( $current->getComment() != '' ) {
70 $this->getOutput()->addHTML( $this->msg( 'editcomment' )->rawParams(
71 Linker::formatComment( $current->getComment() ) )->parse() );
75 return;
78 #NOTE: Permission errors already handled by Action::checkExecute.
80 if ( $result == array( array( 'readonlytext' ) ) ) {
81 throw new ReadOnlyError;
84 #XXX: Would be nice if ErrorPageError could take multiple errors, and/or a status object.
85 # Right now, we only show the first error
86 foreach ( $result as $error ) {
87 throw new ErrorPageError( 'rollbackfailed', $error[0], array_slice( $error, 1 ) );
90 /** @var Revision $current */
91 $current = $details['current'];
92 $target = $details['target'];
93 $newId = $details['newid'];
94 $this->getOutput()->setPageTitle( $this->msg( 'actioncomplete' ) );
95 $this->getOutput()->setRobotPolicy( 'noindex,nofollow' );
97 $old = Linker::revUserTools( $current );
98 $new = Linker::revUserTools( $target );
99 $this->getOutput()->addHTML( $this->msg( 'rollback-success' )->rawParams( $old, $new )
100 ->parseAsBlock() );
102 if ( $user->getBoolOption( 'watchrollback' ) ) {
103 $user->addWatch( $this->page->getTitle(), WatchedItem::IGNORE_USER_RIGHTS );
106 $this->getOutput()->returnToMain( false, $this->getTitle() );
108 if ( !$request->getBool( 'hidediff', false ) &&
109 !$this->getUser()->getBoolOption( 'norollbackdiff', false )
111 $contentHandler = $current->getContentHandler();
112 $de = $contentHandler->createDifferenceEngine(
113 $this->getContext(),
114 $current->getId(),
115 $newId,
116 false,
117 true
119 $de->showDiff( '', '' );
123 protected function getDescription() {
124 return '';