API: Added list=allusers to allow enumeration of the registered users
authorYuri Astrakhan <yurik@users.mediawiki.org>
Sun, 8 Jul 2007 07:50:56 +0000 (07:50 +0000)
committerYuri Astrakhan <yurik@users.mediawiki.org>
Sun, 8 Jul 2007 07:50:56 +0000 (07:50 +0000)
RELEASE-NOTES
includes/AutoLoader.php
includes/api/ApiQuery.php
includes/api/ApiQueryAllLinks.php
includes/api/ApiQueryAllUsers.php [new file with mode: 0644]

index e50e2e5..f033109 100644 (file)
@@ -309,6 +309,7 @@ Full API documentation is available at http://www.mediawiki.org/wiki/API
 * (bug 10211) Added db server replication lag information in meta=siteinfo
 * Added external url search within wiki pages (list=exturlusage)
 * Added link enumeration (list=alllinks)
+* Added registered users enumeration (list=allusers)
 
 == Maintenance script changes since 1.10 ==
 
index ab86ab0..29ffb05 100644 (file)
@@ -307,6 +307,7 @@ function __autoload($className) {
                'ApiQuery' => 'includes/api/ApiQuery.php',
                'ApiQueryAllpages' => 'includes/api/ApiQueryAllpages.php',
                'ApiQueryAllLinks' => 'includes/api/ApiQueryAllLinks.php',
+               'ApiQueryAllUsers' => 'includes/api/ApiQueryAllUsers.php',
                'ApiQueryBase' => 'includes/api/ApiQueryBase.php',
                'ApiQueryGeneratorBase' => 'includes/api/ApiQueryBase.php',
                'ApiQueryBacklinks' => 'includes/api/ApiQueryBacklinks.php',
index 46dc8f0..9609861 100644 (file)
@@ -60,6 +60,7 @@ class ApiQuery extends ApiBase {
        private $mQueryListModules = array (
                'allpages' => 'ApiQueryAllpages',
                'alllinks' => 'ApiQueryAllLinks',
+               'allusers' => 'ApiQueryAllUsers',
                'backlinks' => 'ApiQueryBacklinks',
                'categorymembers' => 'ApiQueryCategoryMembers',
                'embeddedin' => 'ApiQueryBacklinks',
@@ -68,7 +69,6 @@ class ApiQuery extends ApiBase {
                'recentchanges' => 'ApiQueryRecentChanges',
                'usercontribs' => 'ApiQueryContributions',
                'watchlist' => 'ApiQueryWatchlist',
-       //      'users' => 'ApiQueryUsers',
                'exturlusage' => 'ApiQueryExtLinksUsage',
        );
 
index 55bc36e..e802108 100644 (file)
@@ -29,7 +29,7 @@ if (!defined('MEDIAWIKI')) {
 }
 
 /**
- * Query module to enumerate all available pages.
+ * Query module to enumerate links from all pages together.
  * 
  * @addtogroup API
  */
@@ -159,13 +159,14 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
                        'from' => 'The page title to start enumerating from.',
                        'prefix' => 'Search for all page titles that begin with this value.',
                        'unique' => 'Only show unique links. Cannot be used with generator or prop=ids',
+                       'prop' => 'What pieces of information to include',
                        'namespace' => 'The namespace to enumerate.',
                        'limit' => 'How many total links to return.'
                );
        }
 
        protected function getDescription() {
-               return 'Enumerate all pages sequentially in a given namespace';
+               return 'Enumerate all links that point to a given namespace';
        }
 
        protected function getExamples() {
diff --git a/includes/api/ApiQueryAllUsers.php b/includes/api/ApiQueryAllUsers.php
new file mode 100644 (file)
index 0000000..a9fcaf0
--- /dev/null
@@ -0,0 +1,130 @@
+<?php
+
+/*
+ * Created on July 7, 2007
+ *
+ * API for MediaWiki 1.8+
+ *
+ * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+if (!defined('MEDIAWIKI')) {
+       // Eclipse helper - will be ignored in production
+       require_once ('ApiQueryBase.php');
+}
+
+/**
+ * Query module to enumerate all registered users.
+ * 
+ * @addtogroup API
+ */
+class ApiQueryAllUsers extends ApiQueryBase {
+
+       public function __construct($query, $moduleName) {
+               parent :: __construct($query, $moduleName, 'au');
+       }
+
+       public function execute() {
+               $db = $this->getDB();
+               $params = $this->extractRequestParams();
+
+               $prop = $params['prop'];
+               if (!is_null($prop)) {
+                       $prop = array_flip($prop);
+                       $fld_editcount = isset($prop['editcount']);
+               } else {
+                       $fld_editcount = false;
+               }
+
+               $this->addTables('user');
+               
+               if (!is_null($params['from']))
+                       $this->addWhere('user_name>=' . $db->addQuotes(ApiQueryBase :: titleToKey($params['from'])));
+
+               $this->addFields('user_name');
+               $this->addFieldsIf('user_editcount', $fld_editcount);
+
+               $limit = $params['limit'];
+               $this->addOption('LIMIT', $limit+1);
+               $this->addOption('ORDER BY', 'user_name');
+
+               $res = $this->select(__METHOD__);
+
+               $data = array ();
+               $count = 0;
+               while ($row = $db->fetchObject($res)) {
+                       if (++ $count > $limit) {
+                               // We've reached the one extra which shows that there are additional pages to be had. Stop here...
+                               $this->setContinueEnumParameter('from', ApiQueryBase :: keyToTitle($row->user_name));
+                               break;
+                       }
+
+                       $vals = array( 'name' => $row->user_name );
+                       if ($fld_editcount) {
+                               $vals['editcount'] = intval($row->user_editcount);
+                       }
+                       $data[] = $vals;
+               }
+               $db->freeResult($res);
+
+               $result = $this->getResult();
+               $result->setIndexedTagName($data, 'u');
+               $result->addValue('query', $this->getModuleName(), $data);
+       }
+
+       protected function getAllowedParams() {
+               return array (
+                       'from' => null,
+                       'prop' => array (
+                               ApiBase :: PARAM_ISMULTI => true, 
+                               ApiBase :: PARAM_TYPE => array (
+                                       'editcount'
+                               )
+                       ),
+                       'limit' => array (
+                               ApiBase :: PARAM_DFLT => 10,
+                               ApiBase :: PARAM_TYPE => 'limit',
+                               ApiBase :: PARAM_MIN => 1,
+                               ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
+                               ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
+                       )
+               );
+       }
+
+       protected function getParamDescription() {
+               return array (
+                       'from' => 'The user name to start enumerating from.',
+                       'prop' => 'What pieces of information to include',
+                       'limit' => 'How many total user names to return.'
+               );
+       }
+
+       protected function getDescription() {
+               return 'Enumerate all registered users';
+       }
+
+       protected function getExamples() {
+               return array (
+                       'api.php?action=query&list=allusers&aufrom=Y',
+               );
+       }
+
+       public function getVersion() {
+               return __CLASS__ . ': $Id$';
+       }
+}