Krinkle has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/251117

Change subject: Support new salt-based tokens in deprecated action=tokens API
......................................................................

Support new salt-based tokens in deprecated action=tokens API

This makes transition easier as right now, client-side scripts
are unable to migrate to new tokens due to libraries using
action=tokens. And libraries can't migrate because clients are
using deprecated tokens from action=tokens. Paradox.

Ref T117797.

Change-Id: I928dc33f6d20bc09b65a23b7c52b941ecfa066d3
---
M includes/api/ApiTokens.php
1 file changed, 26 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/17/251117/1

diff --git a/includes/api/ApiTokens.php b/includes/api/ApiTokens.php
index 4d7fc5a..abfae95 100644
--- a/includes/api/ApiTokens.php
+++ b/includes/api/ApiTokens.php
@@ -41,9 +41,17 @@
                        ApiResult::META_TYPE => 'assoc',
                );
 
+               // Legacy callbacks
                $types = $this->getTokenTypes();
+               // Salt-based tokens
+               $salts = ApiQueryTokens::getTokenTypeSalts();
                foreach ( $params['type'] as $type ) {
-                       $val = call_user_func( $types[$type], null, null );
+                       if ( isset( $types[$type] ) ) {
+                               $val = call_user_func( $types[$type], null, 
null );
+                       } else {
+                               $salt = $salts[$type];
+                               $val = $this->getUser()->getEditToken( $salt, 
$this->getRequest() );
+                       }
 
                        if ( $val === false ) {
                                $this->setWarning( "Action '$type' is not 
allowed for the current user" );
@@ -66,15 +74,25 @@
                if ( $types ) {
                        return $types;
                }
+
                $types = array( 'patrol' => array( 'ApiQueryRecentChanges', 
'getPatrolToken' ) );
-               $names = array( 'edit', 'delete', 'protect', 'move', 'block', 
'unblock',
-                       'email', 'import', 'watch', 'options' );
+               $names = array(
+                       'edit',
+                       'delete',
+                       'protect',
+                       'move',
+                       'block',
+                       'unblock',
+                       'email',
+                       'import',
+                       'watch',
+                       'options',
+               );
                foreach ( $names as $name ) {
                        $types[$name] = array( 'ApiQueryInfo', 'get' . ucfirst( 
$name ) . 'Token' );
                }
                Hooks::run( 'ApiTokensGetTokenTypes', array( &$types ) );
                ksort( $types );
-
                return $types;
        }
 
@@ -87,7 +105,10 @@
                        'type' => array(
                                ApiBase::PARAM_DFLT => 'edit',
                                ApiBase::PARAM_ISMULTI => true,
-                               ApiBase::PARAM_TYPE => array_keys( 
$this->getTokenTypes() ),
+                               ApiBase::PARAM_TYPE => array_keys( array_merge(
+                                       $this->getTokenTypes(),
+                                       ApiQueryTokens::getTokenTypeSalts()
+                               ) ),
                        ),
                );
        }

-- 
To view, visit https://gerrit.wikimedia.org/r/251117
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I928dc33f6d20bc09b65a23b7c52b941ecfa066d3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>

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

Reply via email to