Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 56 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
ApiQueryCategoryInfo | |
0.00% |
0 / 55 |
|
0.00% |
0 / 6 |
132 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 43 |
|
0.00% |
0 / 1 |
42 | |||
getCacheMode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAllowedParams | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
getExamplesMessages | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
getHelpUrls | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com" |
4 | * |
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. |
9 | * |
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. |
14 | * |
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 |
19 | * |
20 | * @file |
21 | */ |
22 | |
23 | namespace MediaWiki\Api; |
24 | |
25 | use MediaWiki\Title\Title; |
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( ApiQuery $query, string $moduleName ) { |
36 | parent::__construct( $query, $moduleName, 'ci' ); |
37 | } |
38 | |
39 | public function execute() { |
40 | $params = $this->extractRequestParams(); |
41 | $alltitles = $this->getPageSet()->getGoodAndMissingTitlesByNamespace(); |
42 | if ( empty( $alltitles[NS_CATEGORY] ) ) { |
43 | return; |
44 | } |
45 | $categories = $alltitles[NS_CATEGORY]; |
46 | |
47 | $titles = $this->getPageSet()->getGoodAndMissingPages(); |
48 | $cattitles = []; |
49 | foreach ( $categories as $c ) { |
50 | /** @var Title $t */ |
51 | $t = $titles[$c]; |
52 | $cattitles[$c] = $t->getDBkey(); |
53 | } |
54 | |
55 | $this->addTables( [ 'category', 'page', 'page_props' ] ); |
56 | $this->addJoinConds( [ |
57 | 'page' => [ 'LEFT JOIN', [ |
58 | 'page_namespace' => NS_CATEGORY, |
59 | 'page_title=cat_title' ] ], |
60 | 'page_props' => [ 'LEFT JOIN', [ |
61 | 'pp_page=page_id', |
62 | 'pp_propname' => 'hiddencat' ] ], |
63 | ] ); |
64 | |
65 | $this->addFields( [ |
66 | 'cat_title', |
67 | 'cat_pages', |
68 | 'cat_subcats', |
69 | 'cat_files', |
70 | 'cat_hidden' => 'pp_propname' |
71 | ] ); |
72 | $this->addWhere( [ 'cat_title' => $cattitles ] ); |
73 | |
74 | if ( $params['continue'] !== null ) { |
75 | $this->addWhere( $this->getDB()->expr( 'cat_title', '>=', $params['continue'] ) ); |
76 | } |
77 | $this->addOption( 'ORDER BY', 'cat_title' ); |
78 | |
79 | $res = $this->select( __METHOD__ ); |
80 | |
81 | $catids = array_flip( $cattitles ); |
82 | foreach ( $res as $row ) { |
83 | $vals = []; |
84 | $vals['size'] = (int)$row->cat_pages; |
85 | $vals['pages'] = $row->cat_pages - $row->cat_subcats - $row->cat_files; |
86 | $vals['files'] = (int)$row->cat_files; |
87 | $vals['subcats'] = (int)$row->cat_subcats; |
88 | $vals['hidden'] = (bool)$row->cat_hidden; |
89 | $fit = $this->addPageSubItems( $catids[$row->cat_title], $vals ); |
90 | if ( !$fit ) { |
91 | $this->setContinueEnumParameter( 'continue', $row->cat_title ); |
92 | break; |
93 | } |
94 | } |
95 | } |
96 | |
97 | public function getCacheMode( $params ) { |
98 | return 'public'; |
99 | } |
100 | |
101 | public function getAllowedParams() { |
102 | return [ |
103 | 'continue' => [ |
104 | ApiBase::PARAM_HELP_MSG => 'api-help-param-continue', |
105 | ], |
106 | ]; |
107 | } |
108 | |
109 | protected function getExamplesMessages() { |
110 | return [ |
111 | 'action=query&prop=categoryinfo&titles=Category:Foo|Category:Bar' |
112 | => 'apihelp-query+categoryinfo-example-simple', |
113 | ]; |
114 | } |
115 | |
116 | public function getHelpUrls() { |
117 | return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Categoryinfo'; |
118 | } |
119 | } |
120 | |
121 | /** @deprecated class alias since 1.43 */ |
122 | class_alias( ApiQueryCategoryInfo::class, 'ApiQueryCategoryInfo' ); |