77 parent::__construct( $query, $moduleName,
'ui' );
78 $this->talkPageNotificationManager = $talkPageNotificationManager;
79 $this->watchedItemStore = $watchedItemStore;
80 $this->userEditTracker = $userEditTracker;
81 $this->userOptionsLookup = $userOptionsLookup;
82 $this->userGroupManager = $userGroupManager;
112 $attachedWiki = UserIdentity::LOCAL
114 $providerIds = array_keys( $config->
get( MainConfigNames::CentralIdLookupProviders ) );
118 'attachedlocal' => [],
120 ApiResult::setArrayType( $ret[
'centralids'],
'assoc' );
121 ApiResult::setArrayType( $ret[
'attachedlocal'],
'assoc' );
122 if ( $attachedWiki ) {
123 $ret[
'attachedwiki'] = [];
124 ApiResult::setArrayType( $ret[
'attachedwiki'],
'assoc' );
128 $centralIdLookupFactory = MediaWikiServices::getInstance()
129 ->getCentralIdLookupFactory();
130 foreach ( $providerIds as $providerId ) {
131 $provider = $centralIdLookupFactory->getLookup( $providerId );
132 $ret[
'centralids'][$providerId] = $provider->centralIdFromName( $name );
133 $ret[
'attachedlocal'][$providerId] = $provider->isAttached( $user );
134 if ( $attachedWiki ) {
135 $ret[
'attachedwiki'][$providerId] = $provider->isAttached( $user, $attachedWiki );
145 $vals[
'id'] = $user->getId();
146 $vals[
'name'] = $user->getName();
148 if ( !$user->isRegistered() ) {
149 $vals[
'anon'] =
true;
152 if ( isset( $this->prop[
'blockinfo'] ) ) {
153 $block = $user->getBlock();
155 $vals = array_merge( $vals, $this->getBlockDetails( $block ) );
159 if ( isset( $this->prop[
'hasmsg'] ) ) {
160 $vals[
'messages'] = $this->talkPageNotificationManager->userHasNewMessages( $user );
163 if ( isset( $this->prop[
'groups'] ) ) {
164 $vals[
'groups'] = $this->userGroupManager->getUserEffectiveGroups( $user );
165 ApiResult::setArrayType( $vals[
'groups'],
'array' );
166 ApiResult::setIndexedTagName( $vals[
'groups'],
'g' );
169 if ( isset( $this->prop[
'groupmemberships'] ) ) {
170 $ugms = $this->userGroupManager->getUserGroupMemberships( $user );
171 $vals[
'groupmemberships'] = [];
172 foreach ( $ugms as $group => $ugm ) {
173 $vals[
'groupmemberships'][] = [
175 'expiry' => ApiResult::formatExpiry( $ugm->getExpiry() ),
178 ApiResult::setArrayType( $vals[
'groupmemberships'],
'array' );
179 ApiResult::setIndexedTagName( $vals[
'groupmemberships'],
'groupmembership' );
182 if ( isset( $this->prop[
'implicitgroups'] ) ) {
183 $vals[
'implicitgroups'] = $this->userGroupManager->getUserImplicitGroups( $user );
184 ApiResult::setArrayType( $vals[
'implicitgroups'],
'array' );
185 ApiResult::setIndexedTagName( $vals[
'implicitgroups'],
'g' );
188 if ( isset( $this->prop[
'rights'] ) ) {
190 ApiResult::setArrayType( $vals[
'rights'],
'array' );
191 ApiResult::setIndexedTagName( $vals[
'rights'],
'r' );
194 if ( isset( $this->prop[
'changeablegroups'] ) ) {
195 $vals[
'changeablegroups'] = $this->userGroupManager->getGroupsChangeableBy( $this->
getAuthority() );
196 ApiResult::setIndexedTagName( $vals[
'changeablegroups'][
'add'],
'g' );
197 ApiResult::setIndexedTagName( $vals[
'changeablegroups'][
'remove'],
'g' );
198 ApiResult::setIndexedTagName( $vals[
'changeablegroups'][
'add-self'],
'g' );
199 ApiResult::setIndexedTagName( $vals[
'changeablegroups'][
'remove-self'],
'g' );
202 if ( isset( $this->prop[
'options'] ) ) {
203 $vals[
'options'] = $this->userOptionsLookup->getOptions( $user );
204 $vals[
'options'][ApiResult::META_BC_BOOLS] = array_keys( $vals[
'options'] );
207 if ( isset( $this->prop[
'editcount'] ) ) {
210 $vals[
'editcount'] = (int)$user->getEditCount();
213 if ( isset( $this->prop[
'ratelimits'] ) ) {
217 if ( isset( $this->prop[
'theoreticalratelimits'] ) ) {
219 $vals[
'theoreticalratelimits'] = $this->
getRateLimits(
false );
222 if ( isset( $this->prop[
'realname'] ) &&
223 !in_array(
'realname', $this->
getConfig()->
get( MainConfigNames::HiddenPrefs ) )
225 $vals[
'realname'] = $user->getRealName();
228 if ( $this->
getAuthority()->isAllowed(
'viewmyprivateinfo' ) && isset( $this->prop[
'email'] ) ) {
229 $vals[
'email'] = $user->getEmail();
230 $auth = $user->getEmailAuthenticationTimestamp();
231 if ( $auth !==
null ) {
232 $vals[
'emailauthenticated'] =
wfTimestamp( TS_ISO_8601, $auth );
236 if ( isset( $this->prop[
'registrationdate'] ) ) {
237 $regDate = $user->getRegistration();
238 if ( $regDate !==
false ) {
239 $vals[
'registrationdate'] =
wfTimestamp( TS_ISO_8601, $regDate );
243 if ( isset( $this->prop[
'acceptlang'] ) ) {
244 $langs = $this->
getRequest()->getAcceptLang();
246 foreach ( $langs as $lang => $val ) {
247 $r = [
'q' => $val ];
248 ApiResult::setContentValue( $r,
'code', $lang );
251 ApiResult::setIndexedTagName( $acceptLang,
'lang' );
252 $vals[
'acceptlang'] = $acceptLang;
255 if ( isset( $this->prop[
'unreadcount'] ) ) {
256 $unreadNotifications = $this->watchedItemStore->countUnreadNotifications(
258 self::WL_UNREAD_LIMIT
261 if ( $unreadNotifications ===
true ) {
262 $vals[
'unreadcount'] = self::WL_UNREAD_LIMIT .
'+';
264 $vals[
'unreadcount'] = $unreadNotifications;
268 if ( isset( $this->prop[
'centralids'] ) ) {
274 if ( isset( $this->prop[
'latestcontrib'] ) ) {
276 if ( $ts !==
null ) {
277 $vals[
'latestcontrib'] = $ts;
281 if ( isset( $this->prop[
'cancreateaccount'] ) ) {
282 $status = PermissionStatus::newEmpty();
283 $vals[
'cancreateaccount'] = $user->definitelyCan(
'createaccount',
284 SpecialPage::getTitleFor(
'CreateAccount' ), $status );
285 if ( !$status->isGood() ) {
286 $vals[
'cancreateaccounterror'] = $this->
getErrorFormatter()->arrayFromStatus( $status );
302 ApiResult::META_TYPE =>
'assoc',
306 if ( $applyNoRateLimit && !$user->isPingLimitable() ) {
312 if ( !$user->isRegistered() ) {
313 $categories[] =
'anon';
315 $categories[] =
'user';
317 if ( $user->isNewbie() ) {
318 $categories[] =
'ip';
319 $categories[] =
'subnet';
320 if ( $user->isRegistered() ) {
321 $categories[] =
'newbie';
324 $categories = array_merge( $categories, $this->userGroupManager->getUserGroups( $user ) );
327 foreach ( $this->
getConfig()->
get( MainConfigNames::RateLimits ) as $action => $limits ) {
328 foreach ( $categories as $cat ) {
329 if ( isset( $limits[$cat] ) ) {
330 $retval[$action][$cat][
'hits'] = (int)$limits[$cat][0];
331 $retval[$action][$cat][
'seconds'] = (int)$limits[$cat][1];