r71831 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71830‎ | r71831 | r71832 >
Date:00:37, 28 August 2010
Author:reedy
Status:resolved
Tags:
Comment:
Part of Bug 19195 - Make user IDs more readily available with the API

ApiQueryAllUsers, ApiQueryImageInfo and ApiQueryRevisions exposing user_id
Modified paths:
  • /trunk/phase3/includes/api/ApiQueryAllUsers.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryImageInfo.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryRevisions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryImageInfo.php
@@ -197,8 +197,13 @@
198198 if ( isset( $prop['timestamp'] ) ) {
199199 $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $file->getTimestamp() );
200200 }
201 - if ( isset( $prop['user'] ) ) {
202 - $vals['user'] = $file->getUser();
 201+ if ( isset( $prop['user'] ) || isset( $prop['userid'] ) ) {
 202+
 203+ if ( isset( $prop['user'] ) ) {
 204+ $vals['user'] = $file->getUser();
 205+ } else if ( isset( $prop['userid'] ) ) {
 206+ $vals['userid'] = $file->getUser( 'id' );
 207+ }
203208 if ( !$file->getUser( 'id' ) ) {
204209 $vals['anon'] = '';
205210 }
@@ -323,6 +328,7 @@
324329 return array(
325330 'timestamp',
326331 'user',
 332+ 'userid',
327333 'comment',
328334 'url',
329335 'size',
@@ -342,7 +348,8 @@
343349 'prop' => array(
344350 'What image information to get:',
345351 ' timestamp - Adds timestamp for the uploaded version',
346 - ' user - Adds user for uploaded the image version',
 352+ ' user - Adds the user who uploaded the image version',
 353+ ' userid - Add the user id that uploaded the image version',
347354 ' comment - Comment on the version',
348355 ' url - Gives URL to the image and the description page',
349356 ' size - Adds the size of the image in bytes and the height and width',
Index: trunk/phase3/includes/api/ApiQueryRevisions.php
@@ -43,7 +43,8 @@
4444 }
4545
4646 private $fld_ids = false, $fld_flags = false, $fld_timestamp = false, $fld_size = false,
47 - $fld_comment = false, $fld_parsedcomment = false, $fld_user = false, $fld_content = false, $fld_tags = false;
 47+ $fld_comment = false, $fld_parsedcomment = false, $fld_user = false, $fld_userid = false,
 48+ $fld_content = false, $fld_tags = false;
4849
4950 protected function getTokenFunctions() {
5051 // tokenname => function
@@ -149,6 +150,7 @@
150151 $this->fld_comment = isset ( $prop['comment'] );
151152 $this->fld_parsedcomment = isset ( $prop['parsedcomment'] );
152153 $this->fld_size = isset ( $prop['size'] );
 154+ $this->fld_userid = isset( $prop['userid'] );
153155 $this->fld_user = isset ( $prop['user'] );
154156 $this->token = $params['token'];
155157
@@ -364,11 +366,16 @@
365367 $vals['minor'] = '';
366368 }
367369
368 - if ( $this->fld_user ) {
 370+ if ( $this->fld_user || $this->fld_userid ) {
369371 if ( $revision->isDeleted( Revision::DELETED_USER ) ) {
370372 $vals['userhidden'] = '';
371373 } else {
372 - $vals['user'] = $revision->getUserText();
 374+ if ( $this->fld_user ) {
 375+ $vals['user'] = $revision->getUserText();
 376+ } else {
 377+ $user = User::newFromText( $revision->getUserText() );
 378+ $vals['userid'] = $user->getId();
 379+ }
373380 if ( !$revision->getUser() ) {
374381 $vals['anon'] = '';
375382 }
@@ -502,6 +509,7 @@
503510 'flags',
504511 'timestamp',
505512 'user',
 513+ 'userid',
506514 'size',
507515 'comment',
508516 'parsedcomment',
@@ -562,7 +570,8 @@
563571 ' ids - The ID of the revision',
564572 ' flags - Revision flags (minor)',
565573 ' timestamp - The timestamp of the revision',
566 - ' user - Gives user to make the revision',
 574+ ' user - User that made the revision',
 575+ ' userid - User id of revision creator',
567576 ' size - Length of the revision',
568577 ' comment - Comment by the user for revision',
569578 ' parsedcomment - Parsed comment by the user for the revision',
Index: trunk/phase3/includes/api/ApiQueryAllUsers.php
@@ -108,7 +108,10 @@
109109
110110 $this->addOption( 'LIMIT', $sqlLimit );
111111
112 - $this->addFields( 'u1.user_name' );
 112+ $this->addFields( array(
 113+ 'u1.user_name',
 114+ 'u1.user_id'
 115+ ) );
113116 $this->addFieldsIf( 'u1.user_editcount', $fld_editcount );
114117 $this->addFieldsIf( 'u1.user_registration', $fld_registration );
115118
@@ -155,7 +158,10 @@
156159
157160 // Record new user's data
158161 $lastUser = $row->user_name;
159 - $lastUserData = array( 'name' => $lastUser );
 162+ $lastUserData = array(
 163+ 'name' => $lastUser,
 164+ 'userid' => $row->user_id,
 165+ );
160166 if ( $fld_blockinfo && !is_null( $row->blocker_name ) ) {
161167 $lastUserData['blockedby'] = $row->blocker_name;
162168 $lastUserData['blockreason'] = $row->ipb_reason;

Follow-up revisions

RevisionCommit summaryAuthorDate
r71835Followup r71831, it's not mutually exclusive!...reedy00:54, 28 August 2010
r74392Followup r71831, User::newFromName, not newFromTextreedy21:16, 6 October 2010

Status & tagging log