private $mUser = null;
public function execute() {
+ $user = $this->getUser();
$params = $this->extractRequestParams();
- // User and title already validated in call to getTokenSalt from Main
+ // WikiPage::doRollback needs a Web UI token, so get one of those if we
+ // validated based on an API rollback token.
+ $token = $params['token'];
+ if ( $user->matchEditToken( $token, 'rollback', $this->getRequest() ) ) {
+ $token = $this->getUser()->getEditToken(
+ $this->getWebUITokenSalt( $params ),
+ $this->getRequest()
+ );
+ }
+
$titleObj = $this->getRbTitle( $params );
$pageObj = WikiPage::factory( $titleObj );
$summary = $params['summary'];
$retval = $pageObj->doRollback(
$this->getRbUser( $params ),
$summary,
- $params['token'],
+ $token,
$params['markbot'],
$details,
- $this->getUser()
+ $user
);
if ( $retval ) {
ApiBase::PARAM_TYPE => 'string',
ApiBase::PARAM_REQUIRED => true
),
- 'token' => array(
- ApiBase::PARAM_TYPE => 'string',
- ApiBase::PARAM_REQUIRED => true
- ),
'summary' => '',
'markbot' => false,
'watchlist' => array(
'nochange'
),
),
- );
- }
-
- public function getParamDescription() {
- $p = $this->getModulePrefix();
-
- return array(
- 'title' => "Title of the page you want to roll back. Cannot be used together with {$p}pageid",
- 'pageid' => "Page ID of the page you want to roll back. 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 ' .
- "{$this->getModulePrefix()}prop=revisions",
- 'summary' => 'Custom edit summary. If empty, default summary will be used',
- 'markbot' => 'Mark the reverted edits and the revert as bot edits',
- 'watchlist' => 'Unconditionally add or remove the page from your watchlist, ' .
- 'use preferences or do not change watch',
- );
- }
-
- public function getDescription() {
- return array(
- 'Undo the last edit to the page. If the last user who edited the page made',
- 'multiple edits in a row, they will all be rolled back.'
+ 'token' => array(
+ // Standard definition automatically inserted
+ ApiBase::PARAM_HELP_MSG_APPEND => array( 'api-help-param-token-webui' ),
+ ),
);
}
public function needsToken() {
- return true;
+ return 'rollback';
}
- public function getTokenSalt() {
- $params = $this->extractRequestParams();
-
+ protected function getWebUITokenSalt( array $params ) {
return array(
$this->getRbTitle( $params )->getPrefixedText(),
$this->getRbUser( $params )
return $this->mTitleObj;
}
- public function getExamples() {
+ protected function getExamplesMessages() {
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'
+ 'action=rollback&title=Main%20Page&user=Example&token=123ABC' =>
+ 'apihelp-rollback-example-simple',
+ 'action=rollback&title=Main%20Page&user=192.0.2.5&' .
+ 'token=123ABC&summary=Reverting%20vandalism&markbot=1' =>
+ 'apihelp-rollback-example-summary',
);
}