http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88522

Revision: 88522
Author:   reedy
Date:     2011-05-21 16:38:40 +0000 (Sat, 21 May 2011)
Log Message:
-----------
* (bug 29070) Add token to action=watch

Modified Paths:
--------------
    trunk/phase3/RELEASE-NOTES-1.19
    trunk/phase3/includes/api/ApiQueryInfo.php
    trunk/phase3/includes/api/ApiWatch.php

Modified: trunk/phase3/RELEASE-NOTES-1.19
===================================================================
--- trunk/phase3/RELEASE-NOTES-1.19     2011-05-21 16:15:12 UTC (rev 88521)
+++ trunk/phase3/RELEASE-NOTES-1.19     2011-05-21 16:38:40 UTC (rev 88522)
@@ -83,6 +83,7 @@
 * (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 ===
 

Modified: trunk/phase3/includes/api/ApiQueryInfo.php
===================================================================
--- trunk/phase3/includes/api/ApiQueryInfo.php  2011-05-21 16:15:12 UTC (rev 
88521)
+++ trunk/phase3/includes/api/ApiQueryInfo.php  2011-05-21 16:38:40 UTC (rev 
88522)
@@ -98,6 +98,7 @@
                        '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 @@
                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'] ) ) {

Modified: trunk/phase3/includes/api/ApiWatch.php
===================================================================
--- trunk/phase3/includes/api/ApiWatch.php      2011-05-21 16:15:12 UTC (rev 
88521)
+++ trunk/phase3/includes/api/ApiWatch.php      2011-05-21 16:38:40 UTC (rev 
88522)
@@ -71,18 +71,30 @@
                $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 @@
                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',
                );
        }
 


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to