Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 45 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
ApiQueryProofreadInfo | |
0.00% |
0 / 45 |
|
0.00% |
0 / 8 |
132 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
appendNamespaces | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
appendQualityLevels | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
getQualityLevelCategory | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getCacheMode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAllowedParams | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
2 | |||
getExamplesMessages | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace ProofreadPage\Api; |
4 | |
5 | use ApiBase; |
6 | use ApiQueryBase; |
7 | use ProofreadPage\Context; |
8 | use Wikimedia\ParamValidator\ParamValidator; |
9 | |
10 | /** |
11 | * @license GPL-2.0-or-later |
12 | * |
13 | * A query action to return meta information about the proofread extension. |
14 | * |
15 | * Note: this used to have the prefix 'pi', which conflicted with PageImages |
16 | * (T290585), so it was changed to 'prpi'. |
17 | */ |
18 | class ApiQueryProofreadInfo extends ApiQueryBase { |
19 | |
20 | /** |
21 | * @param \ApiQuery $query |
22 | * @param string $moduleName |
23 | */ |
24 | public function __construct( $query, $moduleName ) { |
25 | parent::__construct( $query, $moduleName, 'prpi' ); |
26 | } |
27 | |
28 | /** |
29 | * @inheritDoc |
30 | */ |
31 | public function execute() { |
32 | $params = $this->extractRequestParams(); |
33 | |
34 | $prop = array_flip( $params['prop'] ); |
35 | |
36 | if ( isset( $prop['namespaces'] ) ) { |
37 | $this->appendNamespaces(); |
38 | } |
39 | |
40 | if ( isset( $prop['qualitylevels'] ) ) { |
41 | $this->appendQualityLevels(); |
42 | } |
43 | } |
44 | |
45 | protected function appendNamespaces() { |
46 | $context = Context::getDefaultContext(); |
47 | $data = [ |
48 | 'index' => [ |
49 | 'id' => $context->getIndexNamespaceId() |
50 | ], |
51 | 'page' => [ |
52 | 'id' => $context->getPageNamespaceId() |
53 | ] |
54 | ]; |
55 | return $this->getResult()->addValue( 'query', 'proofreadnamespaces', $data ); |
56 | } |
57 | |
58 | protected function appendQualityLevels() { |
59 | $data = []; |
60 | for ( $i = 0; $i < 5; $i++ ) { |
61 | $data[$i] = [ |
62 | 'id' => $i, |
63 | 'category' => $this->getQualityLevelCategory( $i ) |
64 | ]; |
65 | } |
66 | $this->getResult()->setIndexedTagName( $data, 'level' ); |
67 | return $this->getResult()->addValue( 'query', 'proofreadqualitylevels', $data ); |
68 | } |
69 | |
70 | /** |
71 | * Get the category name (in the wiki's content language, and without 'Category:' prefix) |
72 | * for a given quality level. |
73 | * @param int $level |
74 | * @return string |
75 | */ |
76 | private function getQualityLevelCategory( $level ) { |
77 | $messageName = "proofreadpage_quality{$level}_category"; |
78 | return $this->msg( $messageName )->inContentLanguage()->text(); |
79 | } |
80 | |
81 | /** |
82 | * @param array $params [optional] Parameters (unused parameter) |
83 | * @see ApiQueryBase::getCacheMode() |
84 | * @return string |
85 | */ |
86 | public function getCacheMode( $params ) { |
87 | return 'public'; |
88 | } |
89 | |
90 | /** |
91 | * Returns list of allowed parameters |
92 | * @see ApiBase::getAllowedParams() |
93 | * @return array |
94 | */ |
95 | public function getAllowedParams() { |
96 | return [ |
97 | 'prop' => [ |
98 | ParamValidator::PARAM_DEFAULT => 'namespaces|qualitylevels', |
99 | ParamValidator::PARAM_ISMULTI => true, |
100 | ParamValidator::PARAM_TYPE => [ |
101 | 'namespaces', |
102 | 'qualitylevels', |
103 | ], |
104 | ApiBase::PARAM_HELP_MSG_PER_VALUE => [], |
105 | ], |
106 | ]; |
107 | } |
108 | |
109 | /** |
110 | * @inheritDoc |
111 | */ |
112 | protected function getExamplesMessages() { |
113 | return [ |
114 | 'action=query&meta=proofreadinfo' |
115 | => 'apihelp-query+proofreadinfo-example-1', |
116 | 'action=query&meta=proofreadinfo&prpiprop=namespaces' |
117 | => 'apihelp-query+proofreadinfo-example-3', |
118 | ]; |
119 | } |
120 | } |