* (bug 2919) Allow the protection of non-existent pages using the regular protection...
[mediawiki.git] / includes / api / ApiQueryUserInfo.php
blobb653c47411da34108e5f774ce84cbe8d9c46a929
1 <?php
3 /*
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');
31 /**
32 * Query module to get information about the currently logged-in user
34 * @addtogroup API
36 class ApiQueryUserInfo extends ApiQueryBase {
38 public function __construct($query, $moduleName) {
39 parent :: __construct($query, $moduleName, 'ui');
42 public function execute() {
44 global $wgUser;
46 $params = $this->extractRequestParams();
47 $result = $this->getResult();
49 $vals = array();
50 $vals['name'] = $wgUser->getName();
52 if( $wgUser->isAnon() ) $vals['anon'] = '';
54 if (!is_null($params['prop'])) {
55 $prop = array_flip($params['prop']);
56 if (isset($prop['blockinfo'])) {
57 if ($wgUser->isBlocked()) {
58 $vals['blockedby'] = User::whoIs($wgUser->blockedBy());
59 $vals['blockreason'] = $wgUser->blockedFor();
62 if (isset($prop['hasmsg']) && $wgUser->getNewtalk()) {
63 $vals['messages'] = '';
65 if (isset($prop['groups'])) {
66 $vals['groups'] = $wgUser->getGroups();
67 $result->setIndexedTagName($vals['groups'], 'g'); // even if empty
69 if (isset($prop['rights'])) {
70 $vals['rights'] = $wgUser->getRights();
71 $result->setIndexedTagName($vals['rights'], 'r'); // even if empty
73 if (isset($prop['options'])) {
74 $vals['options'] = (is_null($wgUser->mOptions) ? User::getDefaultOptions() : $wgUser->mOptions);
78 $result->addValue(null, $this->getModuleName(), $vals);
81 protected function getAllowedParams() {
82 return array (
83 'prop' => array (
84 ApiBase :: PARAM_DFLT => NULL,
85 ApiBase :: PARAM_ISMULTI => true,
86 ApiBase :: PARAM_TYPE => array (
87 'blockinfo',
88 'hasmsg',
89 'groups',
90 'rights',
91 'options'
96 protected function getParamDescription() {
97 return array (
98 'prop' => array(
99 'What pieces of information to include',
100 ' blockinfo - tags if the user is blocked, by whom, and for what reason',
101 ' hasmsg - adds a tag "message" if user has pending messages',
102 ' groups - lists all the groups the current user belongs to',
103 ' rights - lists of all rights the current user has',
104 ' options - lists all preferences the current user has set'
109 protected function getDescription() {
110 return 'Get information about the current user';
113 protected function getExamples() {
114 return array (
115 'api.php?action=query&meta=userinfo',
116 'api.php?action=query&meta=userinfo&uiprop=blockinfo|groups|rights|hasmsg',
117 'api.php?action=query&meta=userinfo&uioption=rememberpassword',
121 public function getVersion() {
122 return __CLASS__ . ': $Id$';