78 parent::__construct( $query, $moduleName,
'ui' );
79 $this->talkPageNotificationManager = $talkPageNotificationManager;
80 $this->watchedItemStore = $watchedItemStore;
81 $this->userEditTracker = $userEditTracker;
82 $this->userOptionsLookup = $userOptionsLookup;
83 $this->userGroupManager = $userGroupManager;
113 $attachedWiki = UserIdentity::LOCAL
115 $providerIds = array_keys( $config->
get( MainConfigNames::CentralIdLookupProviders ) );
119 'attachedlocal' => [],
121 ApiResult::setArrayType( $ret[
'centralids'],
'assoc' );
122 ApiResult::setArrayType( $ret[
'attachedlocal'],
'assoc' );
123 if ( $attachedWiki ) {
124 $ret[
'attachedwiki'] = [];
125 ApiResult::setArrayType( $ret[
'attachedwiki'],
'assoc' );
129 $centralIdLookupFactory = MediaWikiServices::getInstance()
130 ->getCentralIdLookupFactory();
131 foreach ( $providerIds as $providerId ) {
132 $provider = $centralIdLookupFactory->getLookup( $providerId );
133 $ret[
'centralids'][$providerId] = $provider->centralIdFromName( $name );
134 $ret[
'attachedlocal'][$providerId] = $provider->isAttached( $user );
135 if ( $attachedWiki ) {
136 $ret[
'attachedwiki'][$providerId] = $provider->isAttached( $user, $attachedWiki );
146 $vals[
'id'] = $user->getId();
147 $vals[
'name'] = $user->getName();
149 if ( !$user->isRegistered() ) {
150 $vals[
'anon'] =
true;
153 if ( $user->isTemp() ) {
154 $vals[
'temp'] =
true;
157 if ( isset( $this->prop[
'blockinfo'] ) ) {
158 $block = $user->getBlock();
160 $vals = array_merge( $vals, $this->getBlockDetails( $block ) );
164 if ( isset( $this->prop[
'hasmsg'] ) ) {
165 $vals[
'messages'] = $this->talkPageNotificationManager->userHasNewMessages( $user );
168 if ( isset( $this->prop[
'groups'] ) ) {
169 $vals[
'groups'] = $this->userGroupManager->getUserEffectiveGroups( $user );
170 ApiResult::setArrayType( $vals[
'groups'],
'array' );
171 ApiResult::setIndexedTagName( $vals[
'groups'],
'g' );
174 if ( isset( $this->prop[
'groupmemberships'] ) ) {
175 $ugms = $this->userGroupManager->getUserGroupMemberships( $user );
176 $vals[
'groupmemberships'] = [];
177 foreach ( $ugms as $group => $ugm ) {
178 $vals[
'groupmemberships'][] = [
180 'expiry' => ApiResult::formatExpiry( $ugm->getExpiry() ),
183 ApiResult::setArrayType( $vals[
'groupmemberships'],
'array' );
184 ApiResult::setIndexedTagName( $vals[
'groupmemberships'],
'groupmembership' );
187 if ( isset( $this->prop[
'implicitgroups'] ) ) {
188 $vals[
'implicitgroups'] = $this->userGroupManager->getUserImplicitGroups( $user );
189 ApiResult::setArrayType( $vals[
'implicitgroups'],
'array' );
190 ApiResult::setIndexedTagName( $vals[
'implicitgroups'],
'g' );
193 if ( isset( $this->prop[
'rights'] ) ) {
195 ApiResult::setArrayType( $vals[
'rights'],
'array' );
196 ApiResult::setIndexedTagName( $vals[
'rights'],
'r' );
199 if ( isset( $this->prop[
'changeablegroups'] ) ) {
200 $vals[
'changeablegroups'] = $this->userGroupManager->getGroupsChangeableBy( $this->
getAuthority() );
201 ApiResult::setIndexedTagName( $vals[
'changeablegroups'][
'add'],
'g' );
202 ApiResult::setIndexedTagName( $vals[
'changeablegroups'][
'remove'],
'g' );
203 ApiResult::setIndexedTagName( $vals[
'changeablegroups'][
'add-self'],
'g' );
204 ApiResult::setIndexedTagName( $vals[
'changeablegroups'][
'remove-self'],
'g' );
207 if ( isset( $this->prop[
'options'] ) ) {
208 $vals[
'options'] = $this->userOptionsLookup->getOptions( $user );
209 $vals[
'options'][ApiResult::META_BC_BOOLS] = array_keys( $vals[
'options'] );
212 if ( isset( $this->prop[
'editcount'] ) ) {
215 $vals[
'editcount'] = (int)$user->getEditCount();
218 if ( isset( $this->prop[
'ratelimits'] ) ) {
222 if ( isset( $this->prop[
'theoreticalratelimits'] ) ) {
224 $vals[
'theoreticalratelimits'] = $this->
getRateLimits(
false );
227 if ( isset( $this->prop[
'realname'] ) &&
228 !in_array(
'realname', $this->
getConfig()->
get( MainConfigNames::HiddenPrefs ) )
230 $vals[
'realname'] = $user->getRealName();
233 if ( $this->
getAuthority()->isAllowed(
'viewmyprivateinfo' ) && isset( $this->prop[
'email'] ) ) {
234 $vals[
'email'] = $user->getEmail();
235 $auth = $user->getEmailAuthenticationTimestamp();
236 if ( $auth !==
null ) {
237 $vals[
'emailauthenticated'] =
wfTimestamp( TS_ISO_8601, $auth );
241 if ( isset( $this->prop[
'registrationdate'] ) ) {
242 $regDate = $user->getRegistration();
243 if ( $regDate !==
false ) {
248 if ( isset( $this->prop[
'acceptlang'] ) ) {
249 $langs = $this->
getRequest()->getAcceptLang();
251 foreach ( $langs as $lang => $val ) {
252 $r = [
'q' => $val ];
253 ApiResult::setContentValue( $r,
'code', $lang );
256 ApiResult::setIndexedTagName( $acceptLang,
'lang' );
257 $vals[
'acceptlang'] = $acceptLang;
260 if ( isset( $this->prop[
'unreadcount'] ) ) {
261 $unreadNotifications = $this->watchedItemStore->countUnreadNotifications(
263 self::WL_UNREAD_LIMIT
266 if ( $unreadNotifications ===
true ) {
267 $vals[
'unreadcount'] = self::WL_UNREAD_LIMIT .
'+';
269 $vals[
'unreadcount'] = $unreadNotifications;
273 if ( isset( $this->prop[
'centralids'] ) ) {
279 if ( isset( $this->prop[
'latestcontrib'] ) ) {
281 if ( $ts !==
null ) {
282 $vals[
'latestcontrib'] = $ts;
286 if ( isset( $this->prop[
'cancreateaccount'] ) ) {
287 $status = PermissionStatus::newEmpty();
288 $vals[
'cancreateaccount'] = $user->definitelyCan(
'createaccount',
289 SpecialPage::getTitleFor(
'CreateAccount' ), $status );
290 if ( !$status->isGood() ) {
291 $vals[
'cancreateaccounterror'] = $this->
getErrorFormatter()->arrayFromStatus( $status );
307 ApiResult::META_TYPE =>
'assoc',
311 if ( $applyNoRateLimit && !$user->isPingLimitable() ) {
317 if ( !$user->isRegistered() ) {
318 $categories[] =
'anon';
320 $categories[] =
'user';
322 if ( $user->isNewbie() ) {
323 $categories[] =
'ip';
324 $categories[] =
'subnet';
325 if ( $user->isRegistered() ) {
326 $categories[] =
'newbie';
329 $categories = array_merge( $categories, $this->userGroupManager->getUserGroups( $user ) );
332 foreach ( $this->
getConfig()->
get( MainConfigNames::RateLimits ) as $action => $limits ) {
333 foreach ( $categories as $cat ) {
334 if ( isset( $limits[$cat] ) ) {
335 $retval[$action][$cat][
'hits'] = (int)$limits[$cat][0];
336 $retval[$action][$cat][
'seconds'] = (int)$limits[$cat][1];