Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 27 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
ApiQueryProofread | |
0.00% |
0 / 27 |
|
0.00% |
0 / 5 |
90 | |
0.00% |
0 / 1 |
execute | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
20 | |||
getQualityLevelCategory | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
getCacheMode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAllowedParams | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getExamplesMessages | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace ProofreadPage\Api; |
4 | |
5 | use MediaWiki\Api\ApiQueryBase; |
6 | use ProofreadPage\Context; |
7 | |
8 | /** |
9 | * @license GPL-2.0-or-later |
10 | */ |
11 | class ApiQueryProofread extends ApiQueryBase { |
12 | /** @var string[] */ |
13 | private $qualityLevelCategoryCache = []; |
14 | |
15 | /** |
16 | * Executes query and formats data |
17 | */ |
18 | public function execute() { |
19 | $context = Context::getDefaultContext(); |
20 | $pages = $this->getPageSet()->getGoodPages(); |
21 | $result = $this->getResult(); |
22 | |
23 | $pageNamespaceId = $context->getPageNamespaceId(); |
24 | $pageQualityLevelLookup = $context->getPageQualityLevelLookup(); |
25 | $pageQualityLevelLookup->prefetchQualityLevelForTitles( $pages ); |
26 | |
27 | foreach ( $pages as $pageId => $title ) { |
28 | if ( $title->getNamespace() === $pageNamespaceId ) { |
29 | $pageQualityLevel = $pageQualityLevelLookup->getQualityLevelForPageTitle( $title ); |
30 | if ( $pageQualityLevel === null ) { |
31 | continue; |
32 | } |
33 | |
34 | $val = [ |
35 | 'quality' => $pageQualityLevel, |
36 | 'quality_text' => $this->getQualityLevelCategory( $pageQualityLevel ) |
37 | ]; |
38 | $result->addValue( [ 'query', 'pages', $pageId ], 'proofread', $val ); |
39 | } |
40 | } |
41 | } |
42 | |
43 | /** |
44 | * @param int $level |
45 | * @return string |
46 | */ |
47 | private function getQualityLevelCategory( $level ) { |
48 | if ( !array_key_exists( $level, $this->qualityLevelCategoryCache ) ) { |
49 | $messageName = "proofreadpage_quality{$level}_category"; |
50 | $category = $this->msg( $messageName )->inContentLanguage()->text(); |
51 | $this->qualityLevelCategoryCache[$level] = $category; |
52 | } |
53 | return $this->qualityLevelCategoryCache[$level]; |
54 | } |
55 | |
56 | /** |
57 | * @param array $params [optional] Parameters (unused parameter) |
58 | * @see ApiQueryBase::getCacheMode() |
59 | * @return string |
60 | */ |
61 | public function getCacheMode( $params ) { |
62 | return 'public'; |
63 | } |
64 | |
65 | /** |
66 | * @see ApiBase::getAllowedParams() |
67 | * @return array |
68 | */ |
69 | public function getAllowedParams() { |
70 | return []; |
71 | } |
72 | |
73 | /** |
74 | * @inheritDoc |
75 | */ |
76 | protected function getExamplesMessages() { |
77 | return [ |
78 | 'action=query&generator=allpages&gapnamespace=250&prop=proofread' |
79 | => 'apihelp-query+proofread-example-1', |
80 | ]; |
81 | } |
82 | } |