X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiQueryUsers.php;h=edcbc1a439f8adc216adb4df88243fad83e01765;hb=073e1ccf7c2564cc5e74523717a978dd62348b62;hp=855e27090af81f6809baba9fc6ca6d7697e06290;hpb=d47c1e93590c80861e22d409b690d89216de390f;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiQueryUsers.php b/includes/api/ApiQueryUsers.php index 855e27090a..edcbc1a439 100644 --- a/includes/api/ApiQueryUsers.php +++ b/includes/api/ApiQueryUsers.php @@ -110,19 +110,39 @@ class ApiQueryUsers extends ApiQueryBase { $this->addFields( User::selectFields() ); $this->addWhereFld( 'user_name', $goodNames ); - if ( isset( $this->prop['groups'] ) || isset( $this->prop['rights'] ) ) { - $this->addTables( 'user_groups' ); - $this->addJoinConds( array( 'user_groups' => array( 'LEFT JOIN', 'ug_user=user_id' ) ) ); - $this->addFields( 'ug_group' ); - } - $this->showHiddenUsersAddBlockInfo( isset( $this->prop['blockinfo'] ) ); $data = array(); $res = $this->select( __METHOD__ ); + $this->resetQueryParams(); + + // get user groups if needed + if ( isset( $this->prop['groups'] ) || isset( $this->prop['rights'] ) ) { + $userGroups = array(); + + $this->addTables( 'user' ); + $this->addWhereFld( 'user_name', $goodNames ); + $this->addTables( 'user_groups' ); + $this->addJoinConds( array( 'user_groups' => array( 'INNER JOIN', 'ug_user=user_id' ) ) ); + $this->addFields( array('user_name', 'ug_group') ); + $userGroupsRes = $this->select( __METHOD__ ); + + foreach( $userGroupsRes as $row ) { + $userGroups[$row->user_name][] = $row->ug_group; + } + } foreach ( $res as $row ) { - $user = User::newFromRow( $row ); + // create user object and pass along $userGroups if set + // that reduces the number of database queries needed in User dramatically + if ( !isset( $userGroups ) ) { + $user = User::newFromRow( $row ); + } else { + if ( !isset( $userGroups[$row->user_name] ) || !is_array( $userGroups[$row->user_name] ) ) { + $userGroups[$row->user_name] = array(); + } + $user = User::newFromRow( $row, array( 'user_groups' => $userGroups[$row->user_name] ) ); + } $name = $user->getName(); $data[$name]['userid'] = $user->getId(); @@ -137,29 +157,15 @@ class ApiQueryUsers extends ApiQueryBase { } if ( isset( $this->prop['groups'] ) ) { - if ( !isset( $data[$name]['groups'] ) ) { - $data[$name]['groups'] = self::getAutoGroups( $user ); - } - - if ( !is_null( $row->ug_group ) ) { - // This row contains only one group, others will be added from other rows - $data[$name]['groups'][] = $row->ug_group; - } + $data[$name]['groups'] = $user->getEffectiveGroups(); } - if ( isset( $this->prop['implicitgroups'] ) && !isset( $data[$name]['implicitgroups'] ) ) { - $data[$name]['implicitgroups'] = self::getAutoGroups( $user ); + if ( isset( $this->prop['implicitgroups'] ) ) { + $data[$name]['implicitgroups'] = $user->getAutomaticGroups(); } if ( isset( $this->prop['rights'] ) ) { - if ( !isset( $data[$name]['rights'] ) ) { - $data[$name]['rights'] = User::getGroupPermissions( $user->getAutomaticGroups() ); - } - - if ( !is_null( $row->ug_group ) ) { - $data[$name]['rights'] = array_unique( array_merge( $data[$name]['rights'], - User::getGroupPermissions( array( $row->ug_group ) ) ) ); - } + $data[$name]['rights'] = $user->getRights(); } if ( $row->ipb_deleted ) { $data[$name]['hidden'] = ''; @@ -244,25 +250,20 @@ class ApiQueryUsers extends ApiQueryBase { } $done[] = $u; } - return $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'user' ); + $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'user' ); } /** * Gets all the groups that a user is automatically a member of (implicit groups) + * + * @deprecated since 1.20; call User::getAutomaticGroups() directly. * @param $user User * @return array */ public static function getAutoGroups( $user ) { - // FIXME this logic is duplicated from User::getEffectiveGroups(), centralize this - $groups = array(); - $groups[] = '*'; - - if ( !$user->isAnon() ) { - $groups[] = 'user'; - $groups = array_merge( $groups, Autopromote::getAutopromoteGroups( $user ) ); - } + wfDeprecated( __METHOD__, '1.20' ); - return $groups; + return $user->getAutomaticGroups(); } public function getCacheMode( $params ) {