From: Sam Reed Date: Sat, 21 May 2011 16:38:40 +0000 (+0000) Subject: * (bug 29070) Add token to action=watch X-Git-Tag: 1.31.0-rc.0~30038 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22lang_raccourcis%22%2C%22module=%24nom_module%22%29%20.%20%22?a=commitdiff_plain;h=d993a1578c756ab14fe711900c1b891446e53b1d;p=lhc%2Fweb%2Fwiklou.git * (bug 29070) Add token to action=watch --- diff --git a/RELEASE-NOTES-1.19 b/RELEASE-NOTES-1.19 index 67703b4725..f98d25871d 100644 --- a/RELEASE-NOTES-1.19 +++ b/RELEASE-NOTES-1.19 @@ -83,6 +83,7 @@ production. * (bug 28578) API's parse module should not silently override invalid title inputs * (bug 20699) API watchlist should list log-events +* (bug 29070) Add token to action=watch === Languages updated in 1.19 === diff --git a/includes/api/ApiQueryInfo.php b/includes/api/ApiQueryInfo.php index 8a6e570421..707a24c207 100644 --- a/includes/api/ApiQueryInfo.php +++ b/includes/api/ApiQueryInfo.php @@ -98,6 +98,7 @@ class ApiQueryInfo extends ApiQueryBase { 'unblock' => array( 'ApiQueryInfo', 'getUnblockToken' ), 'email' => array( 'ApiQueryInfo', 'getEmailToken' ), 'import' => array( 'ApiQueryInfo', 'getImportToken' ), + 'watch' => array( 'ApiQueryInfo', 'getWatchToken'), ); wfRunHooks( 'APIQueryInfoTokens', array( &$this->tokenFunctions ) ); return $this->tokenFunctions; @@ -217,6 +218,21 @@ class ApiQueryInfo extends ApiQueryBase { return $cachedImportToken; } + public static function getWatchToken( $pageid, $title ) { + global $wgUser; + if ( !$wgUser->isLoggedIn() ) { + return false; + } + + static $cachedWatchToken = null; + if ( !is_null( $cachedWatchToken ) ) { + return $cachedWatchToken; + } + + $cachedWatchToken = $wgUser->editToken( 'watch' ); + return $cachedWatchToken; + } + public function execute() { $this->params = $this->extractRequestParams(); if ( !is_null( $this->params['prop'] ) ) { diff --git a/includes/api/ApiWatch.php b/includes/api/ApiWatch.php index 7eb61689f2..bb38b4232e 100644 --- a/includes/api/ApiWatch.php +++ b/includes/api/ApiWatch.php @@ -71,18 +71,30 @@ class ApiWatch extends ApiBase { $this->getResult()->addValue( null, $this->getModuleName(), $res ); } + public function mustBePosted() { + return true; + } + public function isWriteMode() { return true; } + public function needsToken() { + return true; + } + + public function getTokenSalt() { + return 'watch'; + } + public function getAllowedParams() { return array( 'title' => array( ApiBase::PARAM_TYPE => 'string', ApiBase::PARAM_REQUIRED => true ), - 'unwatch' => false, + 'token' => null, ); } @@ -90,6 +102,7 @@ class ApiWatch extends ApiBase { return array( 'title' => 'The page to (un)watch', 'unwatch' => 'If set the page will be unwatched rather than watched', + 'token' => 'A token previously acquired via prop=info', ); }