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(
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",
+ 'user' => 'Name of the user whose edits are to be rolled back.',
+ 'token' => array(
+ /* Standard description automatically prepended */
+ 'For compatibility, the token used in the web UI is also accepted.'
+ ),
'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, ' .
);
}
- public function getResultProperties() {
- return array(
- '' => array(
- 'title' => 'string',
- 'pageid' => 'integer',
- 'summary' => 'string',
- 'revid' => 'integer',
- 'old_revid' => 'integer',
- 'last_revid' => 'integer'
- )
- );
- }
-
public function getDescription() {
return array(
'Undo the last edit to the page. If the last user who edited the page made',
);
}
- public function getPossibleErrors() {
- 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() {
- return true;
+ return 'rollback';
}
- public function getTokenSalt() {
- $params = $this->extractRequestParams();
-
+ protected function getWebUITokenSalt( array $params ) {
return array(
$this->getRbTitle( $params )->getPrefixedText(),
$this->getRbUser( $params )