Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 26 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
ApiQueryContentTranslationCorpora | |
0.00% |
0 / 26 |
|
0.00% |
0 / 3 |
12 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
getAllowedParams | |
0.00% |
0 / 16 |
|
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 | |
9 | namespace ContentTranslation\ActionApi; |
10 | |
11 | use ContentTranslation\Manager\TranslationCorporaManager; |
12 | use MediaWiki\Api\ApiQuery; |
13 | use MediaWiki\Api\ApiQueryBase; |
14 | use Wikimedia\ParamValidator\ParamValidator; |
15 | |
16 | /** |
17 | * Api module for querying Content Translation parallel corpora. |
18 | */ |
19 | class 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 | public function getAllowedParams() { |
45 | $params = [ |
46 | 'translationid' => [ |
47 | ParamValidator::PARAM_TYPE => 'integer', |
48 | ParamValidator::PARAM_REQUIRED => true, |
49 | ], |
50 | 'striphtml' => [ |
51 | ParamValidator::PARAM_TYPE => 'boolean', |
52 | ParamValidator::PARAM_DEFAULT => false, |
53 | ], |
54 | 'types' => [ |
55 | ParamValidator::PARAM_TYPE => [ 'source', 'mt', 'user' ], |
56 | ParamValidator::PARAM_DEFAULT => 'source|mt|user', |
57 | ParamValidator::PARAM_ISMULTI => true, |
58 | ], |
59 | ]; |
60 | |
61 | return $params; |
62 | } |
63 | } |