TyA has uploaded a new change for review.

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

Change subject: T34494 API: Get user info with user ids
......................................................................

T34494 API: Get user info with user ids

Allows users to get user info from ?action=query&list=users
with user ids. We assume that if a user provides an id, they
will rather use that than usernames provided. Updated message
strings to specify that.

Bug: T34494
Change-Id: Icfdde0fa9f6445fe69b408b589a58e649808823e
---
M includes/api/ApiQueryUsers.php
M includes/api/i18n/en.json
2 files changed, 55 insertions(+), 26 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/93/252893/1

diff --git a/includes/api/ApiQueryUsers.php b/includes/api/ApiQueryUsers.php
index a826c1b..d4446a8 100644
--- a/includes/api/ApiQueryUsers.php
+++ b/includes/api/ApiQueryUsers.php
@@ -102,36 +102,51 @@
                } else {
                        $this->prop = array();
                }
-
-               $users = (array)$params['users'];
-               $goodNames = $done = array();
-               $result = $this->getResult();
-               // Canonicalize user names
-               foreach ( $users as $u ) {
-                       $n = User::getCanonicalName( $u );
-                       if ( $n === false || $n === '' ) {
-                               $vals = array( 'name' => $u, 'invalid' => true 
);
-                               $fit = $result->addValue( array( 'query', 
$this->getModuleName() ),
-                                       null, $vals );
-                               if ( !$fit ) {
-                                       $this->setContinueEnumParameter( 
'users',
-                                               implode( '|', array_diff( 
$users, $done ) ) );
-                                       $goodNames = array();
-                                       break;
-                               }
-                               $done[] = $u;
-                       } else {
-                               $goodNames[] = $n;
-                       }
+               
+               if( !is_null( $params['ids'] ) ) {
+                       $usingIds = true;
+                       $users = (array)$params['ids'];
+               } else {
+                       $usingIds = false;
+                       $users = (array)$params['users'];
                }
 
+               $goodNames = $done = array();
                $result = $this->getResult();
+               
+               if( !$usingIds ) {
+                       // Canonicalize user names
+                       foreach ( $users as $u ) {
+                               $n = User::getCanonicalName( $u );
+                               if ( $n === false || $n === '' ) {
+                                       $vals = array( 'name' => $u, 'invalid' 
=> true );
+                                       $fit = $result->addValue( array( 
'query', $this->getModuleName() ),
+                                               null, $vals );
+                                       if ( !$fit ) {
+                                               
$this->setContinueEnumParameter( 'users',
+                                                       implode( '|', 
array_diff( $users, $done ) ) );
+                                               $goodNames = array();
+                                               break;
+                                       }
+                                       $done[] = $u;
+                               } else {
+                                       $goodNames[] = $n;
+                               }
+                       }
+                       
+                       $result = $this->getResult();
+               }
 
-               if ( count( $goodNames ) ) {
+               if ( count( $goodNames ) || $usingIds ) {
                        $this->addTables( 'user' );
                        $this->addFields( User::selectFields() );
-                       $this->addWhereFld( 'user_name', $goodNames );
-
+                       
+                       if( $usingIds ) {
+                               $this->addWhereFld( 'user_id', $ids );
+                       } else {
+                               $this->addWhereFld( 'user_name', $goodNames );
+                       }
+                       
                        $this->showHiddenUsersAddBlockInfo( isset( 
$this->prop['blockinfo'] ) );
 
                        $data = array();
@@ -143,7 +158,13 @@
                                $userGroups = array();
 
                                $this->addTables( 'user' );
-                               $this->addWhereFld( 'user_name', $goodNames );
+                               
+                               if( $usingIds ) {
+                                       $this->addWhereFld( 'user_id', $ids );
+                               } else {
+                                       $this->addWhereFld( 'user_name', 
$goodNames );
+                               }
+                               
                                $this->addTables( 'user_groups' );
                                $this->addJoinConds( array( 'user_groups' => 
array( 'INNER JOIN', 'ug_user=user_id' ) ) );
                                $this->addFields( array( 'user_name', 
'ug_group' ) );
@@ -166,6 +187,10 @@
                                        $user = User::newFromRow( $row, array( 
'user_groups' => $userGroups[$row->user_name] ) );
                                }
                                $name = $user->getName();
+                               
+                               if( $usingIds ) {
+                                       $goodNames[] = $name;
+                               }
 
                                $data[$name]['userid'] = $user->getId();
                                $data[$name]['name'] = $name;
@@ -310,6 +335,9 @@
                        'users' => array(
                                ApiBase::PARAM_ISMULTI => true
                        ),
+                       'ids' => array(
+                               ApiBase::PARAM_ISMULTI => true
+                       ),
                        'token' => array(
                                ApiBase::PARAM_DEPRECATED => true,
                                ApiBase::PARAM_TYPE => array_keys( 
$this->getTokenFunctions() ),
diff --git a/includes/api/i18n/en.json b/includes/api/i18n/en.json
index d4e5303..6230226 100644
--- a/includes/api/i18n/en.json
+++ b/includes/api/i18n/en.json
@@ -1188,7 +1188,8 @@
        "apihelp-query+users-paramvalue-prop-registration": "Adds the user's 
registration timestamp.",
        "apihelp-query+users-paramvalue-prop-emailable": "Tags if the user can 
and wants to receive email through [[Special:Emailuser]].",
        "apihelp-query+users-paramvalue-prop-gender": "Tags the gender of the 
user. Returns \"male\", \"female\", or \"unknown\".",
-       "apihelp-query+users-param-users": "A list of users to obtain 
information for.",
+       "apihelp-query+users-param-users": "A list of users to obtain 
information for. If <kbd>usids</kbd> is provided, this is ignored.",
+       "apihelp-query+users-param-ids": "A list of user ids to obtain 
information for.",
        "apihelp-query+users-param-token": "Use 
<kbd>[[Special:ApiHelp/query+tokens|action=query&meta=tokens]]</kbd> instead.",
        "apihelp-query+users-example-simple": "Return information for user 
<kbd>Example</kbd>.",
 

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

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

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

Reply via email to