* (bug 29070) Add token to action=watch
authorSam Reed <reedy@users.mediawiki.org>
Sat, 21 May 2011 16:38:40 +0000 (16:38 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Sat, 21 May 2011 16:38:40 +0000 (16:38 +0000)
RELEASE-NOTES-1.19
includes/api/ApiQueryInfo.php
includes/api/ApiWatch.php

index 67703b4..f98d258 100644 (file)
@@ -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 ===
 
index 8a6e570..707a24c 100644 (file)
@@ -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'] ) ) {
index 7eb6168..bb38b42 100644 (file)
@@ -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',
                );
        }