From 7cf5f38232111da6ec8834764628aa29422382c1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Szymon=20=C5=9Awierkosz?= Date: Fri, 4 May 2012 12:31:08 +0200 Subject: [PATCH] Move optionstoken from meta=userinfo to action=tokens. Follow up to I0d6c654a7354ba77e65e338423952a6a78c1150f. I have also added a URL to a help page on mw.org. Change-Id: Ie223930cfc313aff150e2dcfd70b74bf4360a8a8 --- includes/api/ApiOptions.php | 6 +++++- includes/api/ApiQueryInfo.php | 15 +++++++++++++++ includes/api/ApiQueryUserInfo.php | 8 -------- includes/api/ApiTokens.php | 4 ++-- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/includes/api/ApiOptions.php b/includes/api/ApiOptions.php index 61da785b25..7bcfe1ed47 100644 --- a/includes/api/ApiOptions.php +++ b/includes/api/ApiOptions.php @@ -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', diff --git a/includes/api/ApiQueryInfo.php b/includes/api/ApiQueryInfo.php index d28642ac09..e5db4d8620 100644 --- a/includes/api/ApiQueryInfo.php +++ b/includes/api/ApiQueryInfo.php @@ -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'] ) ) { diff --git a/includes/api/ApiQueryUserInfo.php b/includes/api/ApiQueryUserInfo.php index 057dd15ee5..cbb35aeb2a 100644 --- a/includes/api/ApiQueryUserInfo.php +++ b/includes/api/ApiQueryUserInfo.php @@ -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', diff --git a/includes/api/ApiTokens.php b/includes/api/ApiTokens.php index 4a68826e10..c56d646cb3 100644 --- a/includes/api/ApiTokens.php +++ b/includes/api/ApiTokens.php @@ -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 ); -- 2.20.1