21use Wikimedia\Timestamp\TimestampFormat as TS;
66 parent::__construct( $query, $moduleName,
'us' );
74 if ( $params[
'prop'] !==
null ) {
75 $this->prop = array_fill_keys( $params[
'prop'],
true );
79 $useNames = $params[
'users'] !==
null;
81 $users = (array)$params[
'users'];
82 $userids = (array)$params[
'userids'];
84 $goodNames = $done = [];
87 foreach ( $users as $u ) {
88 $n = $this->userNameUtils->getCanonical( $u );
89 if ( $n ===
false || $n ===
'' ) {
90 $vals = [
'name' => $u,
'invalid' => true ];
91 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
95 implode(
'|', array_diff( $users, $done ) ) );
106 $parameters = &$goodNames;
108 $parameters = &$userids;
113 if ( count( $parameters ) ) {
121 $this->addDeletedUserFilter();
124 $res = $this->
select( __METHOD__ );
128 if ( isset( $this->prop[
'groups'] ) || isset( $this->prop[
'rights'] ) ) {
139 $this->
addJoinConds( [
'user_groups' => [
'JOIN',
'ug_user=user_id' ] ] );
141 $this->
addFields( [
'ug_user',
'ug_group',
'ug_expiry' ] );
143 $db->expr(
'ug_expiry',
'=',
null )->or(
'ug_expiry',
'>=', $db->timestamp() )
145 $userGroupsRes = $this->
select( __METHOD__ );
147 foreach ( $userGroupsRes as $row ) {
148 $userGroups[$row->user_name][] = $row;
151 if ( isset( $this->prop[
'gender'] ) ) {
153 foreach ( $res as $row ) {
154 $userNames[] = $row->user_name;
156 $this->genderCache->doQuery( $userNames, __METHOD__ );
159 if ( isset( $this->prop[
'blockinfo'] ) ) {
160 $blockInfos = $this->getBlockDetailsForRows( $res );
165 if ( isset( $this->prop[
'tempexpired'] ) ) {
167 foreach ( $res as $row ) {
168 if ( $this->tempUserConfig->isTempName( $row->user_name ) ) {
169 $tempUsers[] = UserIdentityValue::newRegistered( $row->user_id, $row->user_name );
172 $this->tempUserDetailsLookup->preloadExpirationStatus( $tempUsers );
175 foreach ( $res as $row ) {
178 if ( !isset( $userGroups ) ) {
179 $user = $this->userFactory->newFromRow( $row );
181 if ( !isset( $userGroups[$row->user_name] ) || !is_array( $userGroups[$row->user_name] ) ) {
182 $userGroups[$row->user_name] = [];
184 $user = $this->userFactory->newFromRow( $row, [
'user_groups' => $userGroups[$row->user_name] ] );
187 $key = $user->getName();
189 $key = $user->getId();
191 $data[$key][
'userid'] = $user->getId();
192 $data[$key][
'name'] = $user->getName();
194 if ( $user->isSystemUser() ) {
195 $data[$key][
'systemuser'] =
true;
198 if ( isset( $this->prop[
'editcount'] ) ) {
199 $data[$key][
'editcount'] = $user->getEditCount();
202 if ( isset( $this->prop[
'registration'] ) ) {
203 $data[$key][
'registration'] =
wfTimestampOrNull( TS::ISO_8601, $user->getRegistration() );
206 if ( isset( $this->prop[
'groups'] ) ) {
207 $data[$key][
'groups'] = $this->userGroupManager->getUserEffectiveGroups( $user );
210 if ( isset( $this->prop[
'groupmemberships'] ) ) {
211 $data[$key][
'groupmemberships'] = array_map(
static function ( $ugm ) {
213 'group' => $ugm->getGroup(),
216 }, $this->userGroupManager->getUserGroupMemberships( $user ) );
219 if ( isset( $this->prop[
'implicitgroups'] ) ) {
220 $data[$key][
'implicitgroups'] = $this->userGroupManager->getUserImplicitGroups( $user );
223 if ( isset( $this->prop[
'rights'] ) ) {
225 ->getUserPermissions( $user );
227 if ( $row->hu_deleted ) {
228 $data[$key][
'hidden'] =
true;
230 if ( isset( $this->prop[
'blockinfo'] ) && isset( $blockInfos[$row->user_id] ) ) {
231 $data[$key] += $blockInfos[$row->user_id];
234 if ( isset( $this->prop[
'emailable'] ) ) {
235 $data[$key][
'emailable'] = $user->canReceiveEmail();
238 if ( isset( $this->prop[
'gender'] ) ) {
239 $data[$key][
'gender'] = $this->genderCache->getGenderOf( $user, __METHOD__ );
242 if ( isset( $this->prop[
'centralids'] ) ) {
244 $this->
getConfig(), $user, $params[
'attachedwiki']
248 if ( isset( $this->prop[
'tempexpired'] ) ) {
249 if ( $this->tempUserConfig->isTempName( $row->user_name ) ) {
250 $data[$key][
'tempexpired'] = $this->tempUserDetailsLookup->isExpired( $user );
252 $data[$key][
'tempexpired'] =
null;
259 foreach ( $parameters as $u ) {
260 if ( !isset( $data[$u] ) ) {
262 $data[$u] = [
'name' => $u,
'missing' => true ];
263 if ( isset( $this->prop[
'cancreate'] ) ) {
264 $status = $this->authManager->canCreateAccount( $u );
265 $data[$u][
'cancreate'] = $status->isGood();
266 if ( !$status->isGood() ) {
267 $data[$u][
'cancreateerror'] = $this->
getErrorFormatter()->arrayFromStatus( $status );
271 $data[$u] = [
'userid' => $u,
'missing' => true ];
275 if ( isset( $this->prop[
'groups'] ) && isset( $data[$u][
'groups'] ) ) {
279 if ( isset( $this->prop[
'groupmemberships'] ) && isset( $data[$u][
'groupmemberships'] ) ) {
283 if ( isset( $this->prop[
'implicitgroups'] ) && isset( $data[$u][
'implicitgroups'] ) ) {
287 if ( isset( $this->prop[
'rights'] ) && isset( $data[$u][
'rights'] ) ) {
293 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $data[$u] );
297 implode(
'|', array_diff( $users, $done ) ) );
300 implode(
'|', array_diff( $userids, $done ) ) );
306 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'user' );
311 if ( array_diff( (array)$params[
'prop'], static::$publicProps ) ) {
312 return 'anon-public-user-private';
322 ParamValidator::PARAM_ISMULTI =>
true,
323 ParamValidator::PARAM_TYPE => [
341 'attachedwiki' =>
null,
343 ParamValidator::PARAM_ISMULTI => true
346 ParamValidator::PARAM_ISMULTI =>
true,
347 ParamValidator::PARAM_TYPE =>
'integer'
355 'action=query&list=users&ususers=Example&usprop=groups|editcount|gender'
356 =>
'apihelp-query+users-example-simple',
362 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Users';
367class_alias( ApiQueryUsers::class,
'ApiQueryUsers' );
wfTimestampOrNull( $outputtype=TS::UNIX, $ts=null)
Return a formatted timestamp, or null if input is null.
trait ApiQueryBlockInfoTrait