From 222b01f5169f1c7e69762e0e8904c24f78f71882 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Wed, 28 Jul 2010 11:52:48 +0200 Subject: update to MediaWiki 1.16.0 --- includes/api/ApiRollback.php | 76 ++++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 34 deletions(-) (limited to 'includes/api/ApiRollback.php') diff --git a/includes/api/ApiRollback.php b/includes/api/ApiRollback.php index 0f0eae10..5c259f4e 100644 --- a/includes/api/ApiRollback.php +++ b/includes/api/ApiRollback.php @@ -22,9 +22,9 @@ * http://www.gnu.org/copyleft/gpl.html */ -if (!defined('MEDIAWIKI')) { +if ( !defined( 'MEDIAWIKI' ) ) { // Eclipse helper - will be ignored in production - require_once ("ApiBase.php"); + require_once ( "ApiBase.php" ); } /** @@ -32,53 +32,51 @@ if (!defined('MEDIAWIKI')) { */ class ApiRollback extends ApiBase { - public function __construct($main, $action) { - parent :: __construct($main, $action); + public function __construct( $main, $action ) { + parent :: __construct( $main, $action ); } public function execute() { $params = $this->extractRequestParams(); - $titleObj = NULL; - if(!isset($params['title'])) - $this->dieUsageMsg(array('missingparam', 'title')); - if(!isset($params['user'])) - $this->dieUsageMsg(array('missingparam', 'user')); - if(!isset($params['token'])) - $this->dieUsageMsg(array('missingparam', 'token')); - - $titleObj = Title::newFromText($params['title']); - if(!$titleObj) - $this->dieUsageMsg(array('invalidtitle', $params['title'])); - if(!$titleObj->exists()) - $this->dieUsageMsg(array('notanarticle')); - - #We need to be able to revert IPs, but getCanonicalName rejects them - $username = User::isIP($params['user']) + $titleObj = null; + if ( !isset( $params['title'] ) ) + $this->dieUsageMsg( array( 'missingparam', 'title' ) ); + if ( !isset( $params['user'] ) ) + $this->dieUsageMsg( array( 'missingparam', 'user' ) ); + + $titleObj = Title::newFromText( $params['title'] ); + if ( !$titleObj ) + $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) ); + if ( !$titleObj->exists() ) + $this->dieUsageMsg( array( 'notanarticle' ) ); + + // We need to be able to revert IPs, but getCanonicalName rejects them + $username = User::isIP( $params['user'] ) ? $params['user'] - : User::getCanonicalName($params['user']); - if(!$username) - $this->dieUsageMsg(array('invaliduser', $params['user'])); + : User::getCanonicalName( $params['user'] ); + if ( !$username ) + $this->dieUsageMsg( array( 'invaliduser', $params['user'] ) ); - $articleObj = new Article($titleObj); - $summary = (isset($params['summary']) ? $params['summary'] : ""); + $articleObj = new Article( $titleObj ); + $summary = ( isset( $params['summary'] ) ? $params['summary'] : "" ); $details = null; - $retval = $articleObj->doRollback($username, $summary, $params['token'], $params['markbot'], $details); + $retval = $articleObj->doRollback( $username, $summary, $params['token'], $params['markbot'], $details ); - if($retval) + if ( $retval ) // We don't care about multiple errors, just report one of them - $this->dieUsageMsg(reset($retval)); + $this->dieUsageMsg( reset( $retval ) ); $info = array( 'title' => $titleObj->getPrefixedText(), - 'pageid' => intval($details['current']->getPage()), + 'pageid' => intval( $details['current']->getPage() ), 'summary' => $details['summary'], - 'revid' => intval($titleObj->getLatestRevID()), - 'old_revid' => intval($details['current']->getID()), - 'last_revid' => intval($details['target']->getID()) + 'revid' => intval( $details['newid'] ), + 'old_revid' => intval( $details['current']->getID() ), + 'last_revid' => intval( $details['target']->getID() ) ); - $this->getResult()->addValue(null, $this->getModuleName(), $info); + $this->getResult()->addValue( null, $this->getModuleName(), $info ); } public function mustBePosted() { return true; } @@ -113,6 +111,16 @@ class ApiRollback extends ApiBase { 'they will all be rolled back.' ); } + + public function getPossibleErrors() { + return array_merge( parent::getPossibleErrors(), array( + array( 'missingparam', 'title' ), + array( 'missingparam', 'user' ), + array( 'invalidtitle', 'title' ), + array( 'notanarticle' ), + array( 'invaliduser', 'user' ), + ) ); + } protected function getExamples() { return array ( @@ -122,6 +130,6 @@ class ApiRollback extends ApiBase { } public function getVersion() { - return __CLASS__ . ': $Id: ApiRollback.php 48122 2009-03-07 12:58:41Z catrope $'; + return __CLASS__ . ': $Id: ApiRollback.php 65371 2010-04-21 10:41:25Z tstarling $'; } } -- cgit v1.2.2