r82412 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82411‎ | r82412 | r82413 >
Date:18:54, 18 February 2011
Author:reedy
Status:ok
Tags:
Comment:
* (bug 25508) Poor API behavior when the SUL account does not exist

Original patch by Brad Jorsch, modified to fit/work. Minor addition

Rough idea of patch tested on fenari, and when global user didn't exist, list of unattached accounts was still available (aim of the patch)
Modified paths:
  • /trunk/extensions/CentralAuth/ApiQueryGlobalUserInfo.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralAuth/ApiQueryGlobalUserInfo.php
@@ -42,37 +42,40 @@
4343 $params['user'] = $wgUser->getName();
4444 }
4545 $user = new CentralAuthUser( $params['user'] );
46 - if ( !$user->exists() ) {
47 - $this->dieUsageMsg( array( 'nosuchuser', $params['user'] ) );
48 - }
4946
5047 // Add basic info
5148 $result = $this->getResult();
52 - $data = array(
53 - 'home' => $user->getHomeWiki(),
54 - 'id' => $user->getId(),
55 - 'registration' => wfTimestamp( TS_ISO_8601, $user->getRegistration() )
56 - );
57 - if ( $user->isLocked() ) {
58 - $data['locked'] = '';
 49+ $data = array();
 50+ $userExists = $user->exists();
 51+
 52+ if ( $userExists ) {
 53+ $data['home'] = $user->getHomeWiki();
 54+ $data['id'] = $user->getId();
 55+ $data['registration'] = wfTimestamp( TS_ISO_8601, $user->getRegistration() );
 56+
 57+ if ( $user->isLocked() ) {
 58+ $data['locked'] = '';
 59+ }
 60+ if ( $user->isHidden() ) {
 61+ $data['hidden'] = '';
 62+ }
 63+ } else {
 64+ $data['missing'] = '';
5965 }
60 - if ( $user->isHidden() ) {
61 - $data['hidden'] = '';
62 - }
6366 $result->addValue( 'query', $this->getModuleName(), $data );
6467
6568 // Add requested info
66 - if ( isset( $prop['groups'] ) ) {
 69+ if ( $userExists && isset( $prop['groups'] ) ) {
6770 $groups = $user->getGlobalGroups();
6871 $result->setIndexedTagName( $groups, 'g' );
6972 $result->addValue( array( 'query', $this->getModuleName() ), 'groups', $groups );
7073 }
71 - if ( isset( $prop['rights'] ) ) {
 74+ if ( $userExists && isset( $prop['rights'] ) ) {
7275 $rights = $user->getGlobalRights();
7376 $result->setIndexedTagName( $rights, 'r' );
7477 $result->addValue( array( 'query', $this->getModuleName() ), 'rights', $rights );
7578 }
76 - if ( isset( $prop['merged'] ) ) {
 79+ if ( $userExists && isset( $prop['merged'] ) ) {
7780 $accounts = $user->queryAttached();
7881 foreach ( $accounts as $account ) {
7982 $a = array(
@@ -152,12 +155,6 @@
153156 return 'Show information about a global user.';
154157 }
155158
156 - public function getPossibleErrors() {
157 - return array_merge( parent::getPossibleErrors(), array(
158 - array( 'nosuchuser', 'user' ),
159 - ) );
160 - }
161 -
162159 protected function getExamples() {
163160 return array(
164161 'api.php?action=query&meta=globaluserinfo',

Follow-up revisions

RevisionCommit summaryAuthorDate
r824541.17wmf1: MFT r82315, r82386, r82411, r82412, r82413catrope14:35, 19 February 2011

Status & tagging log