2007-12-06 16:06:22 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Created on Jun 20, 2007
|
|
|
|
|
* API for MediaWiki 1.8+
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*/
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( !defined( 'MEDIAWIKI' ) ) {
|
2007-12-06 16:06:22 +00:00
|
|
|
// Eclipse helper - will be ignored in production
|
2010-02-26 13:18:56 +00:00
|
|
|
require_once( "ApiBase.php" );
|
2007-12-06 16:06:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup API
|
2007-12-06 16:06:22 +00:00
|
|
|
*/
|
|
|
|
|
class ApiRollback extends ApiBase {
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
public function __construct( $main, $action ) {
|
2010-02-26 13:18:56 +00:00
|
|
|
parent::__construct( $main, $action );
|
2007-12-06 16:06:22 +00:00
|
|
|
}
|
2010-04-09 20:05:33 +00:00
|
|
|
|
|
|
|
|
private $mTitleObj = null;
|
2007-12-06 16:06:22 +00:00
|
|
|
|
|
|
|
|
public function execute() {
|
|
|
|
|
$params = $this->extractRequestParams();
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-04-09 20:05:33 +00:00
|
|
|
// User and title already validated in call to getTokenSalt from Main
|
2007-12-06 16:06:22 +00:00
|
|
|
|
2010-04-09 20:05:33 +00:00
|
|
|
$articleObj = new Article( $this->mTitleObj );
|
2010-02-26 13:18:56 +00:00
|
|
|
$summary = ( isset( $params['summary'] ) ? $params['summary'] : '' );
|
2008-01-15 20:21:16 +00:00
|
|
|
$details = null;
|
2010-04-10 04:31:43 +00:00
|
|
|
$retval = $articleObj->doRollback( $params['user'], $summary, $params['token'], $params['markbot'], $details );
|
2007-12-06 16:06:22 +00:00
|
|
|
|
2010-02-26 13:18:56 +00:00
|
|
|
if ( $retval ) {
|
2008-01-18 14:34:14 +00:00
|
|
|
// We don't care about multiple errors, just report one of them
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( reset( $retval ) );
|
2010-02-26 13:18:56 +00:00
|
|
|
}
|
2010-03-25 22:15:08 +00:00
|
|
|
|
2010-04-09 20:05:33 +00:00
|
|
|
$watch = $this->getWatchlistValue( $params['watchlist'], $this->mTitleObj );
|
2010-03-25 22:15:08 +00:00
|
|
|
|
2010-03-28 15:08:45 +00:00
|
|
|
if ( $watch !== null) {
|
|
|
|
|
if ( $watch ) {
|
|
|
|
|
$articleObj->doWatch();
|
|
|
|
|
} else {
|
|
|
|
|
$articleObj->doUnwatch();
|
|
|
|
|
}
|
2010-03-25 22:15:08 +00:00
|
|
|
}
|
2008-01-15 20:21:16 +00:00
|
|
|
|
2007-12-06 16:06:22 +00:00
|
|
|
$info = array(
|
2010-04-09 20:05:33 +00:00
|
|
|
'title' => $this->mTitleObj->getPrefixedText(),
|
2010-01-11 15:55:52 +00:00
|
|
|
'pageid' => intval( $details['current']->getPage() ),
|
2008-12-17 16:34:01 +00:00
|
|
|
'summary' => $details['summary'],
|
2010-01-11 15:55:52 +00:00
|
|
|
'revid' => intval( $details['newid'] ),
|
|
|
|
|
'old_revid' => intval( $details['current']->getID() ),
|
|
|
|
|
'last_revid' => intval( $details['target']->getID() )
|
2007-12-06 16:06:22 +00:00
|
|
|
);
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->getResult()->addValue( null, $this->getModuleName(), $info );
|
2007-12-06 16:06:22 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-02-26 13:18:56 +00:00
|
|
|
public function mustBePosted() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2009-03-06 13:49:44 +00:00
|
|
|
public function isWriteMode() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
public function getAllowedParams() {
|
2010-02-26 13:18:56 +00:00
|
|
|
return array(
|
2007-12-06 16:06:22 +00:00
|
|
|
'title' => null,
|
|
|
|
|
'user' => null,
|
|
|
|
|
'token' => null,
|
|
|
|
|
'summary' => null,
|
2010-03-25 22:15:08 +00:00
|
|
|
'markbot' => false,
|
|
|
|
|
'watchlist' => array(
|
|
|
|
|
ApiBase::PARAM_DFLT => 'preferences',
|
|
|
|
|
ApiBase::PARAM_TYPE => array(
|
|
|
|
|
'watch',
|
|
|
|
|
'unwatch',
|
|
|
|
|
'preferences',
|
|
|
|
|
'nochange'
|
|
|
|
|
),
|
|
|
|
|
),
|
2007-12-06 16:06:22 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
public function getParamDescription() {
|
2010-02-26 13:18:56 +00:00
|
|
|
return array(
|
2007-12-06 16:06:22 +00:00
|
|
|
'title' => 'Title of the page you want to rollback.',
|
|
|
|
|
'user' => 'Name of the user whose edits are to be rolled back. If set incorrectly, you\'ll get a badtoken error.',
|
2008-12-26 04:13:47 +00:00
|
|
|
'token' => 'A rollback token previously retrieved through prop=revisions',
|
2007-12-06 16:06:22 +00:00
|
|
|
'summary' => 'Custom edit summary. If not set, default summary will be used.',
|
2010-03-25 22:15:08 +00:00
|
|
|
'markbot' => 'Mark the reverted edits and the revert as bot edits',
|
|
|
|
|
'watchlist' => 'Unconditionally add or remove the page from your watchlist, use preferences or do not change watch',
|
2007-12-06 16:06:22 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
public function getDescription() {
|
2007-12-06 16:06:22 +00:00
|
|
|
return array(
|
2010-02-26 13:18:56 +00:00
|
|
|
'Undo the last edit to the page. If the last user who edited the page made multiple edits in a row,',
|
|
|
|
|
'they will all be rolled back.'
|
|
|
|
|
);
|
2007-12-06 16:06:22 +00:00
|
|
|
}
|
2010-02-26 13:18:56 +00:00
|
|
|
|
2010-02-14 14:29:24 +00:00
|
|
|
public function getPossibleErrors() {
|
2010-02-13 00:28:27 +00:00
|
|
|
return array_merge( parent::getPossibleErrors(), array(
|
|
|
|
|
array( 'missingparam', 'title' ),
|
|
|
|
|
array( 'missingparam', 'user' ),
|
|
|
|
|
array( 'invalidtitle', 'title' ),
|
|
|
|
|
array( 'notanarticle' ),
|
|
|
|
|
array( 'invaliduser', 'user' ),
|
2010-02-14 14:29:24 +00:00
|
|
|
) );
|
2010-02-13 00:28:27 +00:00
|
|
|
}
|
2010-02-26 13:18:56 +00:00
|
|
|
|
2010-02-15 23:53:43 +00:00
|
|
|
public function getTokenSalt() {
|
2010-04-09 20:05:33 +00:00
|
|
|
$params = $this->extractRequestParams();
|
|
|
|
|
|
|
|
|
|
if ( !isset( $params['user'] ) ) {
|
|
|
|
|
$this->dieUsageMsg( array( 'missingparam', 'user' ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We need to be able to revert IPs, but getCanonicalName rejects them
|
|
|
|
|
$this->username = User::isIP( $params['user'] )
|
|
|
|
|
? $params['user']
|
|
|
|
|
: User::getCanonicalName( $params['user'] );
|
|
|
|
|
if ( !$this->username ) {
|
|
|
|
|
$this->dieUsageMsg( array( 'invaliduser', $params['user'] ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !isset( $params['title'] ) ) {
|
|
|
|
|
$this->dieUsageMsg( array( 'missingparam', 'title' ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->mTitleObj = Title::newFromText( $params['title'] );
|
|
|
|
|
if ( !$this->mTitleObj ) {
|
|
|
|
|
$this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
|
|
|
|
|
}
|
|
|
|
|
if ( !$this->mTitleObj->exists() ) {
|
|
|
|
|
$this->dieUsageMsg( array( 'notanarticle' ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return array( $this->mTitleObj->getPrefixedText(), $this->username );
|
2010-02-14 22:20:27 +00:00
|
|
|
}
|
2007-12-06 16:06:22 +00:00
|
|
|
|
|
|
|
|
protected function getExamples() {
|
2010-02-26 13:18:56 +00:00
|
|
|
return array(
|
2007-12-06 16:06:22 +00:00
|
|
|
'api.php?action=rollback&title=Main%20Page&user=Catrope&token=123ABC',
|
|
|
|
|
'api.php?action=rollback&title=Main%20Page&user=217.121.114.116&token=123ABC&summary=Reverting%20vandalism&markbot=1'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getVersion() {
|
2007-12-06 18:33:18 +00:00
|
|
|
return __CLASS__ . ': $Id$';
|
2007-12-06 16:06:22 +00:00
|
|
|
}
|
|
|
|
|
}
|