Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 44 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| ApiQueryPublishedTranslations | |
0.00% |
0 / 44 |
|
0.00% |
0 / 4 |
42 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| execute | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
12 | |||
| getAllowedParams | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
2 | |||
| getExamplesMessages | |
0.00% |
0 / 4 |
|
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\Store\TranslationStore; |
| 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 | public function __construct( |
| 21 | ApiQuery $query, |
| 22 | string $moduleName, |
| 23 | private readonly LanguageNameUtils $languageNameUtils, |
| 24 | private readonly TranslationStore $translationStore, |
| 25 | ) { |
| 26 | parent::__construct( $query, $moduleName ); |
| 27 | } |
| 28 | |
| 29 | public function execute() { |
| 30 | $params = $this->extractRequestParams(); |
| 31 | $result = $this->getResult(); |
| 32 | |
| 33 | $from = $params['from']; |
| 34 | $to = $params['to']; |
| 35 | |
| 36 | $limit = $params['limit']; |
| 37 | $offset = $params['offset']; |
| 38 | if ( !$this->languageNameUtils->isValidBuiltInCode( $from ) ) { |
| 39 | $this->dieWithError( 'apierror-cx-invalidlanguage', 'invalidlanguage' ); |
| 40 | } |
| 41 | if ( !$this->languageNameUtils->isValidBuiltInCode( $to ) ) { |
| 42 | $this->dieWithError( 'apierror-cx-invalidlanguage', 'invalidlanguage' ); |
| 43 | } |
| 44 | $translations = $this->translationStore->getAllPublishedTranslations( |
| 45 | $from, |
| 46 | $to, |
| 47 | $limit, |
| 48 | $offset |
| 49 | ); |
| 50 | |
| 51 | $result->addValue( [ 'result' ], 'translations', $translations ); |
| 52 | } |
| 53 | |
| 54 | /** @inheritDoc */ |
| 55 | public function getAllowedParams() { |
| 56 | return [ |
| 57 | 'from' => [ |
| 58 | ParamValidator::PARAM_TYPE => 'string', |
| 59 | ParamValidator::PARAM_REQUIRED => true, |
| 60 | ], |
| 61 | 'to' => [ |
| 62 | ParamValidator::PARAM_TYPE => 'string', |
| 63 | ParamValidator::PARAM_REQUIRED => true, |
| 64 | ], |
| 65 | 'limit' => [ |
| 66 | ParamValidator::PARAM_DEFAULT => 500, |
| 67 | ParamValidator::PARAM_TYPE => 'limit', |
| 68 | IntegerDef::PARAM_MIN => 1, |
| 69 | IntegerDef::PARAM_MAX => ApiBase::LIMIT_BIG1, |
| 70 | IntegerDef::PARAM_MAX2 => ApiBase::LIMIT_BIG2 |
| 71 | ], |
| 72 | 'offset' => [ |
| 73 | ParamValidator::PARAM_DEFAULT => 0, |
| 74 | ParamValidator::PARAM_TYPE => 'integer', |
| 75 | ApiBase::PARAM_HELP_MSG => 'api-help-param-continue', |
| 76 | ], |
| 77 | ]; |
| 78 | } |
| 79 | |
| 80 | /** @inheritDoc */ |
| 81 | protected function getExamplesMessages() { |
| 82 | return [ |
| 83 | 'action=query&list=cxpublishedtranslations&from=en&to=es' => |
| 84 | 'apihelp-query+cxpublishedtranslations-example-1', |
| 85 | ]; |
| 86 | } |
| 87 | } |