Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 47 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
QueryTranslationStatsActionApi | |
0.00% |
0 / 47 |
|
0.00% |
0 / 4 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
getAllowedParams | |
0.00% |
0 / 29 |
|
0.00% |
0 / 1 |
2 | |||
getExamplesMessages | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | declare( strict_types = 1 ); |
3 | |
4 | namespace MediaWiki\Extension\Translate\Statistics; |
5 | |
6 | use ApiBase; |
7 | use ApiMain; |
8 | use Wikimedia\ParamValidator\ParamValidator; |
9 | use Wikimedia\ParamValidator\TypeDef\IntegerDef; |
10 | |
11 | /** |
12 | * Api module for querying translation statistics |
13 | * @ingroup API TranslateAPI |
14 | * @since 2020.09 |
15 | * @author Abijeet Patro |
16 | * @license GPL-2.0-or-later |
17 | */ |
18 | class QueryTranslationStatsActionApi extends ApiBase { |
19 | private TranslationStatsDataProvider $dataProvider; |
20 | |
21 | public function __construct( ApiMain $mainModule, $moduleName, TranslationStatsDataProvider $dataProvider ) { |
22 | parent::__construct( $mainModule, $moduleName ); |
23 | $this->dataProvider = $dataProvider; |
24 | } |
25 | |
26 | public function execute() { |
27 | $params = $this->extractRequestParams(); |
28 | $graphOpts = new TranslationStatsGraphOptions(); |
29 | $graphOpts->bindArray( $params ); |
30 | |
31 | $language = $this->getLanguage(); |
32 | |
33 | [ $labels, $data ] = $this->dataProvider->getGraphData( $graphOpts, $language ); |
34 | $output = [ |
35 | 'labels' => $labels, |
36 | 'data' => $data |
37 | ]; |
38 | |
39 | $this->getResult()->addValue( null, $this->getModuleName(), $output ); |
40 | } |
41 | |
42 | protected function getAllowedParams() { |
43 | return [ |
44 | 'count' => [ |
45 | ParamValidator::PARAM_TYPE => $this->dataProvider->getGraphTypes(), |
46 | ParamValidator::PARAM_REQUIRED => true, |
47 | ], |
48 | 'days' => [ |
49 | ParamValidator::PARAM_TYPE => 'integer', |
50 | ParamValidator::PARAM_REQUIRED => true, |
51 | ParamValidator::PARAM_DEFAULT => 30, |
52 | IntegerDef::PARAM_MIN => 1, |
53 | IntegerDef::PARAM_MAX => 10000, |
54 | ApiBase::PARAM_RANGE_ENFORCE => true |
55 | ], |
56 | 'group' => [ |
57 | ParamValidator::PARAM_TYPE => 'string', |
58 | ParamValidator::PARAM_ISMULTI => true |
59 | ], |
60 | 'language' => [ |
61 | ParamValidator::PARAM_TYPE => 'string', |
62 | ParamValidator::PARAM_ISMULTI => true |
63 | ], |
64 | 'scale' => [ |
65 | ParamValidator::PARAM_TYPE => TranslationStatsGraphOptions::VALID_SCALES, |
66 | ParamValidator::PARAM_DEFAULT => 'days' |
67 | ], |
68 | 'start' => [ |
69 | ParamValidator::PARAM_TYPE => 'timestamp' |
70 | ] |
71 | ]; |
72 | } |
73 | |
74 | protected function getExamplesMessages() { |
75 | return [ |
76 | 'action=translationstats&count=edits&days=30' |
77 | => 'apihelp-translationstats-example-1', |
78 | 'action=translationstats&count=edits&days=30&language=en|fr' |
79 | => 'apihelp-translationstats-example-2' |
80 | ]; |
81 | } |
82 | } |