102 $db = $this->
getDB();
106 if ( $params[
'prop'] !==
null ) {
107 $this->prop = array_fill_keys( $params[
'prop'],
true );
111 $useNames = $params[
'users'] !==
null;
113 $users = (array)$params[
'users'];
114 $userids = (array)$params[
'userids'];
116 $goodNames = $done = [];
119 foreach ( $users as $u ) {
120 $n = $this->userNameUtils->getCanonical( $u );
121 if ( $n ===
false || $n ===
'' ) {
122 $vals = [
'name' => $u,
'invalid' =>
true ];
123 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
127 implode(
'|', array_diff( $users, $done ) ) );
138 $parameters = &$goodNames;
140 $parameters = &$userids;
145 if ( count( $parameters ) ) {
147 $this->
addTables( $userQuery[
'tables'] );
148 $this->
addFields( $userQuery[
'fields'] );
156 $this->addBlockInfoToQuery( isset( $this->prop[
'blockinfo'] ) );
163 if ( isset( $this->prop[
'groups'] ) || isset( $this->prop[
'rights'] ) ) {
174 $this->
addJoinConds( [
'user_groups' => [
'JOIN',
'ug_user=user_id' ] ] );
176 $this->
addFields( $this->userGroupManager->getQueryInfo()[
'fields'] );
177 $this->
addWhere(
'ug_expiry IS NULL OR ug_expiry >= ' .
178 $db->addQuotes( $db->timestamp() ) );
179 $userGroupsRes = $this->
select( __METHOD__ );
181 foreach ( $userGroupsRes as $row ) {
182 $userGroups[$row->user_name][] = $row;
185 if ( isset( $this->prop[
'gender'] ) ) {
187 foreach (
$res as $row ) {
188 $userNames[] = $row->user_name;
190 $this->genderCache->doQuery( $userNames, __METHOD__ );
193 foreach (
$res as $row ) {
196 if ( !isset( $userGroups ) ) {
197 $user = $this->userFactory->newFromRow( $row );
199 if ( !isset( $userGroups[$row->user_name] ) || !is_array( $userGroups[$row->user_name] ) ) {
200 $userGroups[$row->user_name] = [];
202 $user = $this->userFactory->newFromRow( $row, [
'user_groups' => $userGroups[$row->user_name] ] );
205 $key = $user->getName();
207 $key = $user->getId();
209 $data[$key][
'userid'] = $user->getId();
210 $data[$key][
'name'] = $user->getName();
212 if ( isset( $this->prop[
'editcount'] ) ) {
213 $data[$key][
'editcount'] = $user->getEditCount();
216 if ( isset( $this->prop[
'registration'] ) ) {
217 $data[$key][
'registration'] =
wfTimestampOrNull( TS_ISO_8601, $user->getRegistration() );
220 if ( isset( $this->prop[
'groups'] ) ) {
221 $data[$key][
'groups'] = $this->userGroupManager->getUserEffectiveGroups( $user );
224 if ( isset( $this->prop[
'groupmemberships'] ) ) {
225 $data[$key][
'groupmemberships'] = array_map(
static function ( $ugm ) {
227 'group' => $ugm->getGroup(),
228 'expiry' => ApiResult::formatExpiry( $ugm->getExpiry() ),
230 }, $this->userGroupManager->getUserGroupMemberships( $user ) );
233 if ( isset( $this->prop[
'implicitgroups'] ) ) {
234 $data[$key][
'implicitgroups'] = $this->userGroupManager->getUserImplicitGroups( $user );
237 if ( isset( $this->prop[
'rights'] ) ) {
239 ->getUserPermissions( $user );
241 if ( $row->ipb_deleted ) {
242 $data[$key][
'hidden'] =
true;
244 if ( isset( $this->prop[
'blockinfo'] ) && $row->ipb_by_text !==
null ) {
245 $data[$key] += $this->getBlockDetails( DatabaseBlock::newFromRow( $row ) );
248 if ( isset( $this->prop[
'emailable'] ) ) {
249 $data[$key][
'emailable'] = $user->canReceiveEmail();
252 if ( isset( $this->prop[
'gender'] ) ) {
253 $data[$key][
'gender'] = $this->genderCache->getGenderOf( $user, __METHOD__ );
256 if ( isset( $this->prop[
'centralids'] ) ) {
258 $this->
getConfig(), $user, $params[
'attachedwiki']
266 foreach ( $parameters as $u ) {
267 if ( !isset( $data[$u] ) ) {
269 $data[$u] = [
'name' => $u ];
273 $iwUser = $urPage->fetchUser( $u );
276 $data[$u][
'interwiki'] =
true;
278 $data[$u][
'missing'] =
true;
279 if ( isset( $this->prop[
'cancreate'] ) ) {
280 $status = $this->authManager->canCreateAccount( $u );
281 $data[$u][
'cancreate'] = $status->isGood();
282 if ( !$status->isGood() ) {
283 $data[$u][
'cancreateerror'] = $this->
getErrorFormatter()->arrayFromStatus( $status );
288 $data[$u] = [
'userid' => $u,
'missing' =>
true ];
292 if ( isset( $this->prop[
'groups'] ) && isset( $data[$u][
'groups'] ) ) {
293 ApiResult::setArrayType( $data[$u][
'groups'],
'array' );
294 ApiResult::setIndexedTagName( $data[$u][
'groups'],
'g' );
296 if ( isset( $this->prop[
'groupmemberships'] ) && isset( $data[$u][
'groupmemberships'] ) ) {
297 ApiResult::setArrayType( $data[$u][
'groupmemberships'],
'array' );
298 ApiResult::setIndexedTagName( $data[$u][
'groupmemberships'],
'groupmembership' );
300 if ( isset( $this->prop[
'implicitgroups'] ) && isset( $data[$u][
'implicitgroups'] ) ) {
301 ApiResult::setArrayType( $data[$u][
'implicitgroups'],
'array' );
302 ApiResult::setIndexedTagName( $data[$u][
'implicitgroups'],
'g' );
304 if ( isset( $this->prop[
'rights'] ) && isset( $data[$u][
'rights'] ) ) {
305 ApiResult::setArrayType( $data[$u][
'rights'],
'array' );
306 ApiResult::setIndexedTagName( $data[$u][
'rights'],
'r' );
310 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $data[$u] );
314 implode(
'|', array_diff( $users, $done ) ) );
317 implode(
'|', array_diff( $userids, $done ) ) );
323 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'user' );