42 private const WL_UNREAD_LIMIT = 1000;
53 private $talkPageNotificationManager;
58 private $watchedItemStore;
63 private $userEditTracker;
68 private $userOptionsLookup;
71 private $userGroupManager;
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;
103 if ( $this->params[
'prop'] !==
null ) {
104 $this->prop = array_fill_keys( $this->params[
'prop'],
true );
126 $attachedWiki = UserIdentity::LOCAL
128 $providerIds = array_keys( $config->
get( MainConfigNames::CentralIdLookupProviders ) );
132 'attachedlocal' => [],
136 if ( $attachedWiki ) {
137 $ret[
'attachedwiki'] = [];
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 );
183 if ( isset( $this->prop[
'groupmemberships'] ) ) {
184 $ugms = $this->userGroupManager->getUserGroupMemberships( $user );
185 $vals[
'groupmemberships'] = [];
186 foreach ( $ugms as $group => $ugm ) {
187 $vals[
'groupmemberships'][] = [
196 if ( isset( $this->prop[
'implicitgroups'] ) ) {
197 $vals[
'implicitgroups'] = $this->userGroupManager->getUserImplicitGroups( $user );
202 if ( isset( $this->prop[
'rights'] ) ) {
208 if ( isset( $this->prop[
'changeablegroups'] ) ) {
209 $vals[
'changeablegroups'] = $this->userGroupManager->getGroupsChangeableBy( $this->
getAuthority() );
216 if ( isset( $this->prop[
'options'] ) ) {
217 $vals[
'options'] = $this->userOptionsLookup->getOptions( $user );
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 ];
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 );
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];
357 $timestamp = $this->userEditTracker->getLatestEditTimestamp( $this->
getUser() );
358 if ( $timestamp ===
false ) {
361 return MWTimestamp::convert( TS_ISO_8601, $timestamp );
367 ParamValidator::PARAM_ISMULTI =>
true,
368 ParamValidator::PARAM_ALL =>
true,
369 ParamValidator::PARAM_TYPE => [
380 'theoreticalratelimits',
392 'apihelp-query+userinfo-paramvalue-prop-unreadcount',
393 self::WL_UNREAD_LIMIT - 1,
394 self::WL_UNREAD_LIMIT .
'+',
398 'attachedwiki' =>
null,
404 'action=query&meta=userinfo'
405 =>
'apihelp-query+userinfo-example-simple',
406 'action=query&meta=userinfo&uiprop=blockinfo|groups|rights|hasmsg'
407 =>
'apihelp-query+userinfo-example-data',
412 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Userinfo';
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
getPermissionManager()
Obtain a PermissionManager instance that subclasses may use in their authorization checks.
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, or 'string' with PARAM_ISMULTI,...
getResult()
Get the result object.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
getModuleName()
Get the name of the module being executed by this instance.
This is a base class for all Query modules.
Query module to get information about the currently logged-in user.
getExamplesMessages()
Returns usage examples for this module.
static getCentralUserInfo(Config $config, UserIdentity $user, $attachedWiki=UserIdentity::LOCAL)
Get central user info.
getLatestContributionTime()
getHelpUrls()
Return links to more detailed help pages about the module.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
getRateLimits(bool $applyNoRateLimit)
Get the rate limits that apply to the user, or the rate limits that would apply if the user didn't ha...
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
__construct(ApiQuery $query, $moduleName, TalkPageNotificationManager $talkPageNotificationManager, WatchedItemStore $watchedItemStore, UserEditTracker $userEditTracker, UserOptionsLookup $userOptionsLookup, UserGroupManager $userGroupManager)
This is the main query class.
const META_TYPE
Key for the 'type' metadata item.
static setArrayType(array &$arr, $type, $kvpKeyName=null)
Set the array data type.
const META_BC_BOOLS
Key for the 'BC bools' metadata item.
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
static setContentValue(array &$arr, $name, $value, $flags=0)
Add an output value to the array by name and mark as META_CONTENT.
static formatExpiry( $expiry, $infinity='infinity')
Format an expiry timestamp for API output.
A class containing constants representing the names of configuration variables.
Manages user talk page notifications.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
Storage layer class for WatchedItems.
Interface for configuration instances.
get( $name)
Get a configuration variable such as "Sitename" or "UploadMaintenance.".
if(!isset( $args[0])) $lang