X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiRollback.php;h=f4d3c5414d29681ca94b05f576b0257386056f97;hb=cda108df67691b0a9ebcfe8e79cbf7aeb9aebc52;hp=80e09b689a2beb419a82f62c9453d7cd44d7e2e3;hpb=3b658a2dd3339dce93ad74984eb0120f6c50ccd9;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiRollback.php b/includes/api/ApiRollback.php index 80e09b689a..f4d3c5414d 100644 --- a/includes/api/ApiRollback.php +++ b/includes/api/ApiRollback.php @@ -40,9 +40,19 @@ class ApiRollback extends ApiBase { 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']; @@ -50,10 +60,10 @@ class ApiRollback extends ApiBase { $retval = $pageObj->doRollback( $this->getRbUser( $params ), $summary, - $params['token'], + $token, $params['markbot'], $details, - $this->getUser() + $user ); if ( $retval ) { @@ -61,7 +71,13 @@ class ApiRollback extends ApiBase { $this->dieUsageMsg( reset( $retval ) ); } - $this->setWatch( $params['watchlist'], $titleObj ); + $watch = 'preferences'; + if ( isset( $params['watchlist'] ) ) { + $watch = $params['watchlist']; + } + + // Watch pages + $this->setWatch( $watch, $titleObj, 'watchrollback' ); $info = array( 'title' => $titleObj->getPrefixedText(), @@ -93,10 +109,6 @@ class ApiRollback extends ApiBase { ApiBase::PARAM_TYPE => 'string', ApiBase::PARAM_REQUIRED => true ), - 'token' => array( - ApiBase::PARAM_TYPE => 'string', - ApiBase::PARAM_REQUIRED => true - ), 'summary' => '', 'markbot' => false, 'watchlist' => array( @@ -117,10 +129,11 @@ class ApiRollback extends ApiBase { 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, ' . @@ -128,19 +141,6 @@ class ApiRollback extends ApiBase { ); } - 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', @@ -148,26 +148,11 @@ class ApiRollback extends ApiBase { ); } - 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 )