91 parent::__construct( $query, $moduleName,
'ui' );
92 $this->talkPageNotificationManager = $talkPageNotificationManager;
93 $this->watchedItemStore = $watchedItemStore;
94 $this->userEditTracker = $userEditTracker;
95 $this->userOptionsLookup = $userOptionsLookup;
96 $this->userGroupManager = $userGroupManager;
126 $attachedWiki = UserIdentity::LOCAL
128 $providerIds = array_keys( $config->
get( MainConfigNames::CentralIdLookupProviders ) );
132 'attachedlocal' => [],
134 ApiResult::setArrayType( $ret[
'centralids'],
'assoc' );
135 ApiResult::setArrayType( $ret[
'attachedlocal'],
'assoc' );
136 if ( $attachedWiki ) {
137 $ret[
'attachedwiki'] = [];
138 ApiResult::setArrayType( $ret[
'attachedwiki'],
'assoc' );
142 $centralIdLookupFactory = MediaWikiServices::getInstance()
143 ->getCentralIdLookupFactory();
144 foreach ( $providerIds as $providerId ) {
145 $provider = $centralIdLookupFactory->getLookup( $providerId );
146 $ret[
'centralids'][$providerId] = $provider->centralIdFromName( $name );
147 $ret[
'attachedlocal'][$providerId] = $provider->isAttached( $user );
148 if ( $attachedWiki ) {
149 $ret[
'attachedwiki'][$providerId] = $provider->isAttached( $user, $attachedWiki );
159 $vals[
'id'] = $user->getId();
160 $vals[
'name'] = $user->getName();
162 if ( !$user->isRegistered() ) {
163 $vals[
'anon'] =
true;
166 if ( isset( $this->prop[
'blockinfo'] ) ) {
167 $block = $user->getBlock();
169 $vals = array_merge( $vals, $this->getBlockDetails( $block ) );
173 if ( isset( $this->prop[
'hasmsg'] ) ) {
174 $vals[
'messages'] = $this->talkPageNotificationManager->userHasNewMessages( $user );
177 if ( isset( $this->prop[
'groups'] ) ) {
178 $vals[
'groups'] = $this->userGroupManager->getUserEffectiveGroups( $user );
179 ApiResult::setArrayType( $vals[
'groups'],
'array' );
180 ApiResult::setIndexedTagName( $vals[
'groups'],
'g' );
183 if ( isset( $this->prop[
'groupmemberships'] ) ) {
184 $ugms = $this->userGroupManager->getUserGroupMemberships( $user );
185 $vals[
'groupmemberships'] = [];
186 foreach ( $ugms as $group => $ugm ) {
187 $vals[
'groupmemberships'][] = [
189 'expiry' => ApiResult::formatExpiry( $ugm->getExpiry() ),
192 ApiResult::setArrayType( $vals[
'groupmemberships'],
'array' );
193 ApiResult::setIndexedTagName( $vals[
'groupmemberships'],
'groupmembership' );
196 if ( isset( $this->prop[
'implicitgroups'] ) ) {
197 $vals[
'implicitgroups'] = $this->userGroupManager->getUserImplicitGroups( $user );
198 ApiResult::setArrayType( $vals[
'implicitgroups'],
'array' );
199 ApiResult::setIndexedTagName( $vals[
'implicitgroups'],
'g' );
202 if ( isset( $this->prop[
'rights'] ) ) {
204 ApiResult::setArrayType( $vals[
'rights'],
'array' );
205 ApiResult::setIndexedTagName( $vals[
'rights'],
'r' );
208 if ( isset( $this->prop[
'changeablegroups'] ) ) {
209 $vals[
'changeablegroups'] = $this->userGroupManager->getGroupsChangeableBy( $this->
getAuthority() );
210 ApiResult::setIndexedTagName( $vals[
'changeablegroups'][
'add'],
'g' );
211 ApiResult::setIndexedTagName( $vals[
'changeablegroups'][
'remove'],
'g' );
212 ApiResult::setIndexedTagName( $vals[
'changeablegroups'][
'add-self'],
'g' );
213 ApiResult::setIndexedTagName( $vals[
'changeablegroups'][
'remove-self'],
'g' );
216 if ( isset( $this->prop[
'options'] ) ) {
217 $vals[
'options'] = $this->userOptionsLookup->getOptions( $user );
218 $vals[
'options'][ApiResult::META_BC_BOOLS] = array_keys( $vals[
'options'] );
221 if ( isset( $this->prop[
'editcount'] ) ) {
224 $vals[
'editcount'] = (int)$user->getEditCount();
227 if ( isset( $this->prop[
'ratelimits'] ) ) {
231 if ( isset( $this->prop[
'theoreticalratelimits'] ) ) {
233 $vals[
'theoreticalratelimits'] = $this->
getRateLimits(
false );
236 if ( isset( $this->prop[
'realname'] ) &&
237 !in_array(
'realname', $this->
getConfig()->
get( MainConfigNames::HiddenPrefs ) )
239 $vals[
'realname'] = $user->getRealName();
242 if ( $this->
getAuthority()->isAllowed(
'viewmyprivateinfo' ) && isset( $this->prop[
'email'] ) ) {
243 $vals[
'email'] = $user->getEmail();
244 $auth = $user->getEmailAuthenticationTimestamp();
245 if ( $auth !==
null ) {
246 $vals[
'emailauthenticated'] =
wfTimestamp( TS_ISO_8601, $auth );
250 if ( isset( $this->prop[
'registrationdate'] ) ) {
251 $regDate = $user->getRegistration();
252 if ( $regDate !==
false ) {
253 $vals[
'registrationdate'] =
wfTimestamp( TS_ISO_8601, $regDate );
257 if ( isset( $this->prop[
'acceptlang'] ) ) {
258 $langs = $this->
getRequest()->getAcceptLang();
260 foreach ( $langs as
$lang => $val ) {
261 $r = [
'q' => $val ];
262 ApiResult::setContentValue( $r,
'code',
$lang );
265 ApiResult::setIndexedTagName( $acceptLang,
'lang' );
266 $vals[
'acceptlang'] = $acceptLang;
269 if ( isset( $this->prop[
'unreadcount'] ) ) {
270 $unreadNotifications = $this->watchedItemStore->countUnreadNotifications(
272 self::WL_UNREAD_LIMIT
275 if ( $unreadNotifications ===
true ) {
276 $vals[
'unreadcount'] = self::WL_UNREAD_LIMIT .
'+';
278 $vals[
'unreadcount'] = $unreadNotifications;
282 if ( isset( $this->prop[
'centralids'] ) ) {
288 if ( isset( $this->prop[
'latestcontrib'] ) ) {
290 if ( $ts !==
null ) {
291 $vals[
'latestcontrib'] = $ts;
295 if ( isset( $this->prop[
'cancreateaccount'] ) ) {
296 $status = PermissionStatus::newEmpty();
297 $vals[
'cancreateaccount'] = $user->definitelyCan(
'createaccount',
299 if ( !$status->isGood() ) {
300 $vals[
'cancreateaccounterror'] = $this->
getErrorFormatter()->arrayFromStatus( $status );
316 ApiResult::META_TYPE =>
'assoc',
320 if ( $applyNoRateLimit && !$user->isPingLimitable() ) {
326 if ( !$user->isRegistered() ) {
327 $categories[] =
'anon';
329 $categories[] =
'user';
331 if ( $user->isNewbie() ) {
332 $categories[] =
'ip';
333 $categories[] =
'subnet';
334 if ( $user->isRegistered() ) {
335 $categories[] =
'newbie';
338 $categories = array_merge( $categories, $this->userGroupManager->getUserGroups( $user ) );
341 foreach ( $this->
getConfig()->
get( MainConfigNames::RateLimits ) as $action => $limits ) {
342 foreach ( $categories as $cat ) {
343 if ( isset( $limits[$cat] ) ) {
344 $retval[$action][$cat][
'hits'] = (int)$limits[$cat][0];
345 $retval[$action][$cat][
'seconds'] = (int)$limits[$cat][1];