Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 57 |
|
0.00% |
0 / 9 |
CRAP | |
0.00% |
0 / 1 |
| ApiQueryTrackingCategories | |
0.00% |
0 / 57 |
|
0.00% |
0 / 9 |
210 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| execute | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getCacheMode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| executeGenerator | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| run | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
42 | |||
| createQuery | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| getAllowedParams | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
2 | |||
| getExamplesMessages | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| getHelpUrls | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Copyright © 2007 Roan Kattouw <roan.kattouw@gmail.com> |
| 4 | * |
| 5 | * @license GPL-2.0-or-later |
| 6 | * @file |
| 7 | */ |
| 8 | |
| 9 | namespace MediaWiki\Api; |
| 10 | |
| 11 | use MediaWiki\Category\TrackingCategories; |
| 12 | use Wikimedia\ParamValidator\ParamValidator; |
| 13 | use Wikimedia\ParamValidator\TypeDef\IntegerDef; |
| 14 | use Wikimedia\Rdbms\IReadableDatabase; |
| 15 | |
| 16 | /** |
| 17 | * Query module to enumerate existing tracking categories. A tracking category exists if it contains pages |
| 18 | * or if its category page exists. |
| 19 | * |
| 20 | * @ingroup API |
| 21 | */ |
| 22 | class ApiQueryTrackingCategories extends ApiQueryCategoryList { |
| 23 | private TrackingCategories $trackingCategoriesService; |
| 24 | |
| 25 | public function __construct( ApiQuery $query, string $moduleName, TrackingCategories $tc ) { |
| 26 | parent::__construct( $query, $moduleName, 'tc' ); |
| 27 | $this->trackingCategoriesService = $tc; |
| 28 | } |
| 29 | |
| 30 | public function execute() { |
| 31 | $this->run(); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * @param array $params |
| 36 | * @return string |
| 37 | */ |
| 38 | public function getCacheMode( $params ): string { |
| 39 | return 'public'; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * @param ApiPageSet $resultPageSet |
| 44 | * @return void |
| 45 | */ |
| 46 | public function executeGenerator( $resultPageSet ): void { |
| 47 | $this->run( $resultPageSet ); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * @param ApiPageSet|null $resultPageSet |
| 52 | */ |
| 53 | private function run( $resultPageSet = null ) { |
| 54 | $db = $this->getDB(); |
| 55 | $params = $this->extractRequestParams(); |
| 56 | |
| 57 | $this->createQuery( $db, $params ); |
| 58 | |
| 59 | $cats = $this->trackingCategoriesService->getTrackingCategories(); |
| 60 | $catNameList = []; |
| 61 | foreach ( $cats as $id => $cat ) { |
| 62 | if ( empty( $params['trackingcatname'] ) || in_array( $id, $params['trackingcatname'] ) ) { |
| 63 | foreach ( $cat['cats'] ?? [] as $link ) { |
| 64 | $catNameList[ $link->getDbkey() ] = $id; |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | if ( $catNameList === [] ) { |
| 69 | return; |
| 70 | } |
| 71 | $this->addWhereFld( 'cat_title', array_keys( $catNameList ) ); |
| 72 | $this->executeQuery( $params, $resultPageSet, [ 'catNames' => $catNameList ] ); |
| 73 | } |
| 74 | |
| 75 | protected function createQuery( IReadableDatabase $db, array $params ): void { |
| 76 | $params['from'] = null; |
| 77 | $params['to'] = null; |
| 78 | $params['prefix'] = null; |
| 79 | $params['dir'] = 'ascending'; |
| 80 | parent::createQuery( $db, $params ); |
| 81 | } |
| 82 | |
| 83 | public function getAllowedParams(): array { |
| 84 | return [ |
| 85 | 'continue' => [ |
| 86 | ApiBase::PARAM_HELP_MSG => 'api-help-param-continue', |
| 87 | ], |
| 88 | 'trackingcatname' => [ |
| 89 | ParamValidator::PARAM_ISMULTI => true, |
| 90 | ], |
| 91 | 'min' => [ |
| 92 | ParamValidator::PARAM_TYPE => 'integer' |
| 93 | ], |
| 94 | 'max' => [ |
| 95 | ParamValidator::PARAM_TYPE => 'integer' |
| 96 | ], |
| 97 | 'limit' => [ |
| 98 | ParamValidator::PARAM_DEFAULT => 10, |
| 99 | ParamValidator::PARAM_TYPE => 'limit', |
| 100 | IntegerDef::PARAM_MIN => 1, |
| 101 | IntegerDef::PARAM_MAX => ApiBase::LIMIT_BIG1, |
| 102 | IntegerDef::PARAM_MAX2 => ApiBase::LIMIT_BIG2 |
| 103 | ], |
| 104 | 'prop' => [ |
| 105 | ParamValidator::PARAM_TYPE => [ 'size', 'hidden' ], |
| 106 | ParamValidator::PARAM_DEFAULT => '', |
| 107 | ParamValidator::PARAM_ISMULTI => true, |
| 108 | ApiBase::PARAM_HELP_MSG_PER_VALUE => [], |
| 109 | ], |
| 110 | ]; |
| 111 | } |
| 112 | |
| 113 | protected function getExamplesMessages(): array { |
| 114 | return [ |
| 115 | 'action=query&list=trackingcategories&tcprop=size' |
| 116 | => 'apihelp-query+trackingcategories-example-size', |
| 117 | 'action=query&generator=trackingcategories>ctrackingcatname=broken-file-category&prop=info' |
| 118 | => 'apihelp-query+trackingcategories-example-generator', |
| 119 | ]; |
| 120 | } |
| 121 | |
| 122 | public function getHelpUrls(): string { |
| 123 | return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Trackingcategories'; |
| 124 | } |
| 125 | } |