From: Reedy Date: Thu, 10 May 2012 18:47:42 +0000 (+0000) Subject: Merge "(bug 19195) Make user IDs more readily available with the API" X-Git-Tag: 1.31.0-rc.0~23654 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/operations/recherche.php?a=commitdiff_plain;h=c87a63935a2595f6c24f0a3af94cd29d2b82f80a;hp=-c;p=lhc%2Fweb%2Fwiklou.git Merge "(bug 19195) Make user IDs more readily available with the API" --- c87a63935a2595f6c24f0a3af94cd29d2b82f80a diff --combined includes/api/ApiBlock.php index c566a5cbaf,a5615c5aba..9a2f25565c --- a/includes/api/ApiBlock.php +++ b/includes/api/ApiBlock.php @@@ -103,9 -103,11 +103,11 @@@ class ApiBlock extends ApiBase $res['expiry'] = $block->mExpiry == wfGetDB( DB_SLAVE )->getInfinity() ? 'infinite' : wfTimestamp( TS_ISO_8601, $block->mExpiry ); + $res['id'] = $block->getId(); } else { # should be unreachable $res['expiry'] = ''; + $res['id'] = ''; } $res['reason'] = $params['reason']; @@@ -149,10 -151,7 +151,10 @@@ ApiBase::PARAM_REQUIRED => true ), 'token' => null, - 'gettoken' => false, + 'gettoken' => array( + ApiBase::PARAM_DFLT => false, + ApiBase::PARAM_DEPRECATED => true, + ), 'expiry' => 'never', 'reason' => null, 'anononly' => false, @@@ -169,7 -168,7 +171,7 @@@ public function getParamDescription() { return array( 'user' => 'Username, IP address or IP range you want to block', - 'token' => 'A block token previously obtained through the gettoken parameter or prop=info', + 'token' => 'A block token previously obtained through prop=info', 'gettoken' => 'If set, a block token will be returned, and no other action will be taken', 'expiry' => 'Relative expiry time, e.g. \'5 months\' or \'2 weeks\'. If set to \'infinite\', \'indefinite\' or \'never\', the block will never expire.', 'reason' => 'Reason for block (optional)', diff --combined includes/api/ApiQueryAllUsers.php index e96676ea4b,0f2db10129..01cb15af69 --- a/includes/api/ApiQueryAllUsers.php +++ b/includes/api/ApiQueryAllUsers.php @@@ -34,16 -34,6 +34,16 @@@ class ApiQueryAllUsers extends ApiQuery parent::__construct( $query, $moduleName, 'au' ); } + /** + * This function converts the user name to a canonical form + * which is stored in the database. + * @param String $name + * @return String + */ + private function getCanonicalUserName( $name ) { + return str_replace( '_', ' ', $name ); + } + public function execute() { $db = $this->getDB(); $params = $this->extractRequestParams(); @@@ -67,8 -57,8 +67,8 @@@ $useIndex = true; $dir = ( $params['dir'] == 'descending' ? 'older' : 'newer' ); - $from = is_null( $params['from'] ) ? null : $this->keyToTitle( $params['from'] ); - $to = is_null( $params['to'] ) ? null : $this->keyToTitle( $params['to'] ); + $from = is_null( $params['from'] ) ? null : $this->getCanonicalUserName( $params['from'] ); + $to = is_null( $params['to'] ) ? null : $this->getCanonicalUserName( $params['to'] ); # MySQL doesn't seem to use 'equality propagation' here, so like the # ActiveUsers special page, we have to use rc_user_text for some cases. @@@ -78,7 -68,7 +78,7 @@@ if ( !is_null( $params['prefix'] ) ) { $this->addWhere( $userFieldToSort . - $db->buildLike( $this->keyToTitle( $params['prefix'] ), $db->anyString() ) ); + $db->buildLike( $this->getCanonicalUserName( $params['prefix'] ), $db->anyString() ) ); } if ( !is_null( $params['rights'] ) ) { @@@ -200,14 -190,15 +200,14 @@@ $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; } @@@ -218,7 -209,9 +218,9 @@@ 'name' => $lastUser, ); if ( $fld_blockinfo && !is_null( $row->ipb_by_text ) ) { + $lastUserData['blockid'] = $row->ipb_id; $lastUserData['blockedby'] = $row->ipb_by_text; + $lastUserData['blockedbyid'] = $row->ipb_by; $lastUserData['blockreason'] = $row->ipb_reason; $lastUserData['blockexpiry'] = $row->ipb_expiry; } @@@ -244,23 -237,17 +246,23 @@@ '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' ); } @@@ -269,20 -256,13 +271,20 @@@ $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' ); } } @@@ -291,7 -271,8 +293,7 @@@ $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $lastUserData ); if ( !$fit ) { - $this->setContinueEnumParameter( 'from', - $this->keyToTitle( $lastUserData['name'] ) ); + $this->setContinueEnumParameter( 'from', $lastUserData['name'] ); } } diff --combined includes/api/ApiQueryUserInfo.php index cbb35aeb2a,87edca0d0c..e3bc775a79 --- a/includes/api/ApiQueryUserInfo.php +++ b/includes/api/ApiQueryUserInfo.php @@@ -50,7 -50,7 +50,7 @@@ class ApiQueryUserInfo extends ApiQuery } protected function getCurrentUserInfo() { - global $wgRequest, $wgHiddenPrefs; + global $wgHiddenPrefs; $user = $this->getUser(); $result = $this->getResult(); $vals = array(); @@@ -63,7 -63,10 +63,10 @@@ if ( isset( $this->prop['blockinfo'] ) ) { if ( $user->isBlocked() ) { - $vals['blockedby'] = User::whoIs( $user->blockedBy() ); + $block = $user->getBlock(); + $vals['blockid'] = $block->getId(); + $vals['blockedby'] = $block->getByName(); + $vals['blockedbyid'] = $block->getBy(); $vals['blockreason'] = $user->blockedFor(); } } @@@ -136,7 -139,7 +139,7 @@@ } if ( isset( $this->prop['acceptlang'] ) ) { - $langs = $wgRequest->getAcceptLang(); + $langs = $this->getRequest()->getAcceptLang(); $acceptLang = array(); foreach ( $langs as $lang => $val ) { $r = array( 'q' => $val ); diff --combined includes/api/ApiQueryUsers.php index 38244fff6a,22575956d1..a07ee7f890 --- a/includes/api/ApiQueryUsers.php +++ b/includes/api/ApiQueryUsers.php @@@ -61,10 -61,10 +61,10 @@@ class ApiQueryUsers extends ApiQueryBas return $this->tokenFunctions; } - /** - * @param $user User - * @return String - */ + /** + * @param $user User + * @return String + */ public static function getUserrightsToken( $user ) { global $wgUser; // Since the permissions check for userrights is non-trivial, @@@ -165,7 -165,9 +165,9 @@@ $data[$name]['hidden'] = ''; } if ( isset( $this->prop['blockinfo'] ) && !is_null( $row->ipb_by_text ) ) { + $data[$name]['blockid'] = $row->ipb_id; $data[$name]['blockedby'] = $row->ipb_by_text; + $data[$name]['blockedbyid'] = $row->ipb_by; $data[$name]['blockreason'] = $row->ipb_reason; $data[$name]['blockexpiry'] = $row->ipb_expiry; } diff --combined includes/api/ApiUnblock.php index 32e0d88e82,44e174783a..49353b61f6 --- a/includes/api/ApiUnblock.php +++ b/includes/api/ApiUnblock.php @@@ -78,7 -78,9 +78,9 @@@ class ApiUnblock extends ApiBase } $res['id'] = $block->getId(); - $res['user'] = $block->getType() == Block::TYPE_AUTO ? '' : $block->getTarget(); + $target = $block->getType() == Block::TYPE_AUTO ? '' : $block->getTarget(); + $res['user'] = $target; + $res['userid'] = $target instanceof User ? $target->getId() : 0; $res['reason'] = $params['reason']; $this->getResult()->addValue( null, $this->getModuleName(), $res ); } @@@ -98,10 -100,7 +100,10 @@@ ), 'user' => null, 'token' => null, - 'gettoken' => false, + 'gettoken' => array( + ApiBase::PARAM_DFLT => false, + ApiBase::PARAM_DEPRECATED => true, + ), 'reason' => null, ); } @@@ -111,7 -110,7 +113,7 @@@ return array( 'id' => "ID of the block you want to unblock (obtained through list=blocks). Cannot be used together with {$p}user", 'user' => "Username, IP address or IP range you want to unblock. Cannot be used together with {$p}id", - 'token' => "An unblock token previously obtained through the gettoken parameter or {$p}prop=info", + 'token' => "An unblock token previously obtained through prop=info", 'gettoken' => 'If set, an unblock token will be returned, and no other action will be taken', 'reason' => 'Reason for unblock (optional)', );