MediaWiki  1.23.14
ApiQueryUserInfo.php
Go to the documentation of this file.
1 <?php
33 
34  private $prop = array();
35 
36  public function __construct( $query, $moduleName ) {
37  parent::__construct( $query, $moduleName, 'ui' );
38  }
39 
40  public function execute() {
41  $params = $this->extractRequestParams();
42  $result = $this->getResult();
43 
44  if ( !is_null( $params['prop'] ) ) {
45  $this->prop = array_flip( $params['prop'] );
46  }
47 
48  $r = $this->getCurrentUserInfo();
49  $result->addValue( 'query', $this->getModuleName(), $r );
50  }
51 
52  protected function getCurrentUserInfo() {
53  global $wgHiddenPrefs;
54  $user = $this->getUser();
55  $result = $this->getResult();
56  $vals = array();
57  $vals['id'] = intval( $user->getId() );
58  $vals['name'] = $user->getName();
59 
60  if ( $user->isAnon() ) {
61  $vals['anon'] = '';
62  }
63 
64  if ( isset( $this->prop['blockinfo'] ) ) {
65  if ( $user->isBlocked() ) {
66  $block = $user->getBlock();
67  $vals['blockid'] = $block->getId();
68  $vals['blockedby'] = $block->getByName();
69  $vals['blockedbyid'] = $block->getBy();
70  $vals['blockreason'] = $user->blockedFor();
71  }
72  }
73 
74  if ( isset( $this->prop['hasmsg'] ) && $user->getNewtalk() ) {
75  $vals['messages'] = '';
76  }
77 
78  if ( isset( $this->prop['groups'] ) ) {
79  $vals['groups'] = $user->getEffectiveGroups();
80  $result->setIndexedTagName( $vals['groups'], 'g' ); // even if empty
81  }
82 
83  if ( isset( $this->prop['implicitgroups'] ) ) {
84  $vals['implicitgroups'] = $user->getAutomaticGroups();
85  $result->setIndexedTagName( $vals['implicitgroups'], 'g' ); // even if empty
86  }
87 
88  if ( isset( $this->prop['rights'] ) ) {
89  // User::getRights() may return duplicate values, strip them
90  $vals['rights'] = array_values( array_unique( $user->getRights() ) );
91  $result->setIndexedTagName( $vals['rights'], 'r' ); // even if empty
92  }
93 
94  if ( isset( $this->prop['changeablegroups'] ) ) {
95  $vals['changeablegroups'] = $user->changeableGroups();
96  $result->setIndexedTagName( $vals['changeablegroups']['add'], 'g' );
97  $result->setIndexedTagName( $vals['changeablegroups']['remove'], 'g' );
98  $result->setIndexedTagName( $vals['changeablegroups']['add-self'], 'g' );
99  $result->setIndexedTagName( $vals['changeablegroups']['remove-self'], 'g' );
100  }
101 
102  if ( isset( $this->prop['options'] ) ) {
103  $vals['options'] = $user->getOptions();
104  }
105 
106  if ( isset( $this->prop['preferencestoken'] ) &&
107  is_null( $this->getMain()->getRequest()->getVal( 'callback' ) ) &&
108  $user->isAllowed( 'editmyoptions' )
109  ) {
110  $vals['preferencestoken'] = $user->getEditToken( '', $this->getMain()->getRequest() );
111  }
112 
113  if ( isset( $this->prop['editcount'] ) ) {
114  // use intval to prevent null if a non-logged-in user calls
115  // api.php?format=jsonfm&action=query&meta=userinfo&uiprop=editcount
116  $vals['editcount'] = intval( $user->getEditCount() );
117  }
118 
119  if ( isset( $this->prop['ratelimits'] ) ) {
120  $vals['ratelimits'] = $this->getRateLimits();
121  }
122 
123  if ( isset( $this->prop['realname'] ) && !in_array( 'realname', $wgHiddenPrefs ) ) {
124  $vals['realname'] = $user->getRealName();
125  }
126 
127  if ( $user->isAllowed( 'viewmyprivateinfo' ) ) {
128  if ( isset( $this->prop['email'] ) ) {
129  $vals['email'] = $user->getEmail();
130  $auth = $user->getEmailAuthenticationTimestamp();
131  if ( !is_null( $auth ) ) {
132  $vals['emailauthenticated'] = wfTimestamp( TS_ISO_8601, $auth );
133  }
134  }
135  }
136 
137  if ( isset( $this->prop['registrationdate'] ) ) {
138  $regDate = $user->getRegistration();
139  if ( $regDate !== false ) {
140  $vals['registrationdate'] = wfTimestamp( TS_ISO_8601, $regDate );
141  }
142  }
143 
144  if ( isset( $this->prop['acceptlang'] ) ) {
145  $langs = $this->getRequest()->getAcceptLang();
146  $acceptLang = array();
147  foreach ( $langs as $lang => $val ) {
148  $r = array( 'q' => $val );
149  ApiResult::setContent( $r, $lang );
150  $acceptLang[] = $r;
151  }
152  $result->setIndexedTagName( $acceptLang, 'lang' );
153  $vals['acceptlang'] = $acceptLang;
154  }
155 
156  return $vals;
157  }
158 
159  protected function getRateLimits() {
160  global $wgRateLimits;
161  $user = $this->getUser();
162  if ( !$user->isPingLimitable() ) {
163  return array(); // No limits
164  }
165 
166  // Find out which categories we belong to
167  $categories = array();
168  if ( $user->isAnon() ) {
169  $categories[] = 'anon';
170  } else {
171  $categories[] = 'user';
172  }
173  if ( $user->isNewbie() ) {
174  $categories[] = 'ip';
175  $categories[] = 'subnet';
176  if ( !$user->isAnon() ) {
177  $categories[] = 'newbie';
178  }
179  }
180  $categories = array_merge( $categories, $user->getGroups() );
181 
182  // Now get the actual limits
183  $retval = array();
184  foreach ( $wgRateLimits as $action => $limits ) {
185  foreach ( $categories as $cat ) {
186  if ( isset( $limits[$cat] ) && !is_null( $limits[$cat] ) ) {
187  $retval[$action][$cat]['hits'] = intval( $limits[$cat][0] );
188  $retval[$action][$cat]['seconds'] = intval( $limits[$cat][1] );
189  }
190  }
191  }
192 
193  return $retval;
194  }
195 
196  public function getAllowedParams() {
197  return array(
198  'prop' => array(
199  ApiBase::PARAM_DFLT => null,
200  ApiBase::PARAM_ISMULTI => true,
202  'blockinfo',
203  'hasmsg',
204  'groups',
205  'implicitgroups',
206  'rights',
207  'changeablegroups',
208  'options',
209  'preferencestoken',
210  'editcount',
211  'ratelimits',
212  'email',
213  'realname',
214  'acceptlang',
215  'registrationdate'
216  )
217  )
218  );
219  }
220 
221  public function getParamDescription() {
222  return array(
223  'prop' => array(
224  'What pieces of information to include',
225  ' blockinfo - Tags if the current user is blocked, by whom, and for what reason',
226  ' hasmsg - Adds a tag "message" if the current user has pending messages',
227  ' groups - Lists all the groups the current user belongs to',
228  ' implicitgroups - Lists all the groups the current user is automatically a member of',
229  ' rights - Lists all the rights the current user has',
230  ' changeablegroups - Lists the groups the current user can add to and remove from',
231  ' options - Lists all preferences the current user has set',
232  ' preferencestoken - Get a token to change current user\'s preferences',
233  ' editcount - Adds the current user\'s edit count',
234  ' ratelimits - Lists all rate limits applying to the current user',
235  ' realname - Adds the user\'s real name',
236  ' email - Adds the user\'s email address and email authentication date',
237  ' acceptlang - Echoes the Accept-Language header sent by ' .
238  'the client in a structured format',
239  ' registrationdate - Adds the user\'s registration date',
240  )
241  );
242  }
243 
244  public function getResultProperties() {
245  return array(
246  ApiBase::PROP_LIST => false,
247  '' => array(
248  'id' => 'integer',
249  'name' => 'string',
250  'anon' => 'boolean'
251  ),
252  'blockinfo' => array(
253  'blockid' => array(
254  ApiBase::PROP_TYPE => 'integer',
255  ApiBase::PROP_NULLABLE => true
256  ),
257  'blockedby' => array(
258  ApiBase::PROP_TYPE => 'string',
259  ApiBase::PROP_NULLABLE => true
260  ),
261  'blockedbyid' => array(
262  ApiBase::PROP_TYPE => 'integer',
263  ApiBase::PROP_NULLABLE => true
264  ),
265  'blockedreason' => array(
266  ApiBase::PROP_TYPE => 'string',
267  ApiBase::PROP_NULLABLE => true
268  )
269  ),
270  'hasmsg' => array(
271  'messages' => 'boolean'
272  ),
273  'preferencestoken' => array(
274  'preferencestoken' => 'string'
275  ),
276  'editcount' => array(
277  'editcount' => 'integer'
278  ),
279  'realname' => array(
280  'realname' => array(
281  ApiBase::PROP_TYPE => 'string',
282  ApiBase::PROP_NULLABLE => true
283  )
284  ),
285  'email' => array(
286  'email' => 'string',
287  'emailauthenticated' => array(
288  ApiBase::PROP_TYPE => 'timestamp',
289  ApiBase::PROP_NULLABLE => true
290  )
291  ),
292  'registrationdate' => array(
293  'registrationdate' => array(
294  ApiBase::PROP_TYPE => 'timestamp',
295  ApiBase::PROP_NULLABLE => true
296  )
297  )
298  );
299  }
300 
301  public function getDescription() {
302  return 'Get information about the current user.';
303  }
304 
305  public function getExamples() {
306  return array(
307  'api.php?action=query&meta=userinfo',
308  'api.php?action=query&meta=userinfo&uiprop=blockinfo|groups|rights|hasmsg',
309  );
310  }
311 
312  public function getHelpUrls() {
313  return 'https://www.mediawiki.org/wiki/API:Meta#userinfo_.2F_ui';
314  }
315 }
$result
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. $reader:XMLReader object $logInfo:Array of information Return false to stop further processing of the tag 'ImportHandlePageXMLTag':When parsing a XML tag in a page. $reader:XMLReader object $pageInfo:Array of information Return false to stop further processing of the tag 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information Return false to stop further processing of the tag 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. $reader:XMLReader object Return false to stop further processing of the tag 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. $reader:XMLReader object $revisionInfo:Array of information Return false to stop further processing of the tag 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. $title:Title object for the current page $request:WebRequest $ignoreRedirect:boolean to skip redirect check $target:Title/string of redirect target $article:Article object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) $article:article(object) being checked 'IsTrustedProxy':Override the result of wfIsTrustedProxy() $ip:IP being check $result:Change this value to override the result of wfIsTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of User::isValidEmailAddr(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetMagic':DEPRECATED, use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetSpecialPageAliases':DEPRECATED, use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Associative array mapping language codes to prefixed links of the form "language:title". & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LinkBegin':Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1528
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
ApiResult\setContent
static setContent(&$arr, $value, $subElemName=null)
Adds a content element to an array.
Definition: ApiResult.php:201
ApiQueryUserInfo\__construct
__construct( $query, $moduleName)
Definition: ApiQueryUserInfo.php:36
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:2530
ApiQueryUserInfo
Query module to get information about the currently logged-in user.
Definition: ApiQueryUserInfo.php:32
ApiBase\PARAM_TYPE
const PARAM_TYPE
Definition: ApiBase.php:50
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:205
$params
$params
Definition: styleTest.css.php:40
ContextSource\getRequest
getRequest()
Get the WebRequest object.
Definition: ContextSource.php:77
ContextSource\getUser
getUser()
Get the User object.
Definition: ContextSource.php:132
ApiBase\PROP_LIST
const PROP_LIST
Definition: ApiBase.php:73
ApiQueryUserInfo\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiQueryUserInfo.php:196
ApiQueryUserInfo\getExamples
getExamples()
Returns usage examples for this module.
Definition: ApiQueryUserInfo.php:305
ApiQueryBase
This is a base class for all Query modules.
Definition: ApiQueryBase.php:34
TS_ISO_8601
const TS_ISO_8601
ISO 8601 format with no timezone: 1986-02-09T20:00:00Z.
Definition: GlobalFunctions.php:2495
ApiQueryUserInfo\getResultProperties
getResultProperties()
Returns possible properties in the result, grouped by the value of the prop parameter that shows them...
Definition: ApiQueryUserInfo.php:244
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
ApiBase\PROP_TYPE
const PROP_TYPE
Definition: ApiBase.php:74
ApiBase\extractRequestParams
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:707
ApiQueryUserInfo\getParamDescription
getParamDescription()
Returns an array of parameter descriptions.
Definition: ApiQueryUserInfo.php:221
ApiBase\PROP_NULLABLE
const PROP_NULLABLE
Definition: ApiBase.php:76
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:237
ApiQueryUserInfo\getCurrentUserInfo
getCurrentUserInfo()
Definition: ApiQueryUserInfo.php:52
ApiQueryUserInfo\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiQueryUserInfo.php:40
ApiBase\PARAM_DFLT
const PARAM_DFLT
Definition: ApiBase.php:46
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
ApiQueryUserInfo\$prop
$prop
Definition: ApiQueryUserInfo.php:34
ApiBase\getModuleName
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:148
ApiBase\PARAM_ISMULTI
const PARAM_ISMULTI
Definition: ApiBase.php:48
ApiBase\getMain
getMain()
Get the main module.
Definition: ApiBase.php:188
ApiQueryUserInfo\getRateLimits
getRateLimits()
Definition: ApiQueryUserInfo.php:159
$query
return true to allow those checks to and false if checking is done use this to change the tables headers temp or archived zone change it to an object instance and return false override the list derivative used the name of the old file when set the default code will be skipped add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition: hooks.txt:1105
ApiQueryUserInfo\getDescription
getDescription()
Returns the description string for this module.
Definition: ApiQueryUserInfo.php:301
ApiQueryUserInfo\getHelpUrls
getHelpUrls()
Definition: ApiQueryUserInfo.php:312
$retval
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account incomplete not yet checked for validity & $retval
Definition: hooks.txt:237