API: Adding cascade flag to prop=info&inprop=protection
[lhc/web/wiklou.git] / includes / api / ApiQueryUserInfo.php
1 <?php
2
3 /*
4 * Created on July 30, 2007
5 *
6 * API for MediaWiki 1.8+
7 *
8 * Copyright (C) 2007 Yuri Astrakhan <Firstname><Lastname>@gmail.com
9 *
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.
14 *
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.
19 *
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
24 */
25
26 if (!defined('MEDIAWIKI')) {
27 // Eclipse helper - will be ignored in production
28 require_once ('ApiQueryBase.php');
29 }
30
31 /**
32 * Query module to get information about the currently logged-in user
33 *
34 * @addtogroup API
35 */
36 class ApiQueryUserInfo extends ApiQueryBase {
37
38 public function __construct($query, $moduleName) {
39 parent :: __construct($query, $moduleName, 'ui');
40 }
41
42 public function execute() {
43
44 global $wgUser;
45
46 $params = $this->extractRequestParams();
47 $result = $this->getResult();
48
49 $vals = array();
50 $vals['name'] = $wgUser->getName();
51
52 if( $wgUser->isAnon() ) $vals['anon'] = '';
53
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();
60 }
61 }
62 if (isset($prop['hasmsg']) && $wgUser->getNewtalk()) {
63 $vals['messages'] = '';
64 }
65 if (isset($prop['groups'])) {
66 $vals['groups'] = $wgUser->getGroups();
67 $result->setIndexedTagName($vals['groups'], 'g'); // even if empty
68 }
69 if (isset($prop['rights'])) {
70 $vals['rights'] = $wgUser->getRights();
71 $result->setIndexedTagName($vals['rights'], 'r'); // even if empty
72 }
73 if (isset($prop['options'])) {
74 $vals['options'] = (is_null($wgUser->mOptions) ? User::getDefaultOptions() : $wgUser->mOptions);
75 }
76 }
77
78 $result->addValue("query", $this->getModuleName(), $vals);
79 }
80
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'
92 ))
93 );
94 }
95
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'
105 )
106 );
107 }
108
109 protected function getDescription() {
110 return 'Get information about the current user';
111 }
112
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',
118 );
119 }
120
121 public function getVersion() {
122 return __CLASS__ . ': $Id$';
123 }
124 }
125