$params = $this->extractRequestParams();
// User and title already validated in call to getTokenSalt from Main
- $titleObj = $this->getRbTitle();
+ $titleObj = $this->getRbTitle( $params );
$pageObj = WikiPage::factory( $titleObj );
$summary = $params['summary'];
$details = array();
$retval = $pageObj->doRollback(
- $this->getRbUser(),
+ $this->getRbUser( $params ),
$summary,
$params['token'],
$params['markbot'],
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',
}
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 ' .
}
public function getPossibleErrors() {
- return array_merge( parent::getPossibleErrors(), array(
- array( 'invalidtitle', 'title' ),
- array( 'notanarticle' ),
- array( 'invaliduser', 'user' ),
- ) );
+ return array_merge(
+ parent::getPossibleErrors(),
+ $this->getRequireOnlyOneParameterErrorMessages( array( 'title', 'pageid' ) ),
+ array(
+ array( 'invalidtitle', 'title' ),
+ array( 'notanarticle' ),
+ array( 'nosuchpageid', 'pageid' ),
+ array( 'invaliduser', 'user' ),
+ )
+ );
}
public function needsToken() {
}
public function getTokenSalt() {
- return array( $this->getRbTitle()->getPrefixedText(), $this->getRbUser() );
+ $params = $this->extractRequestParams();
+
+ return array(
+ $this->getRbTitle( $params )->getPrefixedText(),
+ $this->getRbUser( $params )
+ );
}
- private function getRbUser() {
+ /**
+ * @param array $params
+ *
+ * @return string
+ */
+ private function getRbUser( array $params ) {
if ( $this->mUser !== null ) {
return $this->mUser;
}
- $params = $this->extractRequestParams();
-
// We need to be able to revert IPs, but getCanonicalName rejects them
$this->mUser = User::isIP( $params['user'] )
? $params['user']
}
/**
+ * @param array $params
+ *
* @return Title
*/
- private function getRbTitle() {
+ private function getRbTitle( array $params ) {
if ( $this->mTitleObj !== null ) {
return $this->mTitleObj;
}
- $params = $this->extractRequestParams();
-
- $this->mTitleObj = Title::newFromText( $params['title'] );
-
- if ( !$this->mTitleObj || $this->mTitleObj->isExternal() ) {
- $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
+ $this->requireOnlyOneParameter( $params, 'title', 'pageid' );
+
+ 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' );
}
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'
);