From: addshore Date: Tue, 13 May 2014 11:42:10 +0000 (+0100) Subject: Allow use of ApiRollback using pageid instead of title X-Git-Tag: 1.31.0-rc.0~15737 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/password.php?a=commitdiff_plain;h=21de2cffb6d1779823e40d2a6a3c6332676194cc;p=lhc%2Fweb%2Fwiklou.git Allow use of ApiRollback using pageid instead of title Change-Id: I9c4e4fa59af0b84416d950f1428da821318f85fc --- diff --git a/includes/api/ApiRollback.php b/includes/api/ApiRollback.php index 70a2fec29b..7c893d2f65 100644 --- a/includes/api/ApiRollback.php +++ b/includes/api/ApiRollback.php @@ -85,9 +85,9 @@ class ApiRollback extends ApiBase { public function getAllowedParams() { return array( - 'title' => array( - ApiBase::PARAM_TYPE => 'string', - ApiBase::PARAM_REQUIRED => true + 'title' => null, + 'pageid' => array( + ApiBase::PARAM_TYPE => 'integer' ), 'user' => array( ApiBase::PARAM_TYPE => 'string', @@ -112,8 +112,11 @@ class ApiRollback extends ApiBase { } public function getParamDescription() { + $p = $this->getModulePrefix(); + return array( - 'title' => 'Title of the page you want to rollback.', + 'title' => "Title of the page you want to delete. Cannot be used together with {$p}pageid", + 'pageid' => "Page ID of the page you want to delete. Cannot be used together with {$p}title", 'user' => 'Name of the user whose edits are to be rolled back. If ' . 'set incorrectly, you\'ll get a badtoken error.', 'token' => 'A rollback token previously retrieved through ' . @@ -149,6 +152,7 @@ class ApiRollback extends ApiBase { return array_merge( parent::getPossibleErrors(), array( array( 'invalidtitle', 'title' ), array( 'notanarticle' ), + array( 'nosuchpageid', 'pageid' ), array( 'invaliduser', 'user' ), ) ); } @@ -189,11 +193,18 @@ class ApiRollback extends ApiBase { $params = $this->extractRequestParams(); - $this->mTitleObj = Title::newFromText( $params['title'] ); - - if ( !$this->mTitleObj || $this->mTitleObj->isExternal() ) { - $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) ); + if ( isset( $params['title'] ) ) { + $this->mTitleObj = Title::newFromText( $params['title'] ); + if ( !$this->mTitleObj || $this->mTitleObj->isExternal() ) { + $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) ); + } + } elseif ( isset( $params['pageid'] ) ) { + $this->mTitleObj = Title::newFromID( $params['pageid'] ); + if ( !$this->mTitleObj ) { + $this->dieUsageMsg( array( 'nosuchpageid', $params['pageid'] ) ); + } } + if ( !$this->mTitleObj->exists() ) { $this->dieUsageMsg( 'notanarticle' ); } @@ -204,6 +215,7 @@ class ApiRollback extends ApiBase { public function getExamples() { return array( 'api.php?action=rollback&title=Main%20Page&user=Catrope&token=123ABC', + 'api.php?action=rollback&pageid=122&user=Catrope&token=123ABC', 'api.php?action=rollback&title=Main%20Page&user=217.121.114.116&' . 'token=123ABC&summary=Reverting%20vandalism&markbot=1' );