0d9a9027277ca89a1859ea9a0acf70b902eb974c
[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] ) && ( $result[0][0] == 'alreadyrolled' || $result[0][0] == 'cantrollback' ) ) {
57 $this->getOutput()->setPageTitle( $this->msg( 'rollbackfailed' ) );
58 $errArray = $result[0];
59 $errMsg = array_shift( $errArray );
60 $this->getOutput()->addWikiMsgArray( $errMsg, $errArray );
61
62 if ( isset( $details['current'] ) ) {
63 $current = $details['current'];
64
65 if ( $current->getComment() != '' ) {
66 $this->getOutput()->addHTML( $this->msg( 'editcomment' )->rawParams(
67 Linker::formatComment( $current->getComment() ) )->parse() );
68 }
69 }
70
71 return;
72 }
73
74 # Display permissions errors before read-only message -- there's no
75 # point in misleading the user into thinking the inability to rollback
76 # is only temporary.
77 if ( !empty( $result ) && $result !== array( array( 'readonlytext' ) ) ) {
78 # array_diff is completely broken for arrays of arrays, sigh.
79 # Remove any 'readonlytext' error manually.
80 $out = array();
81 foreach ( $result as $error ) {
82 if ( $error != array( 'readonlytext' ) ) {
83 $out [] = $error;
84 }
85 }
86 throw new PermissionsError( 'rollback', $out );
87 }
88
89 if ( $result == array( array( 'readonlytext' ) ) ) {
90 throw new ReadOnlyError;
91 }
92
93 $current = $details['current'];
94 $target = $details['target'];
95 $newId = $details['newid'];
96 $this->getOutput()->setPageTitle( $this->msg( 'actioncomplete' ) );
97 $this->getOutput()->setRobotPolicy( 'noindex,nofollow' );
98
99 if ( $current->getUserText() === '' ) {
100 $old = $this->msg( 'rev-deleted-user' )->escaped();
101 } else {
102 $old = Linker::userLink( $current->getUser(), $current->getUserText() )
103 . Linker::userToolLinks( $current->getUser(), $current->getUserText() );
104 }
105
106 $new = Linker::userLink( $target->getUser(), $target->getUserText() )
107 . Linker::userToolLinks( $target->getUser(), $target->getUserText() );
108 $this->getOutput()->addHTML( $this->msg( 'rollback-success' )->rawParams( $old, $new )->parseAsBlock() );
109 $this->getOutput()->returnToMain( false, $this->getTitle() );
110
111 if ( !$request->getBool( 'hidediff', false ) && !$this->getUser()->getBoolOption( 'norollbackdiff', false ) ) {
112 $de = new DifferenceEngine( $this->getContext(), $current->getId(), $newId, false, true );
113 $de->showDiff( '', '' );
114 }
115 }
116
117 protected function getDescription() {
118 return '';
119 }
120 }