2007-12-06 16:06:22 +00:00
|
|
|
<?php
|
2010-08-07 19:59:42 +00:00
|
|
|
/**
|
2010-12-22 20:52:06 +00:00
|
|
|
*
|
2007-12-06 16:06:22 +00:00
|
|
|
*
|
2010-08-07 19:59:42 +00:00
|
|
|
* Created on Jun 20, 2007
|
|
|
|
|
*
|
2012-07-15 20:13:02 +00:00
|
|
|
* Copyright © 2007 Roan Kattouw "<Firstname>.<Lastname>@gmail.com"
|
2007-12-06 16:06:22 +00:00
|
|
|
*
|
|
|
|
|
* 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.,
|
2010-06-21 13:13:32 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2007-12-06 16:06:22 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
2010-08-07 19:59:42 +00:00
|
|
|
*
|
|
|
|
|
* @file
|
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 {
|
|
|
|
|
|
2011-02-27 21:10:11 +00:00
|
|
|
/**
|
|
|
|
|
* @var Title
|
|
|
|
|
*/
|
|
|
|
|
private $mTitleObj = null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var User
|
|
|
|
|
*/
|
|
|
|
|
private $mUser = null;
|
2007-12-06 16:06:22 +00:00
|
|
|
|
|
|
|
|
public function execute() {
|
2015-08-08 00:08:33 +00:00
|
|
|
$this->useTransactionalTimeLimit();
|
|
|
|
|
|
2014-08-08 16:56:07 +00:00
|
|
|
$user = $this->getUser();
|
2007-12-06 16:06:22 +00:00
|
|
|
$params = $this->extractRequestParams();
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2014-08-08 16:56:07 +00:00
|
|
|
// WikiPage::doRollback needs a Web UI token, so get one of those if we
|
|
|
|
|
// validated based on an API rollback token.
|
|
|
|
|
$token = $params['token'];
|
|
|
|
|
if ( $user->matchEditToken( $token, 'rollback', $this->getRequest() ) ) {
|
|
|
|
|
$token = $this->getUser()->getEditToken(
|
|
|
|
|
$this->getWebUITokenSalt( $params ),
|
|
|
|
|
$this->getRequest()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-13 14:29:22 +00:00
|
|
|
$titleObj = $this->getRbTitle( $params );
|
2011-11-12 07:36:41 +00:00
|
|
|
$pageObj = WikiPage::factory( $titleObj );
|
2012-07-07 07:12:04 +00:00
|
|
|
$summary = $params['summary'];
|
2016-02-17 09:09:32 +00:00
|
|
|
$details = [];
|
2015-12-15 23:45:37 +00:00
|
|
|
|
|
|
|
|
// If change tagging was requested, check that the user is allowed to tag,
|
|
|
|
|
// and the tags are valid
|
|
|
|
|
if ( count( $params['tags'] ) ) {
|
|
|
|
|
$tagStatus = ChangeTags::canAddTagsAccompanyingChange( $params['tags'], $user );
|
|
|
|
|
if ( !$tagStatus->isOK() ) {
|
|
|
|
|
$this->dieStatus( $tagStatus );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-14 13:31:56 +00:00
|
|
|
$retval = $pageObj->doRollback(
|
2014-05-13 14:29:22 +00:00
|
|
|
$this->getRbUser( $params ),
|
2013-11-14 13:31:56 +00:00
|
|
|
$summary,
|
2014-08-08 16:56:07 +00:00
|
|
|
$token,
|
2013-11-14 13:31:56 +00:00
|
|
|
$params['markbot'],
|
|
|
|
|
$details,
|
2016-02-09 09:05:23 +00:00
|
|
|
$user,
|
|
|
|
|
$params['tags']
|
2013-11-14 13:31:56 +00:00
|
|
|
);
|
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-04-10 06:11:02 +00:00
|
|
|
|
2014-07-15 12:32:16 +00:00
|
|
|
$watch = 'preferences';
|
|
|
|
|
if ( isset( $params['watchlist'] ) ) {
|
|
|
|
|
$watch = $params['watchlist'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Watch pages
|
|
|
|
|
$this->setWatch( $watch, $titleObj, 'watchrollback' );
|
2008-01-15 20:21:16 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$info = [
|
2010-04-10 13:33:24 +00:00
|
|
|
'title' => $titleObj->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() )
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
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() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2014-05-13 11:42:10 +00:00
|
|
|
'title' => null,
|
2016-02-17 09:09:32 +00:00
|
|
|
'pageid' => [
|
2014-05-13 11:42:10 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'integer'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'tags' => [
|
2016-01-20 09:51:01 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'tags',
|
2015-12-15 23:45:37 +00:00
|
|
|
ApiBase::PARAM_ISMULTI => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'user' => [
|
2016-01-04 18:55:26 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'user',
|
2010-08-04 14:29:39 +00:00
|
|
|
ApiBase::PARAM_REQUIRED => true
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2012-07-07 07:12:04 +00:00
|
|
|
'summary' => '',
|
2010-03-25 22:15:08 +00:00
|
|
|
'markbot' => false,
|
2016-02-17 09:09:32 +00:00
|
|
|
'watchlist' => [
|
2010-03-25 22:15:08 +00:00
|
|
|
ApiBase::PARAM_DFLT => 'preferences',
|
2016-02-17 09:09:32 +00:00
|
|
|
ApiBase::PARAM_TYPE => [
|
2010-03-25 22:15:08 +00:00
|
|
|
'watch',
|
|
|
|
|
'unwatch',
|
|
|
|
|
'preferences',
|
|
|
|
|
'nochange'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'token' => [
|
2014-09-18 17:38:23 +00:00
|
|
|
// Standard definition automatically inserted
|
2016-02-17 09:09:32 +00:00
|
|
|
ApiBase::PARAM_HELP_MSG_APPEND => [ 'api-help-param-token-webui' ],
|
|
|
|
|
],
|
|
|
|
|
];
|
2007-12-06 16:06:22 +00:00
|
|
|
}
|
2010-02-26 13:18:56 +00:00
|
|
|
|
2010-10-01 20:12:50 +00:00
|
|
|
public function needsToken() {
|
2014-08-08 16:56:07 +00:00
|
|
|
return 'rollback';
|
2010-10-01 20:12:50 +00:00
|
|
|
}
|
|
|
|
|
|
2014-08-08 16:56:07 +00:00
|
|
|
protected function getWebUITokenSalt( array $params ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2014-05-13 14:29:22 +00:00
|
|
|
$this->getRbTitle( $params )->getPrefixedText(),
|
|
|
|
|
$this->getRbUser( $params )
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2010-04-10 13:33:24 +00:00
|
|
|
}
|
|
|
|
|
|
2014-05-13 14:29:22 +00:00
|
|
|
/**
|
|
|
|
|
* @param array $params
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
private function getRbUser( array $params ) {
|
2010-04-10 13:33:24 +00:00
|
|
|
if ( $this->mUser !== null ) {
|
|
|
|
|
return $this->mUser;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-09 20:05:33 +00:00
|
|
|
// We need to be able to revert IPs, but getCanonicalName rejects them
|
2010-04-10 13:33:24 +00:00
|
|
|
$this->mUser = User::isIP( $params['user'] )
|
2010-04-09 20:05:33 +00:00
|
|
|
? $params['user']
|
|
|
|
|
: User::getCanonicalName( $params['user'] );
|
2010-04-10 13:33:24 +00:00
|
|
|
if ( !$this->mUser ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->dieUsageMsg( [ 'invaliduser', $params['user'] ] );
|
2010-04-09 20:05:33 +00:00
|
|
|
}
|
2010-04-10 13:33:24 +00:00
|
|
|
|
|
|
|
|
return $this->mUser;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-28 00:04:48 +00:00
|
|
|
/**
|
2014-05-13 14:29:22 +00:00
|
|
|
* @param array $params
|
|
|
|
|
*
|
2010-10-28 00:04:48 +00:00
|
|
|
* @return Title
|
|
|
|
|
*/
|
2014-05-13 14:29:22 +00:00
|
|
|
private function getRbTitle( array $params ) {
|
2010-04-10 13:33:24 +00:00
|
|
|
if ( $this->mTitleObj !== null ) {
|
|
|
|
|
return $this->mTitleObj;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-13 14:29:22 +00:00
|
|
|
$this->requireOnlyOneParameter( $params, 'title', 'pageid' );
|
2010-04-10 13:33:24 +00:00
|
|
|
|
2014-05-13 11:42:10 +00:00
|
|
|
if ( isset( $params['title'] ) ) {
|
|
|
|
|
$this->mTitleObj = Title::newFromText( $params['title'] );
|
|
|
|
|
if ( !$this->mTitleObj || $this->mTitleObj->isExternal() ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->dieUsageMsg( [ 'invalidtitle', $params['title'] ] );
|
2014-05-13 11:42:10 +00:00
|
|
|
}
|
|
|
|
|
} elseif ( isset( $params['pageid'] ) ) {
|
|
|
|
|
$this->mTitleObj = Title::newFromID( $params['pageid'] );
|
|
|
|
|
if ( !$this->mTitleObj ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->dieUsageMsg( [ 'nosuchpageid', $params['pageid'] ] );
|
2014-05-13 11:42:10 +00:00
|
|
|
}
|
2010-04-09 20:05:33 +00:00
|
|
|
}
|
2014-05-13 11:42:10 +00:00
|
|
|
|
2010-04-09 20:05:33 +00:00
|
|
|
if ( !$this->mTitleObj->exists() ) {
|
2011-05-19 17:51:16 +00:00
|
|
|
$this->dieUsageMsg( 'notanarticle' );
|
2010-04-09 20:05:33 +00:00
|
|
|
}
|
2010-07-23 07:33:40 +00:00
|
|
|
|
2010-04-10 13:33:24 +00:00
|
|
|
return $this->mTitleObj;
|
2010-02-14 22:20:27 +00:00
|
|
|
}
|
2007-12-06 16:06:22 +00:00
|
|
|
|
2014-10-28 17:17:02 +00:00
|
|
|
protected function getExamplesMessages() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2014-09-18 17:38:23 +00:00
|
|
|
'action=rollback&title=Main%20Page&user=Example&token=123ABC' =>
|
|
|
|
|
'apihelp-rollback-example-simple',
|
|
|
|
|
'action=rollback&title=Main%20Page&user=192.0.2.5&' .
|
|
|
|
|
'token=123ABC&summary=Reverting%20vandalism&markbot=1' =>
|
|
|
|
|
'apihelp-rollback-example-summary',
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2007-12-06 16:06:22 +00:00
|
|
|
}
|
|
|
|
|
|
2011-07-17 16:38:24 +00:00
|
|
|
public function getHelpUrls() {
|
2011-11-28 15:43:11 +00:00
|
|
|
return 'https://www.mediawiki.org/wiki/API:Rollback';
|
2011-07-17 16:38:24 +00:00
|
|
|
}
|
2007-12-06 16:06:22 +00:00
|
|
|
}
|