Implement extension registration from an extension.json file
[mediawiki.git] / includes / api / ApiQueryCategoryInfo.php
blob5c67ebf279aa49bfda90243c2cece0bd452dfdc3
1 <?php
2 /**
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
24 * @file
27 /**
28 * This query adds the "<categories>" subelement to all pages with the list of
29 * categories the page is in.
31 * @ingroup API
33 class ApiQueryCategoryInfo extends ApiQueryBase {
35 public function __construct( ApiQuery $query, $moduleName ) {
36 parent::__construct( $query, $moduleName, 'ci' );
39 public function execute() {
40 $params = $this->extractRequestParams();
41 $alltitles = $this->getPageSet()->getGoodAndMissingTitlesByNamespace();
42 if ( empty( $alltitles[NS_CATEGORY] ) ) {
43 return;
45 $categories = $alltitles[NS_CATEGORY];
47 $titles = $this->getPageSet()->getGoodAndMissingTitles();
48 $cattitles = array();
49 foreach ( $categories as $c ) {
50 /** @var $t Title */
51 $t = $titles[$c];
52 $cattitles[$c] = $t->getDBkey();
55 $this->addTables( array( 'category', 'page', 'page_props' ) );
56 $this->addJoinConds( array(
57 'page' => array( 'LEFT JOIN', array(
58 'page_namespace' => NS_CATEGORY,
59 'page_title=cat_title' ) ),
60 'page_props' => array( 'LEFT JOIN', array(
61 'pp_page=page_id',
62 'pp_propname' => 'hiddencat' ) ),
63 ) );
65 $this->addFields( array(
66 'cat_title',
67 'cat_pages',
68 'cat_subcats',
69 'cat_files',
70 'cat_hidden' => 'pp_propname'
71 ) );
72 $this->addWhere( array( 'cat_title' => $cattitles ) );
74 if ( !is_null( $params['continue'] ) ) {
75 $title = $this->getDB()->addQuotes( $params['continue'] );
76 $this->addWhere( "cat_title >= $title" );
78 $this->addOption( 'ORDER BY', 'cat_title' );
80 $res = $this->select( __METHOD__ );
82 $catids = array_flip( $cattitles );
83 foreach ( $res as $row ) {
84 $vals = array();
85 $vals['size'] = intval( $row->cat_pages );
86 $vals['pages'] = $row->cat_pages - $row->cat_subcats - $row->cat_files;
87 $vals['files'] = intval( $row->cat_files );
88 $vals['subcats'] = intval( $row->cat_subcats );
89 if ( $row->cat_hidden ) {
90 $vals['hidden'] = '';
92 $fit = $this->addPageSubItems( $catids[$row->cat_title], $vals );
93 if ( !$fit ) {
94 $this->setContinueEnumParameter( 'continue', $row->cat_title );
95 break;
100 public function getCacheMode( $params ) {
101 return 'public';
104 public function getAllowedParams() {
105 return array(
106 'continue' => array(
107 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
112 protected function getExamplesMessages() {
113 return array(
114 'action=query&prop=categoryinfo&titles=Category:Foo|Category:Bar'
115 => 'apihelp-query+categoryinfo-example-simple',
119 public function getHelpUrls() {
120 return 'https://www.mediawiki.org/wiki/API:Properties#categoryinfo_.2F_ci';