Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
QueryTranslationStatsActionApi.php
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\Statistics;
5
6use ApiBase;
7use ApiMain;
9use Wikimedia\ParamValidator\ParamValidator;
10use Wikimedia\ParamValidator\TypeDef\IntegerDef;
11
19class QueryTranslationStatsActionApi extends ApiBase {
21 private $dataProvider;
22
23 public function __construct( ApiMain $mainModule, $moduleName ) {
24 parent::__construct( $mainModule, $moduleName );
25 $this->dataProvider = Services::getInstance()->getTranslationStatsDataProvider();
26 }
27
28 public function execute() {
29 $params = $this->extractRequestParams();
30 $graphOpts = new TranslationStatsGraphOptions();
31 $graphOpts->bindArray( $params );
32
33 $language = $this->getLanguage();
34
35 [ $labels, $data ] = $this->dataProvider->getGraphData( $graphOpts, $language );
36 $output = [
37 'labels' => $labels,
38 'data' => $data
39 ];
40
41 $this->getResult()->addValue( null, $this->getModuleName(), $output );
42 }
43
44 protected function getAllowedParams() {
45 return [
46 'count' => [
47 ParamValidator::PARAM_TYPE => $this->dataProvider->getGraphTypes(),
48 ParamValidator::PARAM_REQUIRED => true,
49 ],
50 'days' => [
51 ParamValidator::PARAM_TYPE => 'integer',
52 ParamValidator::PARAM_REQUIRED => true,
53 ParamValidator::PARAM_DEFAULT => 30,
54 IntegerDef::PARAM_MIN => 1,
55 IntegerDef::PARAM_MAX => 10000,
56 ApiBase::PARAM_RANGE_ENFORCE => true
57 ],
58 'group' => [
59 ParamValidator::PARAM_TYPE => 'string',
60 ParamValidator::PARAM_ISMULTI => true
61 ],
62 'language' => [
63 ParamValidator::PARAM_TYPE => 'string',
64 ParamValidator::PARAM_ISMULTI => true
65 ],
66 'scale' => [
67 ParamValidator::PARAM_TYPE => TranslationStatsGraphOptions::VALID_SCALES,
68 ParamValidator::PARAM_DEFAULT => 'days'
69 ],
70 'start' => [
71 ParamValidator::PARAM_TYPE => 'timestamp'
72 ]
73 ];
74 }
75
76 protected function getExamplesMessages() {
77 return [
78 'action=translationstats&count=edits&days=30'
79 => 'apihelp-translationstats-example-1',
80 'action=translationstats&count=edits&days=30&language=en|fr'
81 => 'apihelp-translationstats-example-2'
82 ];
83 }
84}
Minimal service container.
Definition Services.php:40