Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 35 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
QueryMessageGroupStatsActionApi | |
0.00% |
0 / 35 |
|
0.00% |
0 / 8 |
342 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
validateTargetParamater | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
loadStatistics | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
makeStatsItem | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
90 | |||
getCacheRebuildJob | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAllowedParams | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
getExamplesMessages | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | declare( strict_types = 1 ); |
3 | |
4 | namespace MediaWiki\Extension\Translate\Statistics; |
5 | |
6 | use IJobSpecification; |
7 | use JobQueueGroup; |
8 | use MediaWiki\Api\ApiQuery; |
9 | use MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups; |
10 | use Wikimedia\ParamValidator\ParamValidator; |
11 | |
12 | /** |
13 | * Api module for querying message group stats. |
14 | * @ingroup API TranslateAPI |
15 | * @author Tim Gerundt |
16 | * @author Niklas Laxström |
17 | * @copyright Copyright © 2012-2013, Tim Gerundt |
18 | * @license GPL-2.0-or-later |
19 | */ |
20 | class QueryMessageGroupStatsActionApi extends QueryStatsActionApi { |
21 | /** Whether to hide rows which are fully translated. */ |
22 | private bool $noComplete = false; |
23 | /** Whether to hide rows which are fully untranslated. */ |
24 | private bool $noEmpty = false; |
25 | |
26 | public function __construct( |
27 | ApiQuery $query, |
28 | string $moduleName, |
29 | JobQueueGroup $jobQueueGroup |
30 | ) { |
31 | parent::__construct( $query, $moduleName, 'mgs', $jobQueueGroup ); |
32 | } |
33 | |
34 | // ApiStatsQuery methods |
35 | |
36 | /** @inheritDoc */ |
37 | protected function validateTargetParamater( array $params ): string { |
38 | $group = MessageGroups::getGroup( $params['group'] ); |
39 | if ( !$group ) { |
40 | $this->dieWithError( [ 'apierror-badparameter', 'mgsgroup' ] ); |
41 | } elseif ( MessageGroups::isDynamic( $group ) ) { |
42 | $this->dieWithError( 'apierror-translate-nodynamicgroups', 'invalidparam' ); |
43 | } |
44 | |
45 | return $group->getId(); |
46 | } |
47 | |
48 | /** @inheritDoc */ |
49 | protected function loadStatistics( string $target, int $flags = 0 ): array { |
50 | return MessageGroupStats::forGroup( $target, $flags ); |
51 | } |
52 | |
53 | /** @inheritDoc */ |
54 | public function execute() { |
55 | $params = $this->extractRequestParams(); |
56 | |
57 | $this->noComplete = $params['suppresscomplete']; |
58 | $this->noEmpty = $params['suppressempty']; |
59 | |
60 | parent::execute(); |
61 | } |
62 | |
63 | /** @inheritDoc */ |
64 | protected function makeStatsItem( string $item, array $stats ): ?array { |
65 | $data = $this->makeItem( $stats ); |
66 | |
67 | if ( $this->noComplete && $data['fuzzy'] === 0 && $data['translated'] === $data['total'] ) { |
68 | return null; |
69 | } |
70 | |
71 | if ( $this->noEmpty && $data['translated'] === 0 && $data['fuzzy'] === 0 ) { |
72 | return null; |
73 | } |
74 | |
75 | // Skip below 2% if "don't show without translations" is checked. |
76 | if ( $this->noEmpty && ( $data['translated'] / $data['total'] ) < 0.02 ) { |
77 | return null; |
78 | } |
79 | |
80 | $data['code'] = $item; // For BC |
81 | $data['language'] = $item; |
82 | |
83 | return $data; |
84 | } |
85 | |
86 | /** @inheritDoc */ |
87 | protected function getCacheRebuildJob( string $target ): IJobSpecification { |
88 | return RebuildMessageGroupStatsJob::newJob( [ 'groupid' => $target ] ); |
89 | } |
90 | |
91 | // Api methods |
92 | |
93 | /** @inheritDoc */ |
94 | protected function getAllowedParams(): array { |
95 | $params = parent::getAllowedParams(); |
96 | $params['group'] = [ |
97 | ParamValidator::PARAM_TYPE => 'string', |
98 | ParamValidator::PARAM_REQUIRED => true, |
99 | ]; |
100 | |
101 | $params['suppresscomplete'] = false; |
102 | $params['suppressempty'] = false; |
103 | |
104 | return $params; |
105 | } |
106 | |
107 | /** @inheritDoc */ |
108 | protected function getExamplesMessages(): array { |
109 | return [ |
110 | 'action=query&meta=messagegroupstats&mgsgroup=page-Example' |
111 | => 'apihelp-query+messagegroupstats-example-1', |
112 | ]; |
113 | } |
114 | } |