Merge "Remove 'prefsnologin' message, don't use 'watchnologin' where inappropriate"
[lhc/web/wiklou.git] / includes / actions / RollbackAction.php
1 <?php
2 /**
3 * Edit rollback user interface
4 *
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.
9 *
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.
14 *
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
18 *
19 * @file
20 * @ingroup Actions
21 */
22
23 /**
24 * User interface for the rollback action
25 *
26 * @ingroup Actions
27 */
28 class RollbackAction extends FormlessAction {
29
30 public function getName() {
31 return 'rollback';
32 }
33
34 public function getRestriction() {
35 return 'rollback';
36 }
37
38 public function onView() {
39 $details = null;
40
41 $request = $this->getRequest();
42
43 $result = $this->page->doRollback(
44 $request->getVal( 'from' ),
45 $request->getText( 'summary' ),
46 $request->getVal( 'token' ),
47 $request->getBool( 'bot' ),
48 $details,
49 $this->getUser()
50 );
51
52 if ( in_array( array( 'actionthrottledtext' ), $result ) ) {
53 throw new ThrottledError;
54 }
55
56 if ( isset( $result[0][0] ) &&
57 ( $result[0][0] == 'alreadyrolled' || $result[0][0] == 'cantrollback' )
58 ) {
59 $this->getOutput()->setPageTitle( $this->msg( 'rollbackfailed' ) );
60 $errArray = $result[0];
61 $errMsg = array_shift( $errArray );
62 $this->getOutput()->addWikiMsgArray( $errMsg, $errArray );
63
64 if ( isset( $details['current'] ) ) {
65 $current = $details['current'];
66
67 if ( $current->getComment() != '' ) {
68 $this->getOutput()->addHTML( $this->msg( 'editcomment' )->rawParams(
69 Linker::formatComment( $current->getComment() ) )->parse() );
70 }
71 }
72
73 return;
74 }
75
76 #NOTE: Permission errors already handled by Action::checkExecute.
77
78 if ( $result == array( array( 'readonlytext' ) ) ) {
79 throw new ReadOnlyError;
80 }
81
82 #XXX: Would be nice if ErrorPageError could take multiple errors, and/or a status object.
83 # Right now, we only show the first error
84 foreach ( $result as $error ) {
85 throw new ErrorPageError( 'rollbackfailed', $error[0], array_slice( $error, 1 ) );
86 }
87
88 $current = $details['current'];
89 $target = $details['target'];
90 $newId = $details['newid'];
91 $this->getOutput()->setPageTitle( $this->msg( 'actioncomplete' ) );
92 $this->getOutput()->setRobotPolicy( 'noindex,nofollow' );
93
94 $old = Linker::revUserTools( $current );
95 $new = Linker::revUserTools( $target );
96 $this->getOutput()->addHTML( $this->msg( 'rollback-success' )->rawParams( $old, $new )
97 ->parseAsBlock() );
98 $this->getOutput()->returnToMain( false, $this->getTitle() );
99
100 if ( !$request->getBool( 'hidediff', false ) &&
101 !$this->getUser()->getBoolOption( 'norollbackdiff', false )
102 ) {
103 $contentHandler = $current->getContentHandler();
104 $de = $contentHandler->createDifferenceEngine(
105 $this->getContext(),
106 $current->getId(),
107 $newId,
108 false,
109 true
110 );
111 $de->showDiff( '', '' );
112 }
113 }
114
115 protected function getDescription() {
116 return '';
117 }
118 }