Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 26
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
ApiQueryContentTranslationCorpora
0.00% covered (danger)
0.00%
0 / 26
0.00% covered (danger)
0.00%
0 / 3
12
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
 getAllowedParams
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * Api module for querying Content Translation parallel corpora.
4 *
5 * @copyright See AUTHORS.txt
6 * @license GPL-2.0-or-later
7 */
8
9namespace ContentTranslation\ActionApi;
10
11use ContentTranslation\Manager\TranslationCorporaManager;
12use MediaWiki\Api\ApiQuery;
13use MediaWiki\Api\ApiQueryBase;
14use Wikimedia\ParamValidator\ParamValidator;
15
16/**
17 * Api module for querying Content Translation parallel corpora.
18 */
19class ApiQueryContentTranslationCorpora extends ApiQueryBase {
20    private TranslationCorporaManager $corporaManager;
21
22    public function __construct(
23        ApiQuery $queryModule,
24        string $moduleName,
25        TranslationCorporaManager $corporaManager
26    ) {
27        parent::__construct( $queryModule, $moduleName );
28
29        $this->corporaManager = $corporaManager;
30    }
31
32    public function execute() {
33        $params = $this->extractRequestParams();
34        $result = $this->getResult();
35
36        $sections = $this->corporaManager->getFilteredCorporaUnits(
37            (int)$params['translationid'],
38            $params['types'],
39            $params['striphtml']
40        );
41        $result->addValue( [ 'query', $this->getModuleName() ], 'sections', $sections );
42    }
43
44    /** @inheritDoc */
45    public function getAllowedParams() {
46        $params = [
47            'translationid' => [
48                ParamValidator::PARAM_TYPE => 'integer',
49                ParamValidator::PARAM_REQUIRED => true,
50            ],
51            'striphtml' => [
52                ParamValidator::PARAM_TYPE => 'boolean',
53                ParamValidator::PARAM_DEFAULT => false,
54            ],
55            'types' => [
56                ParamValidator::PARAM_TYPE => [ 'source', 'mt', 'user' ],
57                ParamValidator::PARAM_DEFAULT => 'source|mt|user',
58                ParamValidator::PARAM_ISMULTI => true,
59            ],
60        ];
61
62        return $params;
63    }
64}