Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 48 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
ApiQueryPublishedTranslations | |
0.00% |
0 / 48 |
|
0.00% |
0 / 4 |
110 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
56 | |||
getAllowedParams | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
2 | |||
getExamplesMessages | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Api module for querying published translations. |
4 | * |
5 | * @copyright See AUTHORS.txt |
6 | * @license GPL-2.0-or-later |
7 | */ |
8 | |
9 | namespace ContentTranslation\ActionApi; |
10 | |
11 | use ContentTranslation\Translation; |
12 | use MediaWiki\Api\ApiBase; |
13 | use MediaWiki\Api\ApiQuery; |
14 | use MediaWiki\Api\ApiQueryBase; |
15 | use MediaWiki\Languages\LanguageNameUtils; |
16 | use Wikimedia\ParamValidator\ParamValidator; |
17 | use Wikimedia\ParamValidator\TypeDef\IntegerDef; |
18 | |
19 | class ApiQueryPublishedTranslations extends ApiQueryBase { |
20 | |
21 | private LanguageNameUtils $languageNameUtils; |
22 | |
23 | public function __construct( |
24 | ApiQuery $query, |
25 | string $moduleName, |
26 | LanguageNameUtils $languageNameUtils |
27 | ) { |
28 | parent::__construct( $query, $moduleName ); |
29 | $this->languageNameUtils = $languageNameUtils; |
30 | } |
31 | |
32 | public function execute() { |
33 | $from = $to = null; |
34 | $params = $this->extractRequestParams(); |
35 | $result = $this->getResult(); |
36 | $user = $this->getUser(); |
37 | if ( isset( $params['from'] ) ) { |
38 | $from = $params['from']; |
39 | } |
40 | if ( isset( $params['to'] ) ) { |
41 | $to = $params['to']; |
42 | } |
43 | $limit = $params['limit']; |
44 | $offset = $params['offset']; |
45 | if ( $from !== null && !$this->languageNameUtils->isValidBuiltInCode( $from ) ) { |
46 | $this->dieWithError( 'apierror-cx-invalidlanguage', 'invalidlanguage' ); |
47 | } |
48 | if ( $to !== null && !$this->languageNameUtils->isValidBuiltInCode( $to ) ) { |
49 | $this->dieWithError( 'apierror-cx-invalidlanguage', 'invalidlanguage' ); |
50 | } |
51 | $translations = Translation::getAllPublishedTranslations( |
52 | $from, $to, $limit, $offset |
53 | ); |
54 | |
55 | $result->addValue( [ 'result' ], 'translations', $translations ); |
56 | } |
57 | |
58 | public function getAllowedParams() { |
59 | return [ |
60 | 'from' => [ |
61 | ParamValidator::PARAM_TYPE => 'string', |
62 | ], |
63 | 'to' => [ |
64 | ParamValidator::PARAM_TYPE => 'string', |
65 | ], |
66 | 'limit' => [ |
67 | ParamValidator::PARAM_DEFAULT => 500, |
68 | ParamValidator::PARAM_TYPE => 'limit', |
69 | IntegerDef::PARAM_MIN => 1, |
70 | IntegerDef::PARAM_MAX => ApiBase::LIMIT_BIG1, |
71 | IntegerDef::PARAM_MAX2 => ApiBase::LIMIT_BIG2 |
72 | ], |
73 | 'offset' => [ |
74 | ParamValidator::PARAM_DEFAULT => '', |
75 | ParamValidator::PARAM_TYPE => 'string', |
76 | ApiBase::PARAM_HELP_MSG => 'api-help-param-continue', |
77 | ], |
78 | ]; |
79 | } |
80 | |
81 | protected function getExamplesMessages() { |
82 | return [ |
83 | 'action=query&list=cxpublishedtranslations' => |
84 | 'apihelp-query+cxpublishedtranslations-example-1', |
85 | 'action=query&list=cxpublishedtranslations&from=en' => |
86 | 'apihelp-query+cxpublishedtranslations-example-2', |
87 | 'action=query&list=cxpublishedtranslations&from=en&to=es' => |
88 | 'apihelp-query+cxpublishedtranslations-example-3', |
89 | ]; |
90 | } |
91 | } |