r98329 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98328‎ | r98329 | r98330 >
Date:16:36, 28 September 2011
Author:reedy
Status:ok (Comments)
Tags:
Comment:
Bug 31199 - Fix notification of implicit groups so it doesn't massively change json output

Needs merging to 1.18, 1.18wmf1 and pushing to site
Modified paths:
  • /trunk/phase3/includes/api/ApiQueryAllUsers.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryUsers.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryAllUsers.php
@@ -51,8 +51,9 @@
5252 $fld_groups = isset( $prop['groups'] );
5353 $fld_rights = isset( $prop['rights'] );
5454 $fld_registration = isset( $prop['registration'] );
 55+ $fld_implicitgroups = isset( $prop['implicitgroups'] );
5556 } else {
56 - $fld_blockinfo = $fld_editcount = $fld_groups = $fld_registration = $fld_rights = false;
 57+ $fld_blockinfo = $fld_editcount = $fld_groups = $fld_registration = $fld_rights = $fld_implicitgroups = false;
5758 }
5859
5960 $limit = $params['limit'];
@@ -246,6 +247,10 @@
247248 $result->setIndexedTagName( $lastUserData['groups'], 'g' );
248249 }
249250
 251+ if ( $fld_implicitgroups && !isset( $lastUserData['implicitgroups'] ) ) {
 252+ $lastUserData['implicitgroups'] = ApiQueryUsers::getAutoGroups( User::newFromName( $lastUser ) );
 253+ $result->setIndexedTagName( $lastUserData['implicitgroups'], 'g' );
 254+ }
250255 if ( $fld_rights ) {
251256 if ( !isset( $lastUserData['rights'] ) ) {
252257 $lastUserData['rights'] = User::getGroupPermissions( User::newFromName( $lastUser )->getAutomaticGroups() );
@@ -304,6 +309,7 @@
305310 ApiBase::PARAM_TYPE => array(
306311 'blockinfo',
307312 'groups',
 313+ 'implicitgroups',
308314 'rights',
309315 'editcount',
310316 'registration'
@@ -333,11 +339,12 @@
334340 'rights' => 'Limit users to given right(s)',
335341 'prop' => array(
336342 'What pieces of information to include.',
337 - ' blockinfo - Adds the information about a current block on the user',
338 - ' groups - Lists groups that the user is in. This uses more server resources and may return fewer results than the limit',
339 - ' rights - Lists rights that the user has',
340 - ' editcount - Adds the edit count of the user',
341 - ' registration - Adds the timestamp of when the user registered if available (may be blank)',
 343+ ' blockinfo - Adds the information about a current block on the user',
 344+ ' groups - Lists groups that the user is in. This uses more server resources and may return fewer results than the limit',
 345+ ' implicitgroups - Lists all the groups the user is automatically in',
 346+ ' rights - Lists rights that the user has',
 347+ ' editcount - Adds the edit count of the user',
 348+ ' registration - Adds the timestamp of when the user registered if available (may be blank)',
342349 ),
343350 'limit' => 'How many total user names to return',
344351 'witheditsonly' => 'Only list users who have made edits',
Index: trunk/phase3/includes/api/ApiQueryUsers.php
@@ -152,6 +152,10 @@
153153 }
154154 }
155155
 156+ if ( isset( $this->prop['implicitgroups'] ) && !isset( $data[$name]['implicitgroups'] ) ) {
 157+ $data[$name]['implicitgroups'] = self::getAutoGroups( $user );
 158+ }
 159+
156160 if ( isset( $this->prop['rights'] ) ) {
157161 if ( !isset( $data[$name]['rights'] ) ) {
158162 $data[$name]['rights'] = User::getGroupPermissions( $user->getAutomaticGroups() );
@@ -226,6 +230,9 @@
227231 if ( isset( $this->prop['groups'] ) && isset( $data[$u]['groups'] ) ) {
228232 $result->setIndexedTagName( $data[$u]['groups'], 'g' );
229233 }
 234+ if ( isset( $this->prop['implicitgroups'] ) && isset( $data[$u]['implicitgroups'] ) ) {
 235+ $result->setIndexedTagName( $data[$u]['implicitgroups'], 'g' );
 236+ }
230237 if ( isset( $this->prop['rights'] ) && isset( $data[$u]['rights'] ) ) {
231238 $result->setIndexedTagName( $data[$u]['rights'], 'r' );
232239 }
@@ -256,12 +263,7 @@
257264 $groups[] = 'user';
258265 }
259266
260 - $builtGroups = array();
261 - foreach( array_merge( $groups, Autopromote::getAutopromoteGroups( $user ) ) as $i => $group ) {
262 - $builtGroups[$i] = array( 'implicit' => '' );
263 - ApiResult::setContent( $builtGroups[$i], $group );
264 - }
265 - return $builtGroups;
 267+ return array_merge( $groups, Autopromote::getAutopromoteGroups( $user ) );
266268 }
267269
268270 public function getCacheMode( $params ) {
@@ -280,6 +282,7 @@
281283 ApiBase::PARAM_TYPE => array(
282284 'blockinfo',
283285 'groups',
 286+ 'implicitgroups',
284287 'rights',
285288 'editcount',
286289 'registration',
@@ -301,13 +304,14 @@
302305 return array(
303306 'prop' => array(
304307 'What pieces of information to include',
305 - ' blockinfo - Tags if the user is blocked, by whom, and for what reason',
306 - ' groups - Lists all the groups the user(s) belongs to',
307 - ' rights - Lists all the rights the user(s) has',
308 - ' editcount - Adds the user\'s edit count',
309 - ' registration - Adds the user\'s registration timestamp',
310 - ' emailable - Tags if the user can and wants to receive e-mail through [[Special:Emailuser]]',
311 - ' gender - Tags the gender of the user. Returns "male", "female", or "unknown"',
 308+ ' blockinfo - Tags if the user is blocked, by whom, and for what reason',
 309+ ' groups - Lists all the groups the user(s) belongs to',
 310+ ' implicitgroups - Lists all the groups a user is automatically a member of',
 311+ ' rights - Lists all the rights the user(s) has',
 312+ ' editcount - Adds the user\'s edit count',
 313+ ' registration - Adds the user\'s registration timestamp',
 314+ ' emailable - Tags if the user can and wants to receive e-mail through [[Special:Emailuser]]',
 315+ ' gender - Tags the gender of the user. Returns "male", "female", or "unknown"',
312316 ),
313317 'users' => 'A list of users to obtain the same information for',
314318 'token' => 'Which tokens to obtain for each user',

Follow-up revisions

RevisionCommit summaryAuthorDate
r98330Fix whitespacereedy16:37, 28 September 2011
r98332Followup r98329...reedy17:01, 28 September 2011
r98356MFT r98329, r98332 (and whitespace for ApiQueryAllUsers from r98330)reedy19:34, 28 September 2011

Comments

#Comment by Reedy (talk | contribs)   16:38, 28 September 2011

Whitespace fixed in r98330

#Comment by Duplicatebug (talk | contribs)   16:56, 28 September 2011

meta=userinfo is missing

#Comment by Reedy (talk | contribs)   16:58, 28 September 2011

Not exactly.

meta=userinfo was NEVER migrated to use the code that added the implicit attribute to the output.

Granted, this information should also be added to meta=userinfo, but that's not a bugfix, whereas the above is

#Comment by Reedy (talk | contribs)   16:59, 28 September 2011

Oh no, you're right.

#Comment by Aaron Schulz (talk | contribs)   19:16, 28 September 2011
$lastUserData['implicitgroups'] = ApiQueryUsers::getAutoGroups( User::newFromName( $lastUser ) );

Slightly suspect, but OKish since this is for users in the DB and not anons. If the creatable username rules changes, some old users could make this fatal I suspect.

Status & tagging log