r24494 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24493‎ | r24494 | r24495 >
Date:17:53, 31 July 2007
Author:yurik
Status:old
Tags:
Comment:
API: Added meta=userinfo module to get data about the currently logged-in user.
Modified paths:
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/api/ApiMain.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQuery.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQuerySiteinfo.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryUserInfo.php (added) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQuery.php
@@ -75,7 +75,7 @@
7676
7777 private $mQueryMetaModules = array (
7878 'siteinfo' => 'ApiQuerySiteinfo',
79 - // 'userinfo' => 'ApiQueryUserinfo',
 79+ 'userinfo' => 'ApiQueryUserInfo',
8080 );
8181
8282 private $mSlaveDB = null;
Index: trunk/phase3/includes/api/ApiQuerySiteinfo.php
@@ -99,6 +99,7 @@
100100
101101 protected function appendInterwikiMap($property, $filter) {
102102
 103+ $this->resetQueryParams();
103104 $this->addTables('interwiki');
104105 $this->addFields(array('iw_prefix', 'iw_local', 'iw_url'));
105106
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
1136 + native
Added: svn:keywords
2137 + Id
Index: trunk/phase3/includes/api/ApiMain.php
@@ -456,8 +456,7 @@
457457 public function isSysop() {
458458 if (!isset ($this->mIsSysop)) {
459459 global $wgUser;
460 - $this->mIsSysop = in_array( 'sysop',
461 - $wgUser->getGroups());
 460+ $this->mIsSysop = in_array( 'sysop', $wgUser->getGroups());
462461 }
463462
464463 return $this->mIsSysop;
Index: trunk/phase3/includes/AutoLoader.php
@@ -330,6 +330,7 @@
331331 'ApiQueryRevisions' => 'includes/api/ApiQueryRevisions.php',
332332 'ApiQuerySearch' => 'includes/api/ApiQuerySearch.php',
333333 'ApiQuerySiteinfo' => 'includes/api/ApiQuerySiteinfo.php',
 334+ 'ApiQueryUserInfo' => 'includes/api/ApiQueryUserInfo.php',
334335 'ApiQueryWatchlist' => 'includes/api/ApiQueryWatchlist.php',
335336 'ApiResult' => 'includes/api/ApiResult.php',
336337 );

Follow-up revisions

RevisionCommit summaryAuthorDate
r24631Merged revisions 24480-24600 via svnmerge from...david18:39, 6 August 2007

Status & tagging log