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