a9fcaf0c25c8d2393edfdf2a1b841822114f8c7f
[lhc/web/wiklou.git] / includes / api / ApiQueryAllUsers.php
1 <?php
2
3 /*
4 * Created on July 7, 2007
5 *
6 * API for MediaWiki 1.8+
7 *
8 * Copyright (C) 2006 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 enumerate all registered users.
33 *
34 * @addtogroup API
35 */
36 class ApiQueryAllUsers extends ApiQueryBase {
37
38 public function __construct($query, $moduleName) {
39 parent :: __construct($query, $moduleName, 'au');
40 }
41
42 public function execute() {
43 $db = $this->getDB();
44 $params = $this->extractRequestParams();
45
46 $prop = $params['prop'];
47 if (!is_null($prop)) {
48 $prop = array_flip($prop);
49 $fld_editcount = isset($prop['editcount']);
50 } else {
51 $fld_editcount = false;
52 }
53
54 $this->addTables('user');
55
56 if (!is_null($params['from']))
57 $this->addWhere('user_name>=' . $db->addQuotes(ApiQueryBase :: titleToKey($params['from'])));
58
59 $this->addFields('user_name');
60 $this->addFieldsIf('user_editcount', $fld_editcount);
61
62 $limit = $params['limit'];
63 $this->addOption('LIMIT', $limit+1);
64 $this->addOption('ORDER BY', 'user_name');
65
66 $res = $this->select(__METHOD__);
67
68 $data = array ();
69 $count = 0;
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));
74 break;
75 }
76
77 $vals = array( 'name' => $row->user_name );
78 if ($fld_editcount) {
79 $vals['editcount'] = intval($row->user_editcount);
80 }
81 $data[] = $vals;
82 }
83 $db->freeResult($res);
84
85 $result = $this->getResult();
86 $result->setIndexedTagName($data, 'u');
87 $result->addValue('query', $this->getModuleName(), $data);
88 }
89
90 protected function getAllowedParams() {
91 return array (
92 'from' => null,
93 'prop' => array (
94 ApiBase :: PARAM_ISMULTI => true,
95 ApiBase :: PARAM_TYPE => array (
96 'editcount'
97 )
98 ),
99 'limit' => 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
105 )
106 );
107 }
108
109 protected function getParamDescription() {
110 return array (
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.'
114 );
115 }
116
117 protected function getDescription() {
118 return 'Enumerate all registered users';
119 }
120
121 protected function getExamples() {
122 return array (
123 'api.php?action=query&list=allusers&aufrom=Y',
124 );
125 }
126
127 public function getVersion() {
128 return __CLASS__ . ': $Id$';
129 }
130 }