From 70970c90b2c2933a682e39c8152b26d617fc4cc6 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sun, 8 Jul 2007 07:50:56 +0000 Subject: [PATCH] API: Added list=allusers to allow enumeration of the registered users --- RELEASE-NOTES | 1 + includes/AutoLoader.php | 1 + includes/api/ApiQuery.php | 2 +- includes/api/ApiQueryAllLinks.php | 5 +- includes/api/ApiQueryAllUsers.php | 130 ++++++++++++++++++++++++++++++ 5 files changed, 136 insertions(+), 3 deletions(-) create mode 100644 includes/api/ApiQueryAllUsers.php diff --git a/RELEASE-NOTES b/RELEASE-NOTES index e50e2e5042..f03310997a 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 == diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index ab86ab0915..29ffb052d4 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -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', diff --git a/includes/api/ApiQuery.php b/includes/api/ApiQuery.php index 46dc8f0ff1..9609861bab 100644 --- a/includes/api/ApiQuery.php +++ b/includes/api/ApiQuery.php @@ -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', ); diff --git a/includes/api/ApiQueryAllLinks.php b/includes/api/ApiQueryAllLinks.php index 55bc36e4bb..e802108d45 100644 --- a/includes/api/ApiQueryAllLinks.php +++ b/includes/api/ApiQueryAllLinks.php @@ -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 index 0000000000..a9fcaf0c25 --- /dev/null +++ b/includes/api/ApiQueryAllUsers.php @@ -0,0 +1,130 @@ +@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$'; + } +} -- 2.20.1