Index: trunk/phase3/includes/api/ApiQuery.php |
— | — | @@ -75,7 +75,7 @@ |
76 | 76 | |
77 | 77 | private $mQueryMetaModules = array ( |
78 | 78 | 'siteinfo' => 'ApiQuerySiteinfo', |
79 | | - // 'userinfo' => 'ApiQueryUserinfo', |
| 79 | + 'userinfo' => 'ApiQueryUserInfo', |
80 | 80 | ); |
81 | 81 | |
82 | 82 | private $mSlaveDB = null; |
Index: trunk/phase3/includes/api/ApiQuerySiteinfo.php |
— | — | @@ -99,6 +99,7 @@ |
100 | 100 | |
101 | 101 | protected function appendInterwikiMap($property, $filter) { |
102 | 102 | |
| 103 | + $this->resetQueryParams(); |
103 | 104 | $this->addTables('interwiki'); |
104 | 105 | $this->addFields(array('iw_prefix', 'iw_local', 'iw_url')); |
105 | 106 | |
Index: trunk/phase3/includes/api/ApiQueryUserInfo.php |
— | — | @@ -0,0 +1,134 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/* |
| 5 | + * Created on July 30, 2007 |
| 6 | + * |
| 7 | + * API for MediaWiki 1.8+ |
| 8 | + * |
| 9 | + * Copyright (C) 2007 Yuri Astrakhan <Firstname><Lastname>@gmail.com |
| 10 | + * |
| 11 | + * This program is free software; you can redistribute it and/or modify |
| 12 | + * it under the terms of the GNU General Public License as published by |
| 13 | + * the Free Software Foundation; either version 2 of the License, or |
| 14 | + * (at your option) any later version. |
| 15 | + * |
| 16 | + * This program is distributed in the hope that it will be useful, |
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | + * GNU General Public License for more details. |
| 20 | + * |
| 21 | + * You should have received a copy of the GNU General Public License along |
| 22 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 23 | + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 24 | + * http://www.gnu.org/copyleft/gpl.html |
| 25 | + */ |
| 26 | + |
| 27 | +if (!defined('MEDIAWIKI')) { |
| 28 | + // Eclipse helper - will be ignored in production |
| 29 | + require_once ('ApiQueryBase.php'); |
| 30 | +} |
| 31 | + |
| 32 | +/** |
| 33 | + * Query module to get information about the currently logged-in user |
| 34 | + * |
| 35 | + * @addtogroup API |
| 36 | + */ |
| 37 | +class ApiQueryUserInfo extends ApiQueryBase { |
| 38 | + |
| 39 | + public function __construct($query, $moduleName) { |
| 40 | + parent :: __construct($query, $moduleName, 'ui'); |
| 41 | + } |
| 42 | + |
| 43 | + public function execute() { |
| 44 | + |
| 45 | + global $wgUser; |
| 46 | + |
| 47 | + $params = $this->extractRequestParams(); |
| 48 | + $result = $this->getResult(); |
| 49 | + |
| 50 | + $vals = array(); |
| 51 | + $vals['name'] = $wgUser->getName(); |
| 52 | + |
| 53 | + if( $wgUser->isAnon() ) $vals['anon'] = ''; |
| 54 | + |
| 55 | + if (!is_null($params['prop'])) { |
| 56 | + $prop = array_flip($params['prop']); |
| 57 | + if (isset($prop['blockinfo'])) { |
| 58 | + if ($wgUser->isBlocked()) { |
| 59 | + $id = $wgUser->blockedBy(); |
| 60 | + $vals['blockedby'] = is_numeric($id) ? User::whoIs($id) : $id; |
| 61 | + $vals['blockreason'] = $wgUser->blockedFor(); |
| 62 | + } |
| 63 | + } |
| 64 | + if (isset($prop['hasmsg']) && $wgUser->getNewtalk()) { |
| 65 | + $vals['messages'] = ''; |
| 66 | + } |
| 67 | + if (isset($prop['groups'])) { |
| 68 | + $vals['groups'] = $wgUser->getGroups(); |
| 69 | + $result->setIndexedTagName($vals['groups'], 'g'); // even if empty |
| 70 | + } |
| 71 | + if (isset($prop['rights'])) { |
| 72 | + $vals['rights'] = $wgUser->getRights(); |
| 73 | + $result->setIndexedTagName($vals['rights'], 'r'); // even if empty |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + if (!empty($params['option'])) { |
| 78 | + foreach( $params['option'] as $option ) { |
| 79 | + if (empty($option)) |
| 80 | + $this->dieUsage('Empty value is not allowed for the option parameter', 'option'); |
| 81 | + $vals['options'][$option] = $wgUser->getOption($option); |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + $result->addValue(null, $this->getModuleName(), $vals); |
| 86 | + } |
| 87 | + |
| 88 | + protected function getAllowedParams() { |
| 89 | + return array ( |
| 90 | + 'prop' => array ( |
| 91 | + ApiBase :: PARAM_DFLT => NULL, |
| 92 | + ApiBase :: PARAM_ISMULTI => true, |
| 93 | + ApiBase :: PARAM_TYPE => array ( |
| 94 | + 'blockinfo', |
| 95 | + 'hasmsg', |
| 96 | + 'groups', |
| 97 | + 'rights', |
| 98 | + )), |
| 99 | + 'option' => array ( |
| 100 | + ApiBase :: PARAM_DFLT => NULL, |
| 101 | + ApiBase :: PARAM_ISMULTI => true, |
| 102 | + ), |
| 103 | + ); |
| 104 | + } |
| 105 | + |
| 106 | + protected function getParamDescription() { |
| 107 | + return array ( |
| 108 | + 'prop' => array( |
| 109 | + 'What pieces of information to include', |
| 110 | + ' blockinfo - tags if the user is blocked, by whom, and for what reason', |
| 111 | + ' hasmsg - adds a tag "message" if user has pending messages', |
| 112 | + ' groups - lists all the groups the current user belongs to', |
| 113 | + ' rights - lists of all rights the current user has', |
| 114 | + ), |
| 115 | + 'option' => 'A list of user preference options to get', |
| 116 | + ); |
| 117 | + } |
| 118 | + |
| 119 | + protected function getDescription() { |
| 120 | + return 'Get information about the current user'; |
| 121 | + } |
| 122 | + |
| 123 | + protected function getExamples() { |
| 124 | + return array ( |
| 125 | + 'api.php?action=query&meta=userinfo', |
| 126 | + 'api.php?action=query&meta=userinfo&uiprop=blockinfo|groups|rights|hasmsg', |
| 127 | + 'api.php?action=query&meta=userinfo&uioption=rememberpassword', |
| 128 | + ); |
| 129 | + } |
| 130 | + |
| 131 | + public function getVersion() { |
| 132 | + return __CLASS__ . ': $Id$'; |
| 133 | + } |
| 134 | +} |
| 135 | + |
Property changes on: trunk/phase3/includes/api/ApiQueryUserInfo.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 136 | + native |
Added: svn:keywords |
2 | 137 | + Id |
Index: trunk/phase3/includes/api/ApiMain.php |
— | — | @@ -456,8 +456,7 @@ |
457 | 457 | public function isSysop() { |
458 | 458 | if (!isset ($this->mIsSysop)) { |
459 | 459 | global $wgUser; |
460 | | - $this->mIsSysop = in_array( 'sysop', |
461 | | - $wgUser->getGroups()); |
| 460 | + $this->mIsSysop = in_array( 'sysop', $wgUser->getGroups()); |
462 | 461 | } |
463 | 462 | |
464 | 463 | return $this->mIsSysop; |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -330,6 +330,7 @@ |
331 | 331 | 'ApiQueryRevisions' => 'includes/api/ApiQueryRevisions.php', |
332 | 332 | 'ApiQuerySearch' => 'includes/api/ApiQuerySearch.php', |
333 | 333 | 'ApiQuerySiteinfo' => 'includes/api/ApiQuerySiteinfo.php', |
| 334 | + 'ApiQueryUserInfo' => 'includes/api/ApiQueryUserInfo.php', |
334 | 335 | 'ApiQueryWatchlist' => 'includes/api/ApiQueryWatchlist.php', |
335 | 336 | 'ApiResult' => 'includes/api/ApiResult.php', |
336 | 337 | ); |