4 * Created on July 30, 2007
6 * API for MediaWiki 1.8+
8 * Copyright (C) 2007 Yuri Astrakhan <Firstname><Lastname>@gmail.com
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 * http://www.gnu.org/copyleft/gpl.html
26 if (!defined('MEDIAWIKI')) {
27 // Eclipse helper - will be ignored in production
28 require_once ('ApiQueryBase.php');
32 * Query module to get information about the currently logged-in user
36 class ApiQueryUserInfo
extends ApiQueryBase
{
38 public function __construct($query, $moduleName) {
39 parent
:: __construct($query, $moduleName, 'ui');
42 public function execute() {
43 $params = $this->extractRequestParams();
44 $result = $this->getResult();
47 if (!is_null($params['prop'])) {
48 $this->prop
= array_flip($params['prop']);
50 $this->prop
= array();
52 $r = $this->getCurrentUserInfo();
53 $result->addValue("query", $this->getModuleName(), $r);
56 protected function getCurrentUserInfo() {
58 $result = $this->getResult();
60 $vals['id'] = $wgUser->getId();
61 $vals['name'] = $wgUser->getName();
63 if( $wgUser->isAnon() ) $vals['anon'] = '';
64 if (isset($this->prop
['blockinfo'])) {
65 if ($wgUser->isBlocked()) {
66 $vals['blockedby'] = User
::whoIs($wgUser->blockedBy());
67 $vals['blockreason'] = $wgUser->blockedFor();
70 if (isset($this->prop
['hasmsg']) && $wgUser->getNewtalk()) {
71 $vals['messages'] = '';
73 if (isset($this->prop
['groups'])) {
74 $vals['groups'] = $wgUser->getGroups();
75 $result->setIndexedTagName($vals['groups'], 'g'); // even if empty
77 if (isset($this->prop
['rights'])) {
78 $vals['rights'] = $wgUser->getRights();
79 $result->setIndexedTagName($vals['rights'], 'r'); // even if empty
81 if (isset($this->prop
['options'])) {
82 $vals['options'] = (is_null($wgUser->mOptions
) ? User
::getDefaultOptions() : $wgUser->mOptions
);
84 if (isset($this->prop
['editcount'])) {
85 $vals['editcount'] = $wgUser->getEditCount();
90 public function getAllowedParams() {
93 ApiBase
:: PARAM_DFLT
=> NULL,
94 ApiBase
:: PARAM_ISMULTI
=> true,
95 ApiBase
:: PARAM_TYPE
=> array (
105 ApiBase
:: PARAM_ISMULTI
=> true
110 public function getParamDescription() {
113 'What pieces of information to include',
114 ' blockinfo - tags if the user is blocked, by whom, and for what reason',
115 ' hasmsg - adds a tag "message" if user has pending messages',
116 ' groups - lists all the groups the user belongs to',
117 ' rights - lists of all rights the user has',
118 ' options - lists all preferences the user has set',
119 ' editcount - adds the user\'s edit count'
121 'users' => 'A list of other users to obtain the same information for'
125 public function getDescription() {
126 return 'Get information about the current user';
129 protected function getExamples() {
131 'api.php?action=query&meta=userinfo',
132 'api.php?action=query&meta=userinfo&uiprop=blockinfo|groups|rights|hasmsg',
133 'api.php?action=query&meta=userinfo&uioption=rememberpassword',
137 public function getVersion() {
138 return __CLASS__
. ': $Id$';