Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 25
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 / 25
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 / 1
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    public function __construct(
21        ApiQuery $queryModule,
22        string $moduleName,
23        private readonly TranslationCorporaManager $corporaManager
24    ) {
25        parent::__construct( $queryModule, $moduleName );
26    }
27
28    public function execute() {
29        $params = $this->extractRequestParams();
30        $result = $this->getResult();
31
32        $sections = $this->corporaManager->getFilteredCorporaUnits(
33            (int)$params['translationid'],
34            $params['types'],
35            $params['striphtml']
36        );
37        $result->addValue( [ 'query', $this->getModuleName() ], 'sections', $sections );
38    }
39
40    /** @inheritDoc */
41    public function getAllowedParams() {
42        $params = [
43            'translationid' => [
44                ParamValidator::PARAM_TYPE => 'integer',
45                ParamValidator::PARAM_REQUIRED => true,
46            ],
47            'striphtml' => [
48                ParamValidator::PARAM_TYPE => 'boolean',
49                ParamValidator::PARAM_DEFAULT => false,
50            ],
51            'types' => [
52                ParamValidator::PARAM_TYPE => [ 'source', 'mt', 'user' ],
53                ParamValidator::PARAM_DEFAULT => 'source|mt|user',
54                ParamValidator::PARAM_ISMULTI => true,
55            ],
56        ];
57
58        return $params;
59    }
60}