Use 'email' instead of 'e-mail' in API texts.
[lhc/web/wiklou.git] / includes / api / ApiQueryCategoryInfo.php
1 <?php
2 /**
3 *
4 *
5 * Created on May 13, 2007
6 *
7 * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
8 *
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.
13 *
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.
18 *
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
23 *
24 * @file
25 */
26
27 /**
28 * This query adds the "<categories>" subelement to all pages with the list of
29 * categories the page is in.
30 *
31 * @ingroup API
32 */
33 class ApiQueryCategoryInfo extends ApiQueryBase {
34
35 public function __construct( $query, $moduleName ) {
36 parent::__construct( $query, $moduleName, 'ci' );
37 }
38
39 public function execute() {
40 $params = $this->extractRequestParams();
41 $alltitles = $this->getPageSet()->getAllTitlesByNamespace();
42 if ( empty( $alltitles[NS_CATEGORY] ) ) {
43 return;
44 }
45 $categories = $alltitles[NS_CATEGORY];
46
47 $titles = $this->getPageSet()->getGoodTitles() +
48 $this->getPageSet()->getMissingTitles();
49 $cattitles = array();
50 foreach ( $categories as $c ) {
51 $t = $titles[$c];
52 $cattitles[$c] = $t->getDBkey();
53 }
54
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 ) );
64
65 $this->addFields( array( 'cat_title', 'cat_pages', 'cat_subcats', 'cat_files', 'cat_hidden' => 'pp_propname' ) );
66 $this->addWhere( array( 'cat_title' => $cattitles ) );
67
68 if ( !is_null( $params['continue'] ) ) {
69 $title = $this->getDB()->addQuotes( $params['continue'] );
70 $this->addWhere( "cat_title >= $title" );
71 }
72 $this->addOption( 'ORDER BY', 'cat_title' );
73
74 $res = $this->select( __METHOD__ );
75
76 $catids = array_flip( $cattitles );
77 foreach ( $res as $row ) {
78 $vals = array();
79 $vals['size'] = intval( $row->cat_pages );
80 $vals['pages'] = $row->cat_pages - $row->cat_subcats - $row->cat_files;
81 $vals['files'] = intval( $row->cat_files );
82 $vals['subcats'] = intval( $row->cat_subcats );
83 if ( $row->cat_hidden ) {
84 $vals['hidden'] = '';
85 }
86 $fit = $this->addPageSubItems( $catids[$row->cat_title], $vals );
87 if ( !$fit ) {
88 $this->setContinueEnumParameter( 'continue', $row->cat_title );
89 break;
90 }
91 }
92 }
93
94 public function getCacheMode( $params ) {
95 return 'public';
96 }
97
98 public function getAllowedParams() {
99 return array(
100 'continue' => null,
101 );
102 }
103
104 public function getParamDescription() {
105 return array(
106 'continue' => 'When more results are available, use this to continue',
107 );
108 }
109
110 public function getResultProperties() {
111 return array(
112 ApiBase::PROP_LIST => false,
113 '' => array(
114 'size' => array(
115 ApiBase::PROP_TYPE => 'integer',
116 ApiBase::PROP_NULLABLE => false
117 ),
118 'pages' => array(
119 ApiBase::PROP_TYPE => 'integer',
120 ApiBase::PROP_NULLABLE => false
121 ),
122 'files' => array(
123 ApiBase::PROP_TYPE => 'integer',
124 ApiBase::PROP_NULLABLE => false
125 ),
126 'subcats' => array(
127 ApiBase::PROP_TYPE => 'integer',
128 ApiBase::PROP_NULLABLE => false
129 ),
130 'hidden' => array(
131 ApiBase::PROP_TYPE => 'boolean',
132 ApiBase::PROP_NULLABLE => false
133 )
134 )
135 );
136 }
137
138 public function getDescription() {
139 return 'Returns information about the given categories';
140 }
141
142 public function getExamples() {
143 return 'api.php?action=query&prop=categoryinfo&titles=Category:Foo|Category:Bar';
144 }
145
146 public function getHelpUrls() {
147 return 'https://www.mediawiki.org/wiki/API:Properties#categoryinfo_.2F_ci';
148 }
149 }