79 parent::__construct( $query, $moduleName,
'us' );
80 $this->userNameUtils = $userNameUtils;
81 $this->userFactory = $userFactory;
82 $this->userGroupManager = $userGroupManager;
83 $this->genderCache = $genderCache;
84 $this->authManager = $authManager;
92 if (
$params[
'prop'] !==
null ) {
93 $this->prop = array_fill_keys(
$params[
'prop'],
true );
97 $useNames =
$params[
'users'] !==
null;
99 $users = (array)
$params[
'users'];
100 $userids = (array)
$params[
'userids'];
102 $goodNames = $done = [];
105 foreach ( $users as $u ) {
106 $n = $this->userNameUtils->getCanonical( $u );
107 if ( $n ===
false || $n ===
'' ) {
108 $vals = [
'name' => $u,
'invalid' => true ];
109 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
113 implode(
'|', array_diff( $users, $done ) ) );
124 $parameters = &$goodNames;
126 $parameters = &$userids;
131 if ( count( $parameters ) ) {
139 $this->addDeletedUserFilter();
142 $res = $this->
select( __METHOD__ );
146 if ( isset( $this->prop[
'groups'] ) || isset( $this->prop[
'rights'] ) ) {
157 $this->
addJoinConds( [
'user_groups' => [
'JOIN',
'ug_user=user_id' ] ] );
159 $this->
addFields( [
'ug_user',
'ug_group',
'ug_expiry' ] );
161 $db->expr(
'ug_expiry',
'=',
null )->or(
'ug_expiry',
'>=', $db->timestamp() )
163 $userGroupsRes = $this->
select( __METHOD__ );
165 foreach ( $userGroupsRes as $row ) {
166 $userGroups[$row->user_name][] = $row;
169 if ( isset( $this->prop[
'gender'] ) ) {
171 foreach ( $res as $row ) {
172 $userNames[] = $row->user_name;
174 $this->genderCache->doQuery( $userNames, __METHOD__ );
177 if ( isset( $this->prop[
'blockinfo'] ) ) {
178 $blockInfos = $this->getBlockDetailsForRows( $res );
183 foreach ( $res as $row ) {
186 if ( !isset( $userGroups ) ) {
187 $user = $this->userFactory->newFromRow( $row );
189 if ( !isset( $userGroups[$row->user_name] ) || !is_array( $userGroups[$row->user_name] ) ) {
190 $userGroups[$row->user_name] = [];
192 $user = $this->userFactory->newFromRow( $row, [
'user_groups' => $userGroups[$row->user_name] ] );
195 $key = $user->getName();
197 $key = $user->getId();
199 $data[$key][
'userid'] = $user->getId();
200 $data[$key][
'name'] = $user->getName();
202 if ( $user->isSystemUser() ) {
203 $data[$key][
'systemuser'] =
true;
206 if ( isset( $this->prop[
'editcount'] ) ) {
207 $data[$key][
'editcount'] = $user->getEditCount();
210 if ( isset( $this->prop[
'registration'] ) ) {
211 $data[$key][
'registration'] =
wfTimestampOrNull( TS_ISO_8601, $user->getRegistration() );
214 if ( isset( $this->prop[
'groups'] ) ) {
215 $data[$key][
'groups'] = $this->userGroupManager->getUserEffectiveGroups( $user );
218 if ( isset( $this->prop[
'groupmemberships'] ) ) {
219 $data[$key][
'groupmemberships'] = array_map(
static function ( $ugm ) {
221 'group' => $ugm->getGroup(),
224 }, $this->userGroupManager->getUserGroupMemberships( $user ) );
227 if ( isset( $this->prop[
'implicitgroups'] ) ) {
228 $data[$key][
'implicitgroups'] = $this->userGroupManager->getUserImplicitGroups( $user );
231 if ( isset( $this->prop[
'rights'] ) ) {
233 ->getUserPermissions( $user );
235 if ( $row->hu_deleted ) {
236 $data[$key][
'hidden'] =
true;
238 if ( isset( $this->prop[
'blockinfo'] ) && isset( $blockInfos[$row->user_id] ) ) {
239 $data[$key] += $blockInfos[$row->user_id];
242 if ( isset( $this->prop[
'emailable'] ) ) {
243 $data[$key][
'emailable'] = $user->canReceiveEmail();
246 if ( isset( $this->prop[
'gender'] ) ) {
247 $data[$key][
'gender'] = $this->genderCache->getGenderOf( $user, __METHOD__ );
250 if ( isset( $this->prop[
'centralids'] ) ) {
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' );
310 if ( array_diff( (array)
$params[
'prop'], static::$publicProps ) ) {
311 return 'anon-public-user-private';
320 ParamValidator::PARAM_ISMULTI =>
true,
321 ParamValidator::PARAM_TYPE => [
338 'attachedwiki' =>
null,
340 ParamValidator::PARAM_ISMULTI => true
343 ParamValidator::PARAM_ISMULTI =>
true,
344 ParamValidator::PARAM_TYPE =>
'integer'
351 'action=query&list=users&ususers=Example&usprop=groups|editcount|gender'
352 =>
'apihelp-query+users-example-simple',
357 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Users';
362class_alias( ApiQueryUsers::class,
'ApiQueryUsers' );
wfTimestampOrNull( $outputtype=TS_UNIX, $ts=null)
Return a formatted timestamp, or null if input is null.
array $params
The job parameters.
trait ApiQueryBlockInfoTrait