4 * Created on December 12, 2007
6 * API for MediaWiki 1.8+
8 * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
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 categories, even the ones that don't have
37 class ApiQueryAllCategories
extends ApiQueryGeneratorBase
{
39 public function __construct($query, $moduleName) {
40 parent
:: __construct($query, $moduleName, 'ac');
43 public function execute() {
47 public function executeGenerator($resultPageSet) {
48 $this->run($resultPageSet);
51 private function run($resultPageSet = null) {
54 $params = $this->extractRequestParams();
56 $this->addTables('categorylinks');
57 $this->addFields('cl_to');
59 if (!is_null($params['from']))
60 $this->addWhere('cl_to>=' . $db->addQuotes(ApiQueryBase
:: titleToKey($params['from'])));
61 if (isset ($params['prefix']))
62 $this->addWhere("cl_to LIKE '" . $db->escapeLike(ApiQueryBase
:: titleToKey($params['prefix'])) . "%'");
64 $this->addOption('LIMIT', $params['limit']+
1);
65 $this->addOption('ORDER BY', 'cl_to' . ($params['dir'] == 'ZtoA' ?
' DESC' : ''));
66 $this->addOption('DISTINCT');
68 $res = $this->select(__METHOD__
);
72 while ($row = $db->fetchObject($res)) {
73 if (++
$count > $params['limit']) {
74 // We've reached the one extra which shows that there are additional cats to be had. Stop here...
75 // TODO: Security issue - if the user has no right to view next title, it will still be shown
76 $this->setContinueEnumParameter('from', ApiQueryBase
:: keyToTitle($row->cl_to
));
81 if(!is_null($resultPageSet))
82 $titleObj = Title
::newFromText('Category:' . $row->cl_to
);
84 $titleObj = Title
::newFromText($row->cl_to
);
85 $pages[] = $titleObj->getPrefixedText();
87 $db->freeResult($res);
89 if (is_null($resultPageSet)) {
90 $result = $this->getResult();
91 $result->setIndexedTagName($pages, 'c');
92 $result->addValue('query', $this->getModuleName(), $pages);
94 $resultPageSet->populateFromTitles($pages);
98 protected function getAllowedParams() {
103 ApiBase
:: PARAM_DFLT
=> 'AtoZ',
104 ApiBase
:: PARAM_TYPE
=> array(
110 ApiBase
:: PARAM_DFLT
=> 10,
111 ApiBase
:: PARAM_TYPE
=> 'limit',
112 ApiBase
:: PARAM_MIN
=> 1,
113 ApiBase
:: PARAM_MAX
=> ApiBase
:: LIMIT_BIG1
,
114 ApiBase
:: PARAM_MAX2
=> ApiBase
:: LIMIT_BIG2
119 protected function getParamDescription() {
121 'from' => 'The category to start enumerating from.',
122 'prefix' => 'Search for all category titles that begin with this value.',
123 'dir' => 'Direction to sort in.',
124 'limit' => 'How many categories to return.'
128 protected function getDescription() {
129 return 'Enumerate all categories';
132 protected function getExamples() {
134 'api.php?action=query&generator=allcategories&gacprefix=List&prop=info',
138 public function getVersion() {
139 return __CLASS__
. ': $Id: ApiQueryAllLinks.php 28216 2007-12-06 18:33:18Z vasilievvv $';