4 * Created on July 7, 2007
6 * API for MediaWiki 1.8+
8 * Copyright (C) 2006 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');
32 * Query module to enumerate all registered users.
36 class ApiQueryAllUsers
extends ApiQueryBase
{
38 public function __construct($query, $moduleName) {
39 parent
:: __construct($query, $moduleName, 'au');
42 public function execute() {
44 $params = $this->extractRequestParams();
46 $prop = $params['prop'];
47 if (!is_null($prop)) {
48 $prop = array_flip($prop);
49 $fld_editcount = isset($prop['editcount']);
51 $fld_editcount = false;
54 $this->addTables('user');
56 if (!is_null($params['from']))
57 $this->addWhere('user_name>=' . $db->addQuotes(ApiQueryBase
:: titleToKey($params['from'])));
59 $this->addFields('user_name');
60 $this->addFieldsIf('user_editcount', $fld_editcount);
62 $limit = $params['limit'];
63 $this->addOption('LIMIT', $limit+
1);
64 $this->addOption('ORDER BY', 'user_name');
66 $res = $this->select(__METHOD__
);
70 while ($row = $db->fetchObject($res)) {
71 if (++
$count > $limit) {
72 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
73 $this->setContinueEnumParameter('from', ApiQueryBase
:: keyToTitle($row->user_name
));
77 $vals = array( 'name' => $row->user_name
);
79 $vals['editcount'] = intval($row->user_editcount
);
83 $db->freeResult($res);
85 $result = $this->getResult();
86 $result->setIndexedTagName($data, 'u');
87 $result->addValue('query', $this->getModuleName(), $data);
90 protected function getAllowedParams() {
94 ApiBase
:: PARAM_ISMULTI
=> true,
95 ApiBase
:: PARAM_TYPE
=> array (
100 ApiBase
:: PARAM_DFLT
=> 10,
101 ApiBase
:: PARAM_TYPE
=> 'limit',
102 ApiBase
:: PARAM_MIN
=> 1,
103 ApiBase
:: PARAM_MAX
=> ApiBase
:: LIMIT_BIG1
,
104 ApiBase
:: PARAM_MAX2
=> ApiBase
:: LIMIT_BIG2
109 protected function getParamDescription() {
111 'from' => 'The user name to start enumerating from.',
112 'prop' => 'What pieces of information to include',
113 'limit' => 'How many total user names to return.'
117 protected function getDescription() {
118 return 'Enumerate all registered users';
121 protected function getExamples() {
123 'api.php?action=query&list=allusers&aufrom=Y',
127 public function getVersion() {
128 return __CLASS__
. ': $Id$';