]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/api/ApiRollback.php
MediaWiki 1.14.0
[autoinstallsdev/mediawiki.git] / includes / api / ApiRollback.php
1 <?php
2
3 /*
4  * Created on Jun 20, 2007
5  * API for MediaWiki 1.8+
6  *
7  * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write to the Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22  * http://www.gnu.org/copyleft/gpl.html
23  */
24
25 if (!defined('MEDIAWIKI')) {
26         // Eclipse helper - will be ignored in production
27         require_once ("ApiBase.php");
28 }
29
30 /**
31  * @ingroup API
32  */
33 class ApiRollback extends ApiBase {
34
35         public function __construct($main, $action) {
36                 parent :: __construct($main, $action);
37         }
38
39         public function execute() {
40                 $this->getMain()->requestWriteMode();
41                 $params = $this->extractRequestParams();
42
43                 $titleObj = NULL;
44                 if(!isset($params['title']))
45                         $this->dieUsageMsg(array('missingparam', 'title'));
46                 if(!isset($params['user']))
47                         $this->dieUsageMsg(array('missingparam', 'user'));
48                 if(!isset($params['token']))
49                         $this->dieUsageMsg(array('missingparam', 'token'));
50
51                 $titleObj = Title::newFromText($params['title']);
52                 if(!$titleObj)
53                         $this->dieUsageMsg(array('invalidtitle', $params['title']));
54                 if(!$titleObj->exists())
55                         $this->dieUsageMsg(array('notanarticle'));
56
57                 #We need to be able to revert IPs, but getCanonicalName rejects them
58                 $username = User::isIP($params['user'])
59                         ? $params['user']
60                         : User::getCanonicalName($params['user']);
61                 if(!$username)
62                         $this->dieUsageMsg(array('invaliduser', $params['user']));
63
64                 $articleObj = new Article($titleObj);
65                 $summary = (isset($params['summary']) ? $params['summary'] : "");
66                 $details = null;
67                 $retval = $articleObj->doRollback($username, $summary, $params['token'], $params['markbot'], $details);
68
69                 if($retval)
70                         // We don't care about multiple errors, just report one of them
71                         $this->dieUsageMsg(current($retval));
72
73                 $info = array(
74                         'title' => $titleObj->getPrefixedText(),
75                         'pageid' => $details['current']->getPage(),
76                         'summary' => $details['summary'],
77                         'revid' => $titleObj->getLatestRevID(),
78                         'old_revid' => $details['current']->getID(),
79                         'last_revid' => $details['target']->getID()
80                 );
81
82                 $this->getResult()->addValue(null, $this->getModuleName(), $info);
83         }
84
85         public function mustBePosted() { return true; }
86
87         public function getAllowedParams() {
88                 return array (
89                         'title' => null,
90                         'user' => null,
91                         'token' => null,
92                         'summary' => null,
93                         'markbot' => false
94                 );
95         }
96
97         public function getParamDescription() {
98                 return array (
99                         'title' => 'Title of the page you want to rollback.',
100                         'user' => 'Name of the user whose edits are to be rolled back. If set incorrectly, you\'ll get a badtoken error.',
101                         'token' => 'A rollback token previously retrieved through prop=revisions',
102                         'summary' => 'Custom edit summary. If not set, default summary will be used.',
103                         'markbot' => 'Mark the reverted edits and the revert as bot edits'
104                 );
105         }
106
107         public function getDescription() {
108                 return array(
109                                 'Undo the last edit to the page. If the last user who edited the page made multiple edits in a row,',
110                                 'they will all be rolled back.'
111                         );
112         }
113
114         protected function getExamples() {
115                 return array (
116                         'api.php?action=rollback&title=Main%20Page&user=Catrope&token=123ABC',
117                         'api.php?action=rollback&title=Main%20Page&user=217.121.114.116&token=123ABC&summary=Reverting%20vandalism&markbot=1'
118                 );
119         }
120
121         public function getVersion() {
122                 return __CLASS__ . ': $Id: ApiRollback.php 45043 2008-12-26 04:13:47Z mrzman $';
123         }
124 }