From fd976ad072e927f3c911f619bd2f66ab7517a7f3 Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Sat, 28 Aug 2010 00:37:48 +0000 Subject: [PATCH] Part of Bug 19195 - Make user IDs more readily available with the API ApiQueryAllUsers, ApiQueryImageInfo and ApiQueryRevisions exposing user_id --- includes/api/ApiQueryAllUsers.php | 10 ++++++++-- includes/api/ApiQueryImageInfo.php | 13 ++++++++++--- includes/api/ApiQueryRevisions.php | 17 +++++++++++++---- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/includes/api/ApiQueryAllUsers.php b/includes/api/ApiQueryAllUsers.php index ceecb3fd37..8e8132b1d4 100644 --- a/includes/api/ApiQueryAllUsers.php +++ b/includes/api/ApiQueryAllUsers.php @@ -108,7 +108,10 @@ class ApiQueryAllUsers extends ApiQueryBase { $this->addOption( 'LIMIT', $sqlLimit ); - $this->addFields( 'u1.user_name' ); + $this->addFields( array( + 'u1.user_name', + 'u1.user_id' + ) ); $this->addFieldsIf( 'u1.user_editcount', $fld_editcount ); $this->addFieldsIf( 'u1.user_registration', $fld_registration ); @@ -155,7 +158,10 @@ class ApiQueryAllUsers extends ApiQueryBase { // Record new user's data $lastUser = $row->user_name; - $lastUserData = array( 'name' => $lastUser ); + $lastUserData = array( + 'name' => $lastUser, + 'userid' => $row->user_id, + ); if ( $fld_blockinfo && !is_null( $row->blocker_name ) ) { $lastUserData['blockedby'] = $row->blocker_name; $lastUserData['blockreason'] = $row->ipb_reason; diff --git a/includes/api/ApiQueryImageInfo.php b/includes/api/ApiQueryImageInfo.php index 2643db5f16..e58f7ea569 100644 --- a/includes/api/ApiQueryImageInfo.php +++ b/includes/api/ApiQueryImageInfo.php @@ -197,8 +197,13 @@ class ApiQueryImageInfo extends ApiQueryBase { if ( isset( $prop['timestamp'] ) ) { $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $file->getTimestamp() ); } - if ( isset( $prop['user'] ) ) { - $vals['user'] = $file->getUser(); + if ( isset( $prop['user'] ) || isset( $prop['userid'] ) ) { + + if ( isset( $prop['user'] ) ) { + $vals['user'] = $file->getUser(); + } else if ( isset( $prop['userid'] ) ) { + $vals['userid'] = $file->getUser( 'id' ); + } if ( !$file->getUser( 'id' ) ) { $vals['anon'] = ''; } @@ -323,6 +328,7 @@ class ApiQueryImageInfo extends ApiQueryBase { return array( 'timestamp', 'user', + 'userid', 'comment', 'url', 'size', @@ -342,7 +348,8 @@ class ApiQueryImageInfo extends ApiQueryBase { 'prop' => array( 'What image information to get:', ' timestamp - Adds timestamp for the uploaded version', - ' user - Adds user for uploaded the image version', + ' user - Adds the user who uploaded the image version', + ' userid - Add the user id that uploaded the image version', ' comment - Comment on the version', ' url - Gives URL to the image and the description page', ' size - Adds the size of the image in bytes and the height and width', diff --git a/includes/api/ApiQueryRevisions.php b/includes/api/ApiQueryRevisions.php index 998dd0893a..77c41b9d2b 100644 --- a/includes/api/ApiQueryRevisions.php +++ b/includes/api/ApiQueryRevisions.php @@ -43,7 +43,8 @@ class ApiQueryRevisions extends ApiQueryBase { } private $fld_ids = false, $fld_flags = false, $fld_timestamp = false, $fld_size = false, - $fld_comment = false, $fld_parsedcomment = false, $fld_user = false, $fld_content = false, $fld_tags = false; + $fld_comment = false, $fld_parsedcomment = false, $fld_user = false, $fld_userid = false, + $fld_content = false, $fld_tags = false; protected function getTokenFunctions() { // tokenname => function @@ -149,6 +150,7 @@ class ApiQueryRevisions extends ApiQueryBase { $this->fld_comment = isset ( $prop['comment'] ); $this->fld_parsedcomment = isset ( $prop['parsedcomment'] ); $this->fld_size = isset ( $prop['size'] ); + $this->fld_userid = isset( $prop['userid'] ); $this->fld_user = isset ( $prop['user'] ); $this->token = $params['token']; @@ -364,11 +366,16 @@ class ApiQueryRevisions extends ApiQueryBase { $vals['minor'] = ''; } - if ( $this->fld_user ) { + if ( $this->fld_user || $this->fld_userid ) { if ( $revision->isDeleted( Revision::DELETED_USER ) ) { $vals['userhidden'] = ''; } else { - $vals['user'] = $revision->getUserText(); + if ( $this->fld_user ) { + $vals['user'] = $revision->getUserText(); + } else { + $user = User::newFromText( $revision->getUserText() ); + $vals['userid'] = $user->getId(); + } if ( !$revision->getUser() ) { $vals['anon'] = ''; } @@ -502,6 +509,7 @@ class ApiQueryRevisions extends ApiQueryBase { 'flags', 'timestamp', 'user', + 'userid', 'size', 'comment', 'parsedcomment', @@ -562,7 +570,8 @@ class ApiQueryRevisions extends ApiQueryBase { ' ids - The ID of the revision', ' flags - Revision flags (minor)', ' timestamp - The timestamp of the revision', - ' user - Gives user to make the revision', + ' user - User that made the revision', + ' userid - User id of revision creator', ' size - Length of the revision', ' comment - Comment by the user for revision', ' parsedcomment - Parsed comment by the user for the revision', -- 2.20.1