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 ( $user->isTemp() ) {
153 $vals[
'temp'] =
true;
156 if ( isset( $this->prop[
'blockinfo'] ) ) {
157 $block = $user->getBlock();
159 $vals = array_merge( $vals, $this->getBlockDetails( $block ) );
163 if ( isset( $this->prop[
'hasmsg'] ) ) {
164 $vals[
'messages'] = $this->talkPageNotificationManager->userHasNewMessages( $user );
167 if ( isset( $this->prop[
'groups'] ) ) {
168 $vals[
'groups'] = $this->userGroupManager->getUserEffectiveGroups( $user );
169 ApiResult::setArrayType( $vals[
'groups'],
'array' );
170 ApiResult::setIndexedTagName( $vals[
'groups'],
'g' );
173 if ( isset( $this->prop[
'groupmemberships'] ) ) {
174 $ugms = $this->userGroupManager->getUserGroupMemberships( $user );
175 $vals[
'groupmemberships'] = [];
176 foreach ( $ugms as $group => $ugm ) {
177 $vals[
'groupmemberships'][] = [
179 'expiry' => ApiResult::formatExpiry( $ugm->getExpiry() ),
182 ApiResult::setArrayType( $vals[
'groupmemberships'],
'array' );
183 ApiResult::setIndexedTagName( $vals[
'groupmemberships'],
'groupmembership' );
186 if ( isset( $this->prop[
'implicitgroups'] ) ) {
187 $vals[
'implicitgroups'] = $this->userGroupManager->getUserImplicitGroups( $user );
188 ApiResult::setArrayType( $vals[
'implicitgroups'],
'array' );
189 ApiResult::setIndexedTagName( $vals[
'implicitgroups'],
'g' );
192 if ( isset( $this->prop[
'rights'] ) ) {
194 ApiResult::setArrayType( $vals[
'rights'],
'array' );
195 ApiResult::setIndexedTagName( $vals[
'rights'],
'r' );
198 if ( isset( $this->prop[
'changeablegroups'] ) ) {
199 $vals[
'changeablegroups'] = $this->userGroupManager->getGroupsChangeableBy( $this->
getAuthority() );
200 ApiResult::setIndexedTagName( $vals[
'changeablegroups'][
'add'],
'g' );
201 ApiResult::setIndexedTagName( $vals[
'changeablegroups'][
'remove'],
'g' );
202 ApiResult::setIndexedTagName( $vals[
'changeablegroups'][
'add-self'],
'g' );
203 ApiResult::setIndexedTagName( $vals[
'changeablegroups'][
'remove-self'],
'g' );
206 if ( isset( $this->prop[
'options'] ) ) {
207 $vals[
'options'] = $this->userOptionsLookup->getOptions( $user );
208 $vals[
'options'][ApiResult::META_BC_BOOLS] = array_keys( $vals[
'options'] );
211 if ( isset( $this->prop[
'editcount'] ) ) {
214 $vals[
'editcount'] = (int)$user->getEditCount();
217 if ( isset( $this->prop[
'ratelimits'] ) ) {
221 if ( isset( $this->prop[
'theoreticalratelimits'] ) ) {
223 $vals[
'theoreticalratelimits'] = $this->
getRateLimits(
false );
226 if ( isset( $this->prop[
'realname'] ) &&
227 !in_array(
'realname', $this->
getConfig()->
get( MainConfigNames::HiddenPrefs ) )
229 $vals[
'realname'] = $user->getRealName();
232 if ( $this->
getAuthority()->isAllowed(
'viewmyprivateinfo' ) && isset( $this->prop[
'email'] ) ) {
233 $vals[
'email'] = $user->getEmail();
234 $auth = $user->getEmailAuthenticationTimestamp();
235 if ( $auth !==
null ) {
236 $vals[
'emailauthenticated'] =
wfTimestamp( TS_ISO_8601, $auth );
240 if ( isset( $this->prop[
'registrationdate'] ) ) {
241 $regDate = $user->getRegistration();
242 if ( $regDate !==
false ) {
243 $vals[
'registrationdate'] =
wfTimestamp( TS_ISO_8601, $regDate );
247 if ( isset( $this->prop[
'acceptlang'] ) ) {
248 $langs = $this->
getRequest()->getAcceptLang();
250 foreach ( $langs as $lang => $val ) {
251 $r = [
'q' => $val ];
252 ApiResult::setContentValue( $r,
'code', $lang );
255 ApiResult::setIndexedTagName( $acceptLang,
'lang' );
256 $vals[
'acceptlang'] = $acceptLang;
259 if ( isset( $this->prop[
'unreadcount'] ) ) {
260 $unreadNotifications = $this->watchedItemStore->countUnreadNotifications(
262 self::WL_UNREAD_LIMIT
265 if ( $unreadNotifications ===
true ) {
266 $vals[
'unreadcount'] = self::WL_UNREAD_LIMIT .
'+';
268 $vals[
'unreadcount'] = $unreadNotifications;
272 if ( isset( $this->prop[
'centralids'] ) ) {
278 if ( isset( $this->prop[
'latestcontrib'] ) ) {
280 if ( $ts !==
null ) {
281 $vals[
'latestcontrib'] = $ts;
285 if ( isset( $this->prop[
'cancreateaccount'] ) ) {
286 $status = PermissionStatus::newEmpty();
287 $vals[
'cancreateaccount'] = $user->definitelyCan(
'createaccount',
288 SpecialPage::getTitleFor(
'CreateAccount' ), $status );
289 if ( !$status->isGood() ) {
290 $vals[
'cancreateaccounterror'] = $this->
getErrorFormatter()->arrayFromStatus( $status );
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];