103 $db = $this->
getDB();
107 if ( $params[
'prop'] !==
null ) {
108 $this->prop = array_fill_keys( $params[
'prop'],
true );
112 $useNames = $params[
'users'] !==
null;
114 $users = (array)$params[
'users'];
115 $userids = (array)$params[
'userids'];
117 $goodNames = $done = [];
120 foreach ( $users as $u ) {
121 $n = $this->userNameUtils->getCanonical( $u );
122 if ( $n ===
false || $n ===
'' ) {
123 $vals = [
'name' => $u,
'invalid' =>
true ];
124 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
128 implode(
'|', array_diff( $users, $done ) ) );
139 $parameters = &$goodNames;
141 $parameters = &$userids;
146 if ( count( $parameters ) ) {
148 $this->
addTables( $userQuery[
'tables'] );
149 $this->
addFields( $userQuery[
'fields'] );
157 $this->addBlockInfoToQuery( isset( $this->prop[
'blockinfo'] ) );
164 if ( isset( $this->prop[
'groups'] ) || isset( $this->prop[
'rights'] ) ) {
175 $this->
addJoinConds( [
'user_groups' => [
'JOIN',
'ug_user=user_id' ] ] );
177 $this->
addFields( [
'ug_user',
'ug_group',
'ug_expiry' ] );
178 $this->
addWhere(
'ug_expiry IS NULL OR ug_expiry >= ' .
179 $db->addQuotes( $db->timestamp() ) );
180 $userGroupsRes = $this->
select( __METHOD__ );
182 foreach ( $userGroupsRes as $row ) {
183 $userGroups[$row->user_name][] = $row;
186 if ( isset( $this->prop[
'gender'] ) ) {
188 foreach (
$res as $row ) {
189 $userNames[] = $row->user_name;
191 $this->genderCache->doQuery( $userNames, __METHOD__ );
194 foreach (
$res as $row ) {
197 if ( !isset( $userGroups ) ) {
198 $user = $this->userFactory->newFromRow( $row );
200 if ( !isset( $userGroups[$row->user_name] ) || !is_array( $userGroups[$row->user_name] ) ) {
201 $userGroups[$row->user_name] = [];
203 $user = $this->userFactory->newFromRow( $row, [
'user_groups' => $userGroups[$row->user_name] ] );
206 $key = $user->getName();
208 $key = $user->getId();
210 $data[$key][
'userid'] = $user->getId();
211 $data[$key][
'name'] = $user->getName();
213 if ( isset( $this->prop[
'editcount'] ) ) {
214 $data[$key][
'editcount'] = $user->getEditCount();
217 if ( isset( $this->prop[
'registration'] ) ) {
218 $data[$key][
'registration'] =
wfTimestampOrNull( TS_ISO_8601, $user->getRegistration() );
221 if ( isset( $this->prop[
'groups'] ) ) {
222 $data[$key][
'groups'] = $this->userGroupManager->getUserEffectiveGroups( $user );
225 if ( isset( $this->prop[
'groupmemberships'] ) ) {
226 $data[$key][
'groupmemberships'] = array_map(
static function ( $ugm ) {
228 'group' => $ugm->getGroup(),
229 'expiry' => ApiResult::formatExpiry( $ugm->getExpiry() ),
231 }, $this->userGroupManager->getUserGroupMemberships( $user ) );
234 if ( isset( $this->prop[
'implicitgroups'] ) ) {
235 $data[$key][
'implicitgroups'] = $this->userGroupManager->getUserImplicitGroups( $user );
238 if ( isset( $this->prop[
'rights'] ) ) {
240 ->getUserPermissions( $user );
242 if ( $row->ipb_deleted ) {
243 $data[$key][
'hidden'] =
true;
245 if ( isset( $this->prop[
'blockinfo'] ) && $row->ipb_by_text !==
null ) {
246 $data[$key] += $this->getBlockDetails( DatabaseBlock::newFromRow( $row ) );
249 if ( isset( $this->prop[
'emailable'] ) ) {
250 $data[$key][
'emailable'] = $user->canReceiveEmail();
253 if ( isset( $this->prop[
'gender'] ) ) {
254 $data[$key][
'gender'] = $this->genderCache->getGenderOf( $user, __METHOD__ );
257 if ( isset( $this->prop[
'centralids'] ) ) {
259 $this->
getConfig(), $user, $params[
'attachedwiki']
267 foreach ( $parameters as $u ) {
268 if ( !isset( $data[$u] ) ) {
270 $data[$u] = [
'name' => $u ];
274 $iwUser = $urPage->fetchUser( $u );
277 $data[$u][
'interwiki'] =
true;
279 $data[$u][
'missing'] =
true;
280 if ( isset( $this->prop[
'cancreate'] ) ) {
281 $status = $this->authManager->canCreateAccount( $u );
282 $data[$u][
'cancreate'] = $status->isGood();
283 if ( !$status->isGood() ) {
284 $data[$u][
'cancreateerror'] = $this->
getErrorFormatter()->arrayFromStatus( $status );
289 $data[$u] = [
'userid' => $u,
'missing' =>
true ];
293 if ( isset( $this->prop[
'groups'] ) && isset( $data[$u][
'groups'] ) ) {
294 ApiResult::setArrayType( $data[$u][
'groups'],
'array' );
295 ApiResult::setIndexedTagName( $data[$u][
'groups'],
'g' );
297 if ( isset( $this->prop[
'groupmemberships'] ) && isset( $data[$u][
'groupmemberships'] ) ) {
298 ApiResult::setArrayType( $data[$u][
'groupmemberships'],
'array' );
299 ApiResult::setIndexedTagName( $data[$u][
'groupmemberships'],
'groupmembership' );
301 if ( isset( $this->prop[
'implicitgroups'] ) && isset( $data[$u][
'implicitgroups'] ) ) {
302 ApiResult::setArrayType( $data[$u][
'implicitgroups'],
'array' );
303 ApiResult::setIndexedTagName( $data[$u][
'implicitgroups'],
'g' );
305 if ( isset( $this->prop[
'rights'] ) && isset( $data[$u][
'rights'] ) ) {
306 ApiResult::setArrayType( $data[$u][
'rights'],
'array' );
307 ApiResult::setIndexedTagName( $data[$u][
'rights'],
'r' );
311 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $data[$u] );
315 implode(
'|', array_diff( $users, $done ) ) );
318 implode(
'|', array_diff( $userids, $done ) ) );
324 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'user' );