From: Szymon ƚwierkosz Date: Sun, 15 Apr 2012 08:26:33 +0000 (+0200) Subject: (bug 33602) list=allusers throws exceptions with invalid names X-Git-Tag: 1.31.0-rc.0~23819^2 X-Git-Url: https://git.cyclocoop.org/%28%28?a=commitdiff_plain;h=6cf8cd357ec0370fdfafc8e2056a555b930a5d70;p=lhc%2Fweb%2Fwiklou.git (bug 33602) list=allusers throws exceptions with invalid names Some MediaWiki installations have invalid user names in user table (most notable example: en.wikipedia). This commit DOES NOT resolve the issue completely, it only makes the API behave more gracefully. I have replaced User::newFromName call with User::newFromId, so the User object should be always constructed. In case it was not, an empty array will be provided instead of null when returning user rights. I have removed keyToTitle calls for ContinueEnumParameter as user names in the database are stored without underscores (en.wikipedia has of course one user with _ in the database...). This should fix invalidtitle error thrown. There is one issue I don't know how to solve. When API outputs in query-continue aufrom value with invalid user name, subsequent call with aufrom set will return an error, because input parameters 'from' and 'to' are passed to keyToTitle method too. Should I replace it with simple str_replace('_', ' ')? Change-Id: I7d115e734cb8c93dcf6dc3b98bdbc81975951273 --- diff --git a/includes/api/ApiQueryAllUsers.php b/includes/api/ApiQueryAllUsers.php index ac112ef982..3c19c18cb1 100644 --- a/includes/api/ApiQueryAllUsers.php +++ b/includes/api/ApiQueryAllUsers.php @@ -190,15 +190,14 @@ class ApiQueryAllUsers extends ApiQueryBase { $lastUserData = null; if ( !$fit ) { - $this->setContinueEnumParameter( 'from', - $this->keyToTitle( $lastUserData['name'] ) ); + $this->setContinueEnumParameter( 'from', $lastUserData['name'] ); break; } } if ( $count > $limit ) { // We've reached the one extra which shows that there are additional pages to be had. Stop here... - $this->setContinueEnumParameter( 'from', $this->keyToTitle( $row->user_name ) ); + $this->setContinueEnumParameter( 'from', $row->user_name ); break; } @@ -235,17 +234,23 @@ class ApiQueryAllUsers extends ApiQueryBase { 'MediaWiki configuration error: the database contains more user groups than known to User::getAllGroups() function' ); } - $lastUserObj = User::newFromName( $lastUser ); + $lastUserObj = User::newFromId( $row->user_id ); // Add user's group info if ( $fld_groups ) { - if ( !isset( $lastUserData['groups'] ) && $lastUserObj ) { - $lastUserData['groups'] = ApiQueryUsers::getAutoGroups( $lastUserObj ); + if ( !isset( $lastUserData['groups'] ) ) { + if ( $lastUserObj ) { + $lastUserData['groups'] = ApiQueryUsers::getAutoGroups( $lastUserObj ); + } else { + // This should not normally happen + $lastUserData['groups'] = array(); + } } if ( !is_null( $row->ug_group2 ) ) { $lastUserData['groups'][] = $row->ug_group2; } + $result->setIndexedTagName( $lastUserData['groups'], 'g' ); } @@ -254,13 +259,20 @@ class ApiQueryAllUsers extends ApiQueryBase { $result->setIndexedTagName( $lastUserData['implicitgroups'], 'g' ); } if ( $fld_rights ) { - if ( !isset( $lastUserData['rights'] ) && $lastUserObj ) { - $lastUserData['rights'] = User::getGroupPermissions( $lastUserObj->getAutomaticGroups() ); + if ( !isset( $lastUserData['rights'] ) ) { + if ( $lastUserObj ) { + $lastUserData['rights'] = User::getGroupPermissions( $lastUserObj->getAutomaticGroups() ); + } else { + // This should not normally happen + $lastUserData['rights'] = array(); + } } + if ( !is_null( $row->ug_group2 ) ) { $lastUserData['rights'] = array_unique( array_merge( $lastUserData['rights'], User::getGroupPermissions( array( $row->ug_group2 ) ) ) ); } + $result->setIndexedTagName( $lastUserData['rights'], 'r' ); } } @@ -269,8 +281,7 @@ class ApiQueryAllUsers extends ApiQueryBase { $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $lastUserData ); if ( !$fit ) { - $this->setContinueEnumParameter( 'from', - $this->keyToTitle( $lastUserData['name'] ) ); + $this->setContinueEnumParameter( 'from', $lastUserData['name'] ); } }