Localisation updates: Adding/updating Persian translations
[mediawiki.git] / includes / api / ApiQueryCategoryInfo.php
blobaae727985a10a39aac2ccdd676058c0f6f32f725
1 <?php
3 /*
4 * Created on May 13, 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");
31 /**
32 * This query adds <categories> subelement to all pages with the list of images embedded into those pages.
34 * @ingroup API
36 class ApiQueryCategoryInfo extends ApiQueryBase {
38 public function __construct($query, $moduleName) {
39 parent :: __construct($query, $moduleName, 'ci');
42 public function execute() {
43 $alltitles = $this->getPageSet()->getAllTitlesByNamespace();
44 $categories = $alltitles[NS_CATEGORY];
45 if(empty($categories))
46 return;
48 $titles = $this->getPageSet()->getGoodTitles() +
49 $this->getPageSet()->getMissingTitles();
50 $cattitles = array();
51 foreach($categories as $c)
53 $t = $titles[$c];
54 $cattitles[$c] = $t->getDbKey();
57 $this->addTables('category');
58 $this->addFields(array('cat_title', 'cat_pages', 'cat_subcats', 'cat_files', 'cat_hidden'));
59 $this->addWhere(array('cat_title' => $cattitles));
61 $db = $this->getDB();
62 $res = $this->select(__METHOD__);
64 $data = array();
65 $catids = array_flip($cattitles);
66 while($row = $db->fetchObject($res))
68 $vals = array();
69 $vals['size'] = $row->cat_pages;
70 $vals['pages'] = $row->cat_pages - $row->cat_subcats - $row->cat_files;
71 $vals['files'] = $row->cat_files;
72 $vals['subcats'] = $row->cat_subcats;
73 if($row->cat_hidden)
74 $vals['hidden'] = '';
75 $this->addPageSubItems($catids[$row->cat_title], $vals);
77 $db->freeResult($res);
80 public function getDescription() {
81 return 'Returns information about the given categories';
84 protected function getExamples() {
85 return "api.php?action=query&prop=categoryinfo&titles=Category:Foo|Category:Bar";
88 public function getVersion() {
89 return __CLASS__ . ': $Id$';