Follow-up r67045. Delete it from the English message file too.
[mediawiki.git] / includes / api / ApiRollback.php
blobad5c16fcddd847ad3467758da83813c837976fb8
1 <?php
3 /*
4 * Created on Jun 20, 2007
5 * API for MediaWiki 1.8+
7 * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
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.
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.
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
25 if ( !defined( 'MEDIAWIKI' ) ) {
26 // Eclipse helper - will be ignored in production
27 require_once( "ApiBase.php" );
30 /**
31 * @ingroup API
33 class ApiRollback extends ApiBase {
35 public function __construct( $main, $action ) {
36 parent::__construct( $main, $action );
39 private $mTitleObj = null, $mUser = null;
41 public function execute() {
42 $params = $this->extractRequestParams();
44 // User and title already validated in call to getTokenSalt from Main
45 $titleObj = $this->getTitle();
46 $articleObj = new Article( $titleObj );
47 $summary = ( isset( $params['summary'] ) ? $params['summary'] : '' );
48 $details = null;
49 $retval = $articleObj->doRollback( $this->getUser(), $summary, $params['token'], $params['markbot'], $details );
51 if ( $retval ) {
52 // We don't care about multiple errors, just report one of them
53 $this->dieUsageMsg( reset( $retval ) );
56 $this->setWatch( $params['watchlist'], $titleObj );
58 $info = array(
59 'title' => $titleObj->getPrefixedText(),
60 'pageid' => intval( $details['current']->getPage() ),
61 'summary' => $details['summary'],
62 'revid' => intval( $details['newid'] ),
63 'old_revid' => intval( $details['current']->getID() ),
64 'last_revid' => intval( $details['target']->getID() )
67 $this->getResult()->addValue( null, $this->getModuleName(), $info );
70 public function mustBePosted() {
71 return true;
74 public function isWriteMode() {
75 return true;
78 public function getAllowedParams() {
79 return array(
80 'title' => null,
81 'user' => null,
82 'token' => null,
83 'summary' => null,
84 'markbot' => false,
85 'watchlist' => array(
86 ApiBase::PARAM_DFLT => 'preferences',
87 ApiBase::PARAM_TYPE => array(
88 'watch',
89 'unwatch',
90 'preferences',
91 'nochange'
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 {$this->getModulePrefix()}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 'watchlist' => 'Unconditionally add or remove the page from your watchlist, use preferences or do not change watch',
108 public function getDescription() {
109 return array(
110 'Undo the last edit to the page. If the last user who edited the page made multiple edits in a row,',
111 'they will all be rolled back'
115 public function getPossibleErrors() {
116 return array_merge( parent::getPossibleErrors(), array(
117 array( 'missingparam', 'title' ),
118 array( 'missingparam', 'user' ),
119 array( 'invalidtitle', 'title' ),
120 array( 'notanarticle' ),
121 array( 'invaliduser', 'user' ),
122 ) );
125 public function getTokenSalt() {
126 return array( $this->getTitle()->getPrefixedText(), $this->getUser() );
129 private function getUser() {
130 if ( $this->mUser !== null ) {
131 return $this->mUser;
134 $params = $this->extractRequestParams();
136 if ( !isset( $params['user'] ) ) {
137 $this->dieUsageMsg( array( 'missingparam', 'user' ) );
140 // We need to be able to revert IPs, but getCanonicalName rejects them
141 $this->mUser = User::isIP( $params['user'] )
142 ? $params['user']
143 : User::getCanonicalName( $params['user'] );
144 if ( !$this->mUser ) {
145 $this->dieUsageMsg( array( 'invaliduser', $params['user'] ) );
148 return $this->mUser;
151 private function getTitle() {
152 if ( $this->mTitleObj !== null ) {
153 return $this->mTitleObj;
156 $params = $this->extractRequestParams();
157 if ( !isset( $params['title'] ) ) {
158 $this->dieUsageMsg( array( 'missingparam', 'title' ) );
161 $this->mTitleObj = Title::newFromText( $params['title'] );
163 if ( !$this->mTitleObj ) {
164 $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
166 if ( !$this->mTitleObj->exists() ) {
167 $this->dieUsageMsg( array( 'notanarticle' ) );
170 return $this->mTitleObj;
173 protected function getExamples() {
174 return array(
175 'api.php?action=rollback&title=Main%20Page&user=Catrope&token=123ABC',
176 'api.php?action=rollback&title=Main%20Page&user=217.121.114.116&token=123ABC&summary=Reverting%20vandalism&markbot=1'
180 public function getVersion() {
181 return __CLASS__ . ': $Id$';