Merge "Http::getProxy() method to get proxy configuration"
[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 // TODO: use $this->useTransactionalTimeLimit(); when POST only
40 wfTransactionalTimeLimit();
41
42 $details = null;
43
44 $request = $this->getRequest();
45 $user = $this->getUser();
46
47 $result = $this->page->doRollback(
48 $request->getVal( 'from' ),
49 $request->getText( 'summary' ),
50 $request->getVal( 'token' ),
51 $request->getBool( 'bot' ),
52 $details,
53 $this->getUser()
54 );
55
56 if ( in_array( [ 'actionthrottledtext' ], $result ) ) {
57 throw new ThrottledError;
58 }
59
60 if ( isset( $result[0][0] ) &&
61 ( $result[0][0] == 'alreadyrolled' || $result[0][0] == 'cantrollback' )
62 ) {
63 $this->getOutput()->setPageTitle( $this->msg( 'rollbackfailed' ) );
64 $errArray = $result[0];
65 $errMsg = array_shift( $errArray );
66 $this->getOutput()->addWikiMsgArray( $errMsg, $errArray );
67
68 if ( isset( $details['current'] ) ) {
69 /** @var Revision $current */
70 $current = $details['current'];
71
72 if ( $current->getComment() != '' ) {
73 $this->getOutput()->addHTML( $this->msg( 'editcomment' )->rawParams(
74 Linker::formatComment( $current->getComment() ) )->parse() );
75 }
76 }
77
78 return;
79 }
80
81 # NOTE: Permission errors already handled by Action::checkExecute.
82
83 if ( $result == [ [ 'readonlytext' ] ] ) {
84 throw new ReadOnlyError;
85 }
86
87 # XXX: Would be nice if ErrorPageError could take multiple errors, and/or a status object.
88 # Right now, we only show the first error
89 foreach ( $result as $error ) {
90 throw new ErrorPageError( 'rollbackfailed', $error[0], array_slice( $error, 1 ) );
91 }
92
93 /** @var Revision $current */
94 $current = $details['current'];
95 $target = $details['target'];
96 $newId = $details['newid'];
97 $this->getOutput()->setPageTitle( $this->msg( 'actioncomplete' ) );
98 $this->getOutput()->setRobotPolicy( 'noindex,nofollow' );
99
100 $old = Linker::revUserTools( $current );
101 $new = Linker::revUserTools( $target );
102 $this->getOutput()->addHTML( $this->msg( 'rollback-success' )->rawParams( $old, $new )
103 ->parseAsBlock() );
104
105 if ( $user->getBoolOption( 'watchrollback' ) ) {
106 $user->addWatch( $this->page->getTitle(), User::IGNORE_USER_RIGHTS );
107 }
108
109 $this->getOutput()->returnToMain( false, $this->getTitle() );
110
111 if ( !$request->getBool( 'hidediff', false ) &&
112 !$this->getUser()->getBoolOption( 'norollbackdiff' )
113 ) {
114 $contentHandler = $current->getContentHandler();
115 $de = $contentHandler->createDifferenceEngine(
116 $this->getContext(),
117 $current->getId(),
118 $newId,
119 false,
120 true
121 );
122 $de->showDiff( '', '' );
123 }
124 }
125
126 protected function getDescription() {
127 return '';
128 }
129
130 public function doesWrites() {
131 return true;
132 }
133 }