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