Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 55 |
|
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 | use MediaWiki\Title\Title; |
24 | |
25 | /** |
26 | * This query adds the "<categories>" subelement to all pages with the list of |
27 | * categories the page is in. |
28 | * |
29 | * @ingroup API |
30 | */ |
31 | class ApiQueryCategoryInfo extends ApiQueryBase { |
32 | |
33 | public function __construct( ApiQuery $query, $moduleName ) { |
34 | parent::__construct( $query, $moduleName, 'ci' ); |
35 | } |
36 | |
37 | public function execute() { |
38 | $params = $this->extractRequestParams(); |
39 | $alltitles = $this->getPageSet()->getGoodAndMissingTitlesByNamespace(); |
40 | if ( empty( $alltitles[NS_CATEGORY] ) ) { |
41 | return; |
42 | } |
43 | $categories = $alltitles[NS_CATEGORY]; |
44 | |
45 | $titles = $this->getPageSet()->getGoodAndMissingPages(); |
46 | $cattitles = []; |
47 | foreach ( $categories as $c ) { |
48 | /** @var Title $t */ |
49 | $t = $titles[$c]; |
50 | $cattitles[$c] = $t->getDBkey(); |
51 | } |
52 | |
53 | $this->addTables( [ 'category', 'page', 'page_props' ] ); |
54 | $this->addJoinConds( [ |
55 | 'page' => [ 'LEFT JOIN', [ |
56 | 'page_namespace' => NS_CATEGORY, |
57 | 'page_title=cat_title' ] ], |
58 | 'page_props' => [ 'LEFT JOIN', [ |
59 | 'pp_page=page_id', |
60 | 'pp_propname' => 'hiddencat' ] ], |
61 | ] ); |
62 | |
63 | $this->addFields( [ |
64 | 'cat_title', |
65 | 'cat_pages', |
66 | 'cat_subcats', |
67 | 'cat_files', |
68 | 'cat_hidden' => 'pp_propname' |
69 | ] ); |
70 | $this->addWhere( [ 'cat_title' => $cattitles ] ); |
71 | |
72 | if ( $params['continue'] !== null ) { |
73 | $this->addWhere( $this->getDB()->expr( 'cat_title', '>=', $params['continue'] ) ); |
74 | } |
75 | $this->addOption( 'ORDER BY', 'cat_title' ); |
76 | |
77 | $res = $this->select( __METHOD__ ); |
78 | |
79 | $catids = array_flip( $cattitles ); |
80 | foreach ( $res as $row ) { |
81 | $vals = []; |
82 | $vals['size'] = (int)$row->cat_pages; |
83 | $vals['pages'] = $row->cat_pages - $row->cat_subcats - $row->cat_files; |
84 | $vals['files'] = (int)$row->cat_files; |
85 | $vals['subcats'] = (int)$row->cat_subcats; |
86 | $vals['hidden'] = (bool)$row->cat_hidden; |
87 | $fit = $this->addPageSubItems( $catids[$row->cat_title], $vals ); |
88 | if ( !$fit ) { |
89 | $this->setContinueEnumParameter( 'continue', $row->cat_title ); |
90 | break; |
91 | } |
92 | } |
93 | } |
94 | |
95 | public function getCacheMode( $params ) { |
96 | return 'public'; |
97 | } |
98 | |
99 | public function getAllowedParams() { |
100 | return [ |
101 | 'continue' => [ |
102 | ApiBase::PARAM_HELP_MSG => 'api-help-param-continue', |
103 | ], |
104 | ]; |
105 | } |
106 | |
107 | protected function getExamplesMessages() { |
108 | return [ |
109 | 'action=query&prop=categoryinfo&titles=Category:Foo|Category:Bar' |
110 | => 'apihelp-query+categoryinfo-example-simple', |
111 | ]; |
112 | } |
113 | |
114 | public function getHelpUrls() { |
115 | return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Categoryinfo'; |
116 | } |
117 | } |