r23861 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23860‎ | r23861 | r23862 >
Date:07:50, 8 July 2007
Author:yurik
Status:old
Tags:
Comment:
API: Added list=allusers to allow enumeration of the registered users
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQuery.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryAllLinks.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryAllUsers.php (added) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryAllLinks.php
@@ -29,7 +29,7 @@
3030 }
3131
3232 /**
33 - * Query module to enumerate all available pages.
 33+ * Query module to enumerate links from all pages together.
3434 *
3535 * @addtogroup API
3636 */
@@ -159,13 +159,14 @@
160160 'from' => 'The page title to start enumerating from.',
161161 'prefix' => 'Search for all page titles that begin with this value.',
162162 'unique' => 'Only show unique links. Cannot be used with generator or prop=ids',
 163+ 'prop' => 'What pieces of information to include',
163164 'namespace' => 'The namespace to enumerate.',
164165 'limit' => 'How many total links to return.'
165166 );
166167 }
167168
168169 protected function getDescription() {
169 - return 'Enumerate all pages sequentially in a given namespace';
 170+ return 'Enumerate all links that point to a given namespace';
170171 }
171172
172173 protected function getExamples() {
Index: trunk/phase3/includes/api/ApiQuery.php
@@ -60,6 +60,7 @@
6161 private $mQueryListModules = array (
6262 'allpages' => 'ApiQueryAllpages',
6363 'alllinks' => 'ApiQueryAllLinks',
 64+ 'allusers' => 'ApiQueryAllUsers',
6465 'backlinks' => 'ApiQueryBacklinks',
6566 'categorymembers' => 'ApiQueryCategoryMembers',
6667 'embeddedin' => 'ApiQueryBacklinks',
@@ -68,7 +69,6 @@
6970 'recentchanges' => 'ApiQueryRecentChanges',
7071 'usercontribs' => 'ApiQueryContributions',
7172 'watchlist' => 'ApiQueryWatchlist',
72 - // 'users' => 'ApiQueryUsers',
7373 'exturlusage' => 'ApiQueryExtLinksUsage',
7474 );
7575
Index: trunk/phase3/includes/api/ApiQueryAllUsers.php
@@ -0,0 +1,130 @@
 2+<?php
 3+
 4+/*
 5+ * Created on July 7, 2007
 6+ *
 7+ * API for MediaWiki 1.8+
 8+ *
 9+ * Copyright (C) 2006 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 enumerate all registered users.
 34+ *
 35+ * @addtogroup API
 36+ */
 37+class ApiQueryAllUsers extends ApiQueryBase {
 38+
 39+ public function __construct($query, $moduleName) {
 40+ parent :: __construct($query, $moduleName, 'au');
 41+ }
 42+
 43+ public function execute() {
 44+ $db = $this->getDB();
 45+ $params = $this->extractRequestParams();
 46+
 47+ $prop = $params['prop'];
 48+ if (!is_null($prop)) {
 49+ $prop = array_flip($prop);
 50+ $fld_editcount = isset($prop['editcount']);
 51+ } else {
 52+ $fld_editcount = false;
 53+ }
 54+
 55+ $this->addTables('user');
 56+
 57+ if (!is_null($params['from']))
 58+ $this->addWhere('user_name>=' . $db->addQuotes(ApiQueryBase :: titleToKey($params['from'])));
 59+
 60+ $this->addFields('user_name');
 61+ $this->addFieldsIf('user_editcount', $fld_editcount);
 62+
 63+ $limit = $params['limit'];
 64+ $this->addOption('LIMIT', $limit+1);
 65+ $this->addOption('ORDER BY', 'user_name');
 66+
 67+ $res = $this->select(__METHOD__);
 68+
 69+ $data = array ();
 70+ $count = 0;
 71+ while ($row = $db->fetchObject($res)) {
 72+ if (++ $count > $limit) {
 73+ // We've reached the one extra which shows that there are additional pages to be had. Stop here...
 74+ $this->setContinueEnumParameter('from', ApiQueryBase :: keyToTitle($row->user_name));
 75+ break;
 76+ }
 77+
 78+ $vals = array( 'name' => $row->user_name );
 79+ if ($fld_editcount) {
 80+ $vals['editcount'] = intval($row->user_editcount);
 81+ }
 82+ $data[] = $vals;
 83+ }
 84+ $db->freeResult($res);
 85+
 86+ $result = $this->getResult();
 87+ $result->setIndexedTagName($data, 'u');
 88+ $result->addValue('query', $this->getModuleName(), $data);
 89+ }
 90+
 91+ protected function getAllowedParams() {
 92+ return array (
 93+ 'from' => null,
 94+ 'prop' => array (
 95+ ApiBase :: PARAM_ISMULTI => true,
 96+ ApiBase :: PARAM_TYPE => array (
 97+ 'editcount'
 98+ )
 99+ ),
 100+ 'limit' => array (
 101+ ApiBase :: PARAM_DFLT => 10,
 102+ ApiBase :: PARAM_TYPE => 'limit',
 103+ ApiBase :: PARAM_MIN => 1,
 104+ ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
 105+ ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
 106+ )
 107+ );
 108+ }
 109+
 110+ protected function getParamDescription() {
 111+ return array (
 112+ 'from' => 'The user name to start enumerating from.',
 113+ 'prop' => 'What pieces of information to include',
 114+ 'limit' => 'How many total user names to return.'
 115+ );
 116+ }
 117+
 118+ protected function getDescription() {
 119+ return 'Enumerate all registered users';
 120+ }
 121+
 122+ protected function getExamples() {
 123+ return array (
 124+ 'api.php?action=query&list=allusers&aufrom=Y',
 125+ );
 126+ }
 127+
 128+ public function getVersion() {
 129+ return __CLASS__ . ': $Id$';
 130+ }
 131+}
Property changes on: trunk/phase3/includes/api/ApiQueryAllUsers.php
___________________________________________________________________
Added: svn:eol-style
1132 + native
Added: svn:keywords
2133 + Id
Index: trunk/phase3/includes/AutoLoader.php
@@ -307,6 +307,7 @@
308308 'ApiQuery' => 'includes/api/ApiQuery.php',
309309 'ApiQueryAllpages' => 'includes/api/ApiQueryAllpages.php',
310310 'ApiQueryAllLinks' => 'includes/api/ApiQueryAllLinks.php',
 311+ 'ApiQueryAllUsers' => 'includes/api/ApiQueryAllUsers.php',
311312 'ApiQueryBase' => 'includes/api/ApiQueryBase.php',
312313 'ApiQueryGeneratorBase' => 'includes/api/ApiQueryBase.php',
313314 'ApiQueryBacklinks' => 'includes/api/ApiQueryBacklinks.php',
Index: trunk/phase3/RELEASE-NOTES
@@ -309,6 +309,7 @@
310310 * (bug 10211) Added db server replication lag information in meta=siteinfo
311311 * Added external url search within wiki pages (list=exturlusage)
312312 * Added link enumeration (list=alllinks)
 313+* Added registered users enumeration (list=allusers)
313314
314315 == Maintenance script changes since 1.10 ==
315316

Follow-up revisions

RevisionCommit summaryAuthorDate
r23912Merged revisions 23662-23909 via svnmerge from...david18:11, 9 July 2007

Status & tagging log