3 * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 * This query adds the "<categories>" subelement to all pages with the list of
25 * categories the page is in.
29 class ApiQueryCategoryInfo
extends ApiQueryBase
{
31 public function __construct( ApiQuery
$query, $moduleName ) {
32 parent
::__construct( $query, $moduleName, 'ci' );
35 public function execute() {
36 $params = $this->extractRequestParams();
37 $alltitles = $this->getPageSet()->getGoodAndMissingTitlesByNamespace();
38 if ( empty( $alltitles[NS_CATEGORY
] ) ) {
41 $categories = $alltitles[NS_CATEGORY
];
43 $titles = $this->getPageSet()->getGoodAndMissingTitles();
45 foreach ( $categories as $c ) {
48 $cattitles[$c] = $t->getDBkey();
51 $this->addTables( [ 'category', 'page', 'page_props' ] );
52 $this->addJoinConds( [
53 'page' => [ 'LEFT JOIN', [
54 'page_namespace' => NS_CATEGORY
,
55 'page_title=cat_title' ] ],
56 'page_props' => [ 'LEFT JOIN', [
58 'pp_propname' => 'hiddencat' ] ],
66 'cat_hidden' => 'pp_propname'
68 $this->addWhere( [ 'cat_title' => $cattitles ] );
70 if ( !is_null( $params['continue'] ) ) {
71 $title = $this->getDB()->addQuotes( $params['continue'] );
72 $this->addWhere( "cat_title >= $title" );
74 $this->addOption( 'ORDER BY', 'cat_title' );
76 $res = $this->select( __METHOD__
);
78 $catids = array_flip( $cattitles );
79 foreach ( $res as $row ) {
81 $vals['size'] = (int)$row->cat_pages
;
82 $vals['pages'] = $row->cat_pages
- $row->cat_subcats
- $row->cat_files
;
83 $vals['files'] = (int)$row->cat_files
;
84 $vals['subcats'] = (int)$row->cat_subcats
;
85 $vals['hidden'] = (bool)$row->cat_hidden
;
86 $fit = $this->addPageSubItems( $catids[$row->cat_title
], $vals );
88 $this->setContinueEnumParameter( 'continue', $row->cat_title
);
94 public function getCacheMode( $params ) {
98 public function getAllowedParams() {
101 ApiBase
::PARAM_HELP_MSG
=> 'api-help-param-continue',
106 protected function getExamplesMessages() {
108 'action=query&prop=categoryinfo&titles=Category:Foo|Category:Bar'
109 => 'apihelp-query+categoryinfo-example-simple',
113 public function getHelpUrls() {
114 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Categoryinfo';