5 * Created on May 13, 2007
7 * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
28 * This query adds the "<categories>" subelement to all pages with the list of
29 * categories the page is in.
33 class ApiQueryCategoryInfo
extends ApiQueryBase
{
35 public function __construct( $query, $moduleName ) {
36 parent
::__construct( $query, $moduleName, 'ci' );
39 public function execute() {
40 $params = $this->extractRequestParams();
41 $alltitles = $this->getPageSet()->getAllTitlesByNamespace();
42 if ( empty( $alltitles[NS_CATEGORY
] ) ) {
45 $categories = $alltitles[NS_CATEGORY
];
47 $titles = $this->getPageSet()->getGoodTitles() +
48 $this->getPageSet()->getMissingTitles();
50 foreach ( $categories as $c ) {
53 $cattitles[$c] = $t->getDBkey();
56 $this->addTables( array( 'category', 'page', 'page_props' ) );
57 $this->addJoinConds( array(
58 'page' => array( 'LEFT JOIN', array(
59 'page_namespace' => NS_CATEGORY
,
60 'page_title=cat_title' ) ),
61 'page_props' => array( 'LEFT JOIN', array(
63 'pp_propname' => 'hiddencat' ) ),
66 $this->addFields( array( 'cat_title', 'cat_pages', 'cat_subcats', 'cat_files', 'cat_hidden' => 'pp_propname' ) );
67 $this->addWhere( array( 'cat_title' => $cattitles ) );
69 if ( !is_null( $params['continue'] ) ) {
70 $title = $this->getDB()->addQuotes( $params['continue'] );
71 $this->addWhere( "cat_title >= $title" );
73 $this->addOption( 'ORDER BY', 'cat_title' );
75 $res = $this->select( __METHOD__
);
77 $catids = array_flip( $cattitles );
78 foreach ( $res as $row ) {
80 $vals['size'] = intval( $row->cat_pages
);
81 $vals['pages'] = $row->cat_pages
- $row->cat_subcats
- $row->cat_files
;
82 $vals['files'] = intval( $row->cat_files
);
83 $vals['subcats'] = intval( $row->cat_subcats
);
84 if ( $row->cat_hidden
) {
87 $fit = $this->addPageSubItems( $catids[$row->cat_title
], $vals );
89 $this->setContinueEnumParameter( 'continue', $row->cat_title
);
95 public function getCacheMode( $params ) {
99 public function getAllowedParams() {
105 public function getParamDescription() {
107 'continue' => 'When more results are available, use this to continue',
111 public function getResultProperties() {
113 ApiBase
::PROP_LIST
=> false,
116 ApiBase
::PROP_TYPE
=> 'integer',
117 ApiBase
::PROP_NULLABLE
=> false
120 ApiBase
::PROP_TYPE
=> 'integer',
121 ApiBase
::PROP_NULLABLE
=> false
124 ApiBase
::PROP_TYPE
=> 'integer',
125 ApiBase
::PROP_NULLABLE
=> false
128 ApiBase
::PROP_TYPE
=> 'integer',
129 ApiBase
::PROP_NULLABLE
=> false
132 ApiBase
::PROP_TYPE
=> 'boolean',
133 ApiBase
::PROP_NULLABLE
=> false
139 public function getDescription() {
140 return 'Returns information about the given categories';
143 public function getExamples() {
144 return 'api.php?action=query&prop=categoryinfo&titles=Category:Foo|Category:Bar';
147 public function getHelpUrls() {
148 return 'https://www.mediawiki.org/wiki/API:Properties#categoryinfo_.2F_ci';