Move optionstoken from meta=userinfo to action=tokens.
authorSzymon Świerkosz <beau@adres.pl>
Fri, 4 May 2012 10:31:08 +0000 (12:31 +0200)
committerSzymon Świerkosz <beau@adres.pl>
Sun, 6 May 2012 14:07:17 +0000 (16:07 +0200)
Follow up to I0d6c654a7354ba77e65e338423952a6a78c1150f.
I have also added a URL to a help page on mw.org.

Change-Id: Ie223930cfc313aff150e2dcfd70b74bf4360a8a8

includes/api/ApiOptions.php
includes/api/ApiQueryInfo.php
includes/api/ApiQueryUserInfo.php
includes/api/ApiTokens.php

index 61da785..7bcfe1e 100644 (file)
@@ -109,7 +109,7 @@ class ApiOptions extends ApiBase {
 
        public function getParamDescription() {
                return array(
-                       'token' => 'An options token previously obtained through the meta=userinfo',
+                       'token' => 'An options token previously obtained through the action=tokens',
                        'reset' => 'Resets all preferences to the site defaults',
                        'change' => 'Pipe-separated list of changes, formatted name=value (e.g. skin=vector), value cannot contain pipe characters',
                        'optionname' => 'A name of a option which should have an optionvalue set',
@@ -136,6 +136,10 @@ class ApiOptions extends ApiBase {
                return '';
        }
 
+       public function getHelpUrls() {
+               return 'https://www.mediawiki.org/wiki/API:Options';
+       }
+
        public function getExamples() {
                return array(
                        'api.php?action=options&reset=&token=123ABC',
index d28642a..e5db4d8 100644 (file)
@@ -228,6 +228,21 @@ class ApiQueryInfo extends ApiQueryBase {
                return $cachedWatchToken;
        }
 
+       public static function getOptionsToken( $pageid, $title ) {
+               global $wgUser;
+               if ( !$wgUser->isLoggedIn() ) {
+                       return false;
+               }
+
+               static $cachedOptionsToken = null;
+               if ( !is_null( $cachedOptionsToken ) ) {
+                       return $cachedOptionsToken;
+               }
+
+               $cachedOptionsToken = $wgUser->getEditToken();
+               return $cachedOptionsToken;
+       }
+
        public function execute() {
                $this->params = $this->extractRequestParams();
                if ( !is_null( $this->params['prop'] ) ) {
index 057dd15..cbb35ae 100644 (file)
@@ -102,12 +102,6 @@ class ApiQueryUserInfo extends ApiQueryBase {
                        $vals['options'] = $user->getOptions();
                }
 
-               if ( isset( $this->prop['optionstoken'] ) &&
-                       is_null( $this->getMain()->getRequest()->getVal( 'callback' ) )
-               ) {
-                       $vals['optionstoken'] = $user->getEditToken( '', $this->getMain()->getRequest() );
-               }
-
                if ( isset( $this->prop['preferencestoken'] ) &&
                        is_null( $this->getMain()->getRequest()->getVal( 'callback' ) )
                ) {
@@ -203,7 +197,6 @@ class ApiQueryUserInfo extends ApiQueryBase {
                                        'rights',
                                        'changeablegroups',
                                        'options',
-                                       'optionstoken',
                                        'preferencestoken',
                                        'editcount',
                                        'ratelimits',
@@ -227,7 +220,6 @@ class ApiQueryUserInfo extends ApiQueryBase {
                                '  rights           - Lists all the rights the current user has',
                                '  changeablegroups - Lists the groups the current user can add to and remove from',
                                '  options          - Lists all preferences the current user has set',
-                               '  optionstoken     - Get a token to change current user\'s preferences',
                                '  preferencestoken - Get a token to change current user\'s preferences',
                                '  editcount        - Adds the current user\'s edit count',
                                '  ratelimits       - Lists all rate limits applying to the current user',
index 4a68826..c56d646 100644 (file)
@@ -64,9 +64,9 @@ class ApiTokens extends ApiBase {
                wfProfileIn( __METHOD__ );
                $types = array( 'patrol' => 'ApiQueryRecentChanges::getPatrolToken' );
                $names = array( 'edit', 'delete', 'protect', 'move', 'block', 'unblock',
-                       'email', 'import', 'watch' );
+                       'email', 'import', 'watch', 'options' );
                foreach ( $names as $name ) {
-                       $types[$name] = 'ApiQUeryInfo::get' . ucfirst( $name ) . 'Token';
+                       $types[$name] = 'ApiQueryInfo::get' . ucfirst( $name ) . 'Token';
                }
                wfRunHooks( 'ApiTokensGetTokenTypes', array( &$types ) );
                ksort( $types );