00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 if (!defined('MEDIAWIKI')) {
00026
00027 require_once ("ApiBase.php");
00028 }
00029
00033 class ApiRollback extends ApiBase {
00034
00035 public function __construct($main, $action) {
00036 parent :: __construct($main, $action);
00037 }
00038
00039 public function execute() {
00040 $params = $this->extractRequestParams();
00041
00042 $titleObj = NULL;
00043 if(!isset($params['title']))
00044 $this->dieUsageMsg(array('missingparam', 'title'));
00045 if(!isset($params['user']))
00046 $this->dieUsageMsg(array('missingparam', 'user'));
00047 if(!isset($params['token']))
00048 $this->dieUsageMsg(array('missingparam', 'token'));
00049
00050 $titleObj = Title::newFromText($params['title']);
00051 if(!$titleObj)
00052 $this->dieUsageMsg(array('invalidtitle', $params['title']));
00053 if(!$titleObj->exists())
00054 $this->dieUsageMsg(array('notanarticle'));
00055
00056 #We need to be able to revert IPs, but getCanonicalName rejects them
00057 $username = User::isIP($params['user'])
00058 ? $params['user']
00059 : User::getCanonicalName($params['user']);
00060 if(!$username)
00061 $this->dieUsageMsg(array('invaliduser', $params['user']));
00062
00063 $articleObj = new Article($titleObj);
00064 $summary = (isset($params['summary']) ? $params['summary'] : "");
00065 $details = null;
00066 $retval = $articleObj->doRollback($username, $summary, $params['token'], $params['markbot'], $details);
00067
00068 if($retval)
00069
00070 $this->dieUsageMsg(reset($retval));
00071
00072 $info = array(
00073 'title' => $titleObj->getPrefixedText(),
00074 'pageid' => intval($details['current']->getPage()),
00075 'summary' => $details['summary'],
00076 'revid' => intval($titleObj->getLatestRevID()),
00077 'old_revid' => intval($details['current']->getID()),
00078 'last_revid' => intval($details['target']->getID())
00079 );
00080
00081 $this->getResult()->addValue(null, $this->getModuleName(), $info);
00082 }
00083
00084 public function mustBePosted() { return true; }
00085
00086 public function isWriteMode() {
00087 return true;
00088 }
00089
00090 public function getAllowedParams() {
00091 return array (
00092 'title' => null,
00093 'user' => null,
00094 'token' => null,
00095 'summary' => null,
00096 'markbot' => false
00097 );
00098 }
00099
00100 public function getParamDescription() {
00101 return array (
00102 'title' => 'Title of the page you want to rollback.',
00103 'user' => 'Name of the user whose edits are to be rolled back. If set incorrectly, you\'ll get a badtoken error.',
00104 'token' => 'A rollback token previously retrieved through prop=revisions',
00105 'summary' => 'Custom edit summary. If not set, default summary will be used.',
00106 'markbot' => 'Mark the reverted edits and the revert as bot edits'
00107 );
00108 }
00109
00110 public function getDescription() {
00111 return array(
00112 'Undo the last edit to the page. If the last user who edited the page made multiple edits in a row,',
00113 'they will all be rolled back.'
00114 );
00115 }
00116
00117 protected function getExamples() {
00118 return array (
00119 'api.php?action=rollback&title=Main%20Page&user=Catrope&token=123ABC',
00120 'api.php?action=rollback&title=Main%20Page&user=217.121.114.116&token=123ABC&summary=Reverting%20vandalism&markbot=1'
00121 );
00122 }
00123
00124 public function getVersion() {
00125 return __CLASS__ . ': $Id: ApiRollback.php 48122 2009-03-07 12:58:41Z catrope $';
00126 }
00127 }