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
00048 $titleObj = Title::newFromText( $params['title'] );
00049 if ( !$titleObj )
00050 $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
00051 if ( !$titleObj->exists() )
00052 $this->dieUsageMsg( array( 'notanarticle' ) );
00053
00054
00055 $username = User::isIP( $params['user'] )
00056 ? $params['user']
00057 : User::getCanonicalName( $params['user'] );
00058 if ( !$username )
00059 $this->dieUsageMsg( array( 'invaliduser', $params['user'] ) );
00060
00061 $articleObj = new Article( $titleObj );
00062 $summary = ( isset( $params['summary'] ) ? $params['summary'] : "" );
00063 $details = null;
00064 $retval = $articleObj->doRollback( $username, $summary, $params['token'], $params['markbot'], $details );
00065
00066 if ( $retval )
00067
00068 $this->dieUsageMsg( reset( $retval ) );
00069
00070 $info = array(
00071 'title' => $titleObj->getPrefixedText(),
00072 'pageid' => intval( $details['current']->getPage() ),
00073 'summary' => $details['summary'],
00074 'revid' => intval( $details['newid'] ),
00075 'old_revid' => intval( $details['current']->getID() ),
00076 'last_revid' => intval( $details['target']->getID() )
00077 );
00078
00079 $this->getResult()->addValue( null, $this->getModuleName(), $info );
00080 }
00081
00082 public function mustBePosted() { return true; }
00083
00084 public function isWriteMode() {
00085 return true;
00086 }
00087
00088 public function getAllowedParams() {
00089 return array (
00090 'title' => null,
00091 'user' => null,
00092 'token' => null,
00093 'summary' => null,
00094 'markbot' => false
00095 );
00096 }
00097
00098 public function getParamDescription() {
00099 return array (
00100 'title' => 'Title of the page you want to rollback.',
00101 'user' => 'Name of the user whose edits are to be rolled back. If set incorrectly, you\'ll get a badtoken error.',
00102 'token' => 'A rollback token previously retrieved through prop=revisions',
00103 'summary' => 'Custom edit summary. If not set, default summary will be used.',
00104 'markbot' => 'Mark the reverted edits and the revert as bot edits'
00105 );
00106 }
00107
00108 public function getDescription() {
00109 return array(
00110 'Undo the last edit to the page. If the last user who edited the page made multiple edits in a row,',
00111 'they will all be rolled back.'
00112 );
00113 }
00114
00115 public function getPossibleErrors() {
00116 return array_merge( parent::getPossibleErrors(), array(
00117 array( 'missingparam', 'title' ),
00118 array( 'missingparam', 'user' ),
00119 array( 'invalidtitle', 'title' ),
00120 array( 'notanarticle' ),
00121 array( 'invaliduser', 'user' ),
00122 ) );
00123 }
00124
00125 protected function getExamples() {
00126 return array (
00127 'api.php?action=rollback&title=Main%20Page&user=Catrope&token=123ABC',
00128 'api.php?action=rollback&title=Main%20Page&user=217.121.114.116&token=123ABC&summary=Reverting%20vandalism&markbot=1'
00129 );
00130 }
00131
00132 public function getVersion() {
00133 return __CLASS__ . ': $Id: ApiRollback.php 65371 2010-04-21 10:41:25Z tstarling $';
00134 }
00135 }