90 parent::__construct( $query, $moduleName,
'ui' );
91 $this->talkPageNotificationManager = $talkPageNotificationManager;
92 $this->watchedItemStore = $watchedItemStore;
93 $this->userEditTracker = $userEditTracker;
94 $this->userOptionsLookup = $userOptionsLookup;
95 $this->userGroupManager = $userGroupManager;
125 $attachedWiki = UserIdentity::LOCAL
127 $providerIds = array_keys( $config->
get( MainConfigNames::CentralIdLookupProviders ) );
131 'attachedlocal' => [],
133 ApiResult::setArrayType( $ret[
'centralids'],
'assoc' );
134 ApiResult::setArrayType( $ret[
'attachedlocal'],
'assoc' );
135 if ( $attachedWiki ) {
136 $ret[
'attachedwiki'] = [];
137 ApiResult::setArrayType( $ret[
'attachedwiki'],
'assoc' );
141 $centralIdLookupFactory = MediaWikiServices::getInstance()
142 ->getCentralIdLookupFactory();
143 foreach ( $providerIds as $providerId ) {
144 $provider = $centralIdLookupFactory->getLookup( $providerId );
145 $ret[
'centralids'][$providerId] = $provider->centralIdFromName( $name );
146 $ret[
'attachedlocal'][$providerId] = $provider->isAttached( $user );
147 if ( $attachedWiki ) {
148 $ret[
'attachedwiki'][$providerId] = $provider->isAttached( $user, $attachedWiki );
158 $vals[
'id'] = $user->getId();
159 $vals[
'name'] = $user->getName();
161 if ( !$user->isRegistered() ) {
162 $vals[
'anon'] =
true;
165 if ( isset( $this->prop[
'blockinfo'] ) ) {
166 $block = $user->getBlock();
168 $vals = array_merge( $vals, $this->getBlockDetails( $block ) );
172 if ( isset( $this->prop[
'hasmsg'] ) ) {
173 $vals[
'messages'] = $this->talkPageNotificationManager->userHasNewMessages( $user );
176 if ( isset( $this->prop[
'groups'] ) ) {
177 $vals[
'groups'] = $this->userGroupManager->getUserEffectiveGroups( $user );
178 ApiResult::setArrayType( $vals[
'groups'],
'array' );
179 ApiResult::setIndexedTagName( $vals[
'groups'],
'g' );
182 if ( isset( $this->prop[
'groupmemberships'] ) ) {
183 $ugms = $this->userGroupManager->getUserGroupMemberships( $user );
184 $vals[
'groupmemberships'] = [];
185 foreach ( $ugms as $group => $ugm ) {
186 $vals[
'groupmemberships'][] = [
188 'expiry' => ApiResult::formatExpiry( $ugm->getExpiry() ),
191 ApiResult::setArrayType( $vals[
'groupmemberships'],
'array' );
192 ApiResult::setIndexedTagName( $vals[
'groupmemberships'],
'groupmembership' );
195 if ( isset( $this->prop[
'implicitgroups'] ) ) {
196 $vals[
'implicitgroups'] = $this->userGroupManager->getUserImplicitGroups( $user );
197 ApiResult::setArrayType( $vals[
'implicitgroups'],
'array' );
198 ApiResult::setIndexedTagName( $vals[
'implicitgroups'],
'g' );
201 if ( isset( $this->prop[
'rights'] ) ) {
203 ApiResult::setArrayType( $vals[
'rights'],
'array' );
204 ApiResult::setIndexedTagName( $vals[
'rights'],
'r' );
207 if ( isset( $this->prop[
'changeablegroups'] ) ) {
208 $vals[
'changeablegroups'] = $this->userGroupManager->getGroupsChangeableBy( $this->
getAuthority() );
209 ApiResult::setIndexedTagName( $vals[
'changeablegroups'][
'add'],
'g' );
210 ApiResult::setIndexedTagName( $vals[
'changeablegroups'][
'remove'],
'g' );
211 ApiResult::setIndexedTagName( $vals[
'changeablegroups'][
'add-self'],
'g' );
212 ApiResult::setIndexedTagName( $vals[
'changeablegroups'][
'remove-self'],
'g' );
215 if ( isset( $this->prop[
'options'] ) ) {
216 $vals[
'options'] = $this->userOptionsLookup->getOptions( $user );
217 $vals[
'options'][ApiResult::META_BC_BOOLS] = array_keys( $vals[
'options'] );
220 if ( isset( $this->prop[
'editcount'] ) ) {
223 $vals[
'editcount'] = (int)$user->getEditCount();
226 if ( isset( $this->prop[
'ratelimits'] ) ) {
230 if ( isset( $this->prop[
'theoreticalratelimits'] ) ) {
232 $vals[
'theoreticalratelimits'] = $this->
getRateLimits(
false );
235 if ( isset( $this->prop[
'realname'] ) &&
236 !in_array(
'realname', $this->
getConfig()->
get( MainConfigNames::HiddenPrefs ) )
238 $vals[
'realname'] = $user->getRealName();
241 if ( $this->
getAuthority()->isAllowed(
'viewmyprivateinfo' ) && isset( $this->prop[
'email'] ) ) {
242 $vals[
'email'] = $user->getEmail();
243 $auth = $user->getEmailAuthenticationTimestamp();
244 if ( $auth !==
null ) {
245 $vals[
'emailauthenticated'] =
wfTimestamp( TS_ISO_8601, $auth );
249 if ( isset( $this->prop[
'registrationdate'] ) ) {
250 $regDate = $user->getRegistration();
251 if ( $regDate !==
false ) {
252 $vals[
'registrationdate'] =
wfTimestamp( TS_ISO_8601, $regDate );
256 if ( isset( $this->prop[
'acceptlang'] ) ) {
257 $langs = $this->
getRequest()->getAcceptLang();
259 foreach ( $langs as
$lang => $val ) {
260 $r = [
'q' => $val ];
261 ApiResult::setContentValue( $r,
'code',
$lang );
264 ApiResult::setIndexedTagName( $acceptLang,
'lang' );
265 $vals[
'acceptlang'] = $acceptLang;
268 if ( isset( $this->prop[
'unreadcount'] ) ) {
269 $unreadNotifications = $this->watchedItemStore->countUnreadNotifications(
271 self::WL_UNREAD_LIMIT
274 if ( $unreadNotifications ===
true ) {
275 $vals[
'unreadcount'] = self::WL_UNREAD_LIMIT .
'+';
277 $vals[
'unreadcount'] = $unreadNotifications;
281 if ( isset( $this->prop[
'centralids'] ) ) {
287 if ( isset( $this->prop[
'latestcontrib'] ) ) {
289 if ( $ts !==
null ) {
290 $vals[
'latestcontrib'] = $ts;
306 ApiResult::META_TYPE =>
'assoc',
310 if ( $applyNoRateLimit && !$user->isPingLimitable() ) {
316 if ( !$user->isRegistered() ) {
317 $categories[] =
'anon';
319 $categories[] =
'user';
321 if ( $user->isNewbie() ) {
322 $categories[] =
'ip';
323 $categories[] =
'subnet';
324 if ( $user->isRegistered() ) {
325 $categories[] =
'newbie';
328 $categories = array_merge( $categories, $this->userGroupManager->getUserGroups( $user ) );
331 foreach ( $this->
getConfig()->
get( MainConfigNames::RateLimits ) as $action => $limits ) {
332 foreach ( $categories as $cat ) {
333 if ( isset( $limits[$cat] ) ) {
334 $retval[$action][$cat][
'hits'] = (int)$limits[$cat][0];
335 $retval[$action][$cat][
'seconds'] = (int)$limits[$cat][1];