98 if (
$params[
'prop'] !==
null ) {
99 $this->prop = array_fill_keys(
$params[
'prop'],
true );
103 $useNames =
$params[
'users'] !==
null;
105 $users = (array)
$params[
'users'];
106 $userids = (array)
$params[
'userids'];
108 $goodNames = $done = [];
111 foreach ( $users as $u ) {
112 $n = $this->userNameUtils->getCanonical( $u );
113 if ( $n ===
false || $n ===
'' ) {
114 $vals = [
'name' => $u,
'invalid' => true ];
115 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
119 implode(
'|', array_diff( $users, $done ) ) );
130 $parameters = &$goodNames;
132 $parameters = &$userids;
137 if ( count( $parameters ) ) {
145 $this->addDeletedUserFilter();
148 $res = $this->
select( __METHOD__ );
152 if ( isset( $this->prop[
'groups'] ) || isset( $this->prop[
'rights'] ) ) {
163 $this->
addJoinConds( [
'user_groups' => [
'JOIN',
'ug_user=user_id' ] ] );
165 $this->
addFields( [
'ug_user',
'ug_group',
'ug_expiry' ] );
167 $db->expr(
'ug_expiry',
'=',
null )->or(
'ug_expiry',
'>=', $db->timestamp() )
169 $userGroupsRes = $this->
select( __METHOD__ );
171 foreach ( $userGroupsRes as $row ) {
172 $userGroups[$row->user_name][] = $row;
175 if ( isset( $this->prop[
'gender'] ) ) {
177 foreach ( $res as $row ) {
178 $userNames[] = $row->user_name;
180 $this->genderCache->doQuery( $userNames, __METHOD__ );
183 if ( isset( $this->prop[
'blockinfo'] ) ) {
184 $blockInfos = $this->getBlockDetailsForRows( $res );
189 foreach ( $res as $row ) {
192 if ( !isset( $userGroups ) ) {
193 $user = $this->userFactory->newFromRow( $row );
195 if ( !isset( $userGroups[$row->user_name] ) || !is_array( $userGroups[$row->user_name] ) ) {
196 $userGroups[$row->user_name] = [];
198 $user = $this->userFactory->newFromRow( $row, [
'user_groups' => $userGroups[$row->user_name] ] );
201 $key = $user->getName();
203 $key = $user->getId();
205 $data[$key][
'userid'] = $user->getId();
206 $data[$key][
'name'] = $user->getName();
208 if ( isset( $this->prop[
'editcount'] ) ) {
209 $data[$key][
'editcount'] = $user->getEditCount();
212 if ( isset( $this->prop[
'registration'] ) ) {
213 $data[$key][
'registration'] =
wfTimestampOrNull( TS_ISO_8601, $user->getRegistration() );
216 if ( isset( $this->prop[
'groups'] ) ) {
217 $data[$key][
'groups'] = $this->userGroupManager->getUserEffectiveGroups( $user );
220 if ( isset( $this->prop[
'groupmemberships'] ) ) {
221 $data[$key][
'groupmemberships'] = array_map(
static function ( $ugm ) {
223 'group' => $ugm->getGroup(),
224 'expiry' => ApiResult::formatExpiry( $ugm->getExpiry() ),
226 }, $this->userGroupManager->getUserGroupMemberships( $user ) );
229 if ( isset( $this->prop[
'implicitgroups'] ) ) {
230 $data[$key][
'implicitgroups'] = $this->userGroupManager->getUserImplicitGroups( $user );
233 if ( isset( $this->prop[
'rights'] ) ) {
235 ->getUserPermissions( $user );
237 if ( $row->hu_deleted ) {
238 $data[$key][
'hidden'] =
true;
240 if ( isset( $this->prop[
'blockinfo'] ) && isset( $blockInfos[$row->user_id] ) ) {
241 $data[$key] += $blockInfos[$row->user_id];
244 if ( isset( $this->prop[
'emailable'] ) ) {
245 $data[$key][
'emailable'] = $user->canReceiveEmail();
248 if ( isset( $this->prop[
'gender'] ) ) {
249 $data[$key][
'gender'] = $this->genderCache->getGenderOf( $user, __METHOD__ );
252 if ( isset( $this->prop[
'centralids'] ) ) {
261 foreach ( $parameters as $u ) {
262 if ( !isset( $data[$u] ) ) {
264 $data[$u] = [
'name' => $u,
'missing' => true ];
265 if ( isset( $this->prop[
'cancreate'] ) ) {
266 $status = $this->authManager->canCreateAccount( $u );
267 $data[$u][
'cancreate'] = $status->isGood();
268 if ( !$status->isGood() ) {
269 $data[$u][
'cancreateerror'] = $this->
getErrorFormatter()->arrayFromStatus( $status );
273 $data[$u] = [
'userid' => $u,
'missing' => true ];
277 if ( isset( $this->prop[
'groups'] ) && isset( $data[$u][
'groups'] ) ) {
278 ApiResult::setArrayType( $data[$u][
'groups'],
'array' );
279 ApiResult::setIndexedTagName( $data[$u][
'groups'],
'g' );
281 if ( isset( $this->prop[
'groupmemberships'] ) && isset( $data[$u][
'groupmemberships'] ) ) {
282 ApiResult::setArrayType( $data[$u][
'groupmemberships'],
'array' );
283 ApiResult::setIndexedTagName( $data[$u][
'groupmemberships'],
'groupmembership' );
285 if ( isset( $this->prop[
'implicitgroups'] ) && isset( $data[$u][
'implicitgroups'] ) ) {
286 ApiResult::setArrayType( $data[$u][
'implicitgroups'],
'array' );
287 ApiResult::setIndexedTagName( $data[$u][
'implicitgroups'],
'g' );
289 if ( isset( $this->prop[
'rights'] ) && isset( $data[$u][
'rights'] ) ) {
290 ApiResult::setArrayType( $data[$u][
'rights'],
'array' );
291 ApiResult::setIndexedTagName( $data[$u][
'rights'],
'r' );
295 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $data[$u] );
299 implode(
'|', array_diff( $users, $done ) ) );
302 implode(
'|', array_diff( $userids, $done ) ) );
308 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'user' );