Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
60.53% |
23 / 38 |
|
91.67% |
11 / 12 |
CRAP | |
0.00% |
0 / 1 |
Context | |
60.53% |
23 / 38 |
|
91.67% |
11 / 12 |
26.06 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
1 | |||
getPageNamespaceId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getIndexNamespaceId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getConfig | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getFileProvider | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getPaginationFactory | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getCustomIndexFieldsParser | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getIndexForPageLookup | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getIndexContentLookup | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getPageQualityLevelLookup | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getIndexQualityStatsLookup | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getDefaultContext | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | namespace ProofreadPage; |
4 | |
5 | use MediaWiki\Config\Config; |
6 | use MediaWiki\Config\ConfigException; |
7 | use MediaWiki\MediaWikiServices; |
8 | use ProofreadPage\Index\CustomIndexFieldsParser; |
9 | use ProofreadPage\Index\DatabaseIndexContentLookup; |
10 | use ProofreadPage\Index\IndexContentLookup; |
11 | use ProofreadPage\Index\IndexQualityStatsLookup; |
12 | use ProofreadPage\Page\DatabaseIndexForPageLookup; |
13 | use ProofreadPage\Page\DatabasePageQualityLevelLookup; |
14 | use ProofreadPage\Page\IndexForPageLookup; |
15 | use ProofreadPage\Page\PageQualityLevelLookup; |
16 | use ProofreadPage\Pagination\PaginationFactory; |
17 | |
18 | /** |
19 | * @license GPL-2.0-or-later |
20 | * |
21 | * Extension context |
22 | * |
23 | * You should only get it with Context::getDefaultContext in extension entry points and then inject |
24 | * it in objects that requires it |
25 | * For testing, get a test compatible version with ProofreadPageTextCase::getContext() |
26 | */ |
27 | class Context { |
28 | |
29 | /** |
30 | * @var int |
31 | */ |
32 | private $pageNamespaceId; |
33 | |
34 | /** |
35 | * @var int |
36 | */ |
37 | private $indexNamespaceId; |
38 | |
39 | /** |
40 | * @var FileProvider |
41 | */ |
42 | private $fileProvider; |
43 | |
44 | /** |
45 | * @var PaginationFactory |
46 | */ |
47 | private $paginationFactory; |
48 | |
49 | /** |
50 | * @var CustomIndexFieldsParser |
51 | */ |
52 | private $customIndexFieldsParser; |
53 | |
54 | /** |
55 | * @var IndexForPageLookup |
56 | */ |
57 | private $indexForPageLookup; |
58 | |
59 | /** |
60 | * @var IndexContentLookup |
61 | */ |
62 | private $indexContentLookup; |
63 | |
64 | /** |
65 | * @var PageQualityLevelLookup |
66 | */ |
67 | private $pageQualityLevelLookup; |
68 | |
69 | /** |
70 | * @var IndexQualityStatsLookup |
71 | */ |
72 | private $indexQualityStatsLookup; |
73 | |
74 | /** |
75 | * @param int $pageNamespaceId |
76 | * @param int $indexNamespaceId |
77 | * @param FileProvider $fileProvider |
78 | * @param CustomIndexFieldsParser $customIndexFieldsParser |
79 | * @param IndexForPageLookup $indexForPageLookup |
80 | * @param IndexContentLookup $indexContentLookup |
81 | * @param PageQualityLevelLookup $pageQualityLevelLookup |
82 | * @param IndexQualityStatsLookup $indexQualityStatsLookup |
83 | */ |
84 | public function __construct( |
85 | $pageNamespaceId, $indexNamespaceId, FileProvider $fileProvider, |
86 | CustomIndexFieldsParser $customIndexFieldsParser, IndexForPageLookup $indexForPageLookup, |
87 | IndexContentLookup $indexContentLookup, PageQualityLevelLookup $pageQualityLevelLookup, |
88 | IndexQualityStatsLookup $indexQualityStatsLookup |
89 | ) { |
90 | $this->pageNamespaceId = $pageNamespaceId; |
91 | $this->indexNamespaceId = $indexNamespaceId; |
92 | $this->fileProvider = $fileProvider; |
93 | $this->customIndexFieldsParser = $customIndexFieldsParser; |
94 | $this->indexForPageLookup = $indexForPageLookup; |
95 | $this->indexContentLookup = $indexContentLookup; |
96 | $this->pageQualityLevelLookup = $pageQualityLevelLookup; |
97 | $this->indexQualityStatsLookup = $indexQualityStatsLookup; |
98 | |
99 | $this->paginationFactory = new PaginationFactory( |
100 | $fileProvider, |
101 | $indexContentLookup, |
102 | $pageNamespaceId |
103 | ); |
104 | } |
105 | |
106 | /** |
107 | * @return int |
108 | */ |
109 | public function getPageNamespaceId() { |
110 | return $this->pageNamespaceId; |
111 | } |
112 | |
113 | /** |
114 | * @return int |
115 | */ |
116 | public function getIndexNamespaceId() { |
117 | return $this->indexNamespaceId; |
118 | } |
119 | |
120 | /** |
121 | * @return Config |
122 | * @throws ConfigException |
123 | */ |
124 | public function getConfig() { |
125 | return MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'proofreadpage' ); |
126 | } |
127 | |
128 | /** |
129 | * @return FileProvider |
130 | */ |
131 | public function getFileProvider() { |
132 | return $this->fileProvider; |
133 | } |
134 | |
135 | /** |
136 | * @return PaginationFactory |
137 | */ |
138 | public function getPaginationFactory() { |
139 | return $this->paginationFactory; |
140 | } |
141 | |
142 | /** |
143 | * @return CustomIndexFieldsParser |
144 | */ |
145 | public function getCustomIndexFieldsParser() { |
146 | return $this->customIndexFieldsParser; |
147 | } |
148 | |
149 | /** |
150 | * @return IndexForPageLookup |
151 | */ |
152 | public function getIndexForPageLookup() { |
153 | return $this->indexForPageLookup; |
154 | } |
155 | |
156 | /** |
157 | * @return IndexContentLookup |
158 | */ |
159 | public function getIndexContentLookup() { |
160 | return $this->indexContentLookup; |
161 | } |
162 | |
163 | /** |
164 | * @return PageQualityLevelLookup |
165 | */ |
166 | public function getPageQualityLevelLookup() { |
167 | return $this->pageQualityLevelLookup; |
168 | } |
169 | |
170 | /** |
171 | * @return IndexQualityStatsLookup |
172 | */ |
173 | public function getIndexQualityStatsLookup(): IndexQualityStatsLookup { |
174 | return $this->indexQualityStatsLookup; |
175 | } |
176 | |
177 | /** |
178 | * @param bool $purge |
179 | * @return Context |
180 | */ |
181 | public static function getDefaultContext( $purge = false ) { |
182 | static $defaultContext; |
183 | |
184 | if ( $defaultContext === null || $purge ) { |
185 | $loadBalancer = MediaWikiServices::getInstance()->getDBLoadBalancer(); |
186 | $repoGroup = MediaWikiServices::getInstance()->getRepoGroup(); |
187 | $pageNamespaceId = ProofreadPageInit::getNamespaceId( 'page' ); |
188 | $indexNamespaceId = ProofreadPageInit::getNamespaceId( 'index' ); |
189 | $defaultContext = new self( $pageNamespaceId, $indexNamespaceId, |
190 | new FileProvider( $repoGroup ), |
191 | new CustomIndexFieldsParser(), |
192 | new DatabaseIndexForPageLookup( $indexNamespaceId, $repoGroup ), |
193 | new DatabaseIndexContentLookup(), |
194 | new DatabasePageQualityLevelLookup( $pageNamespaceId ), |
195 | new IndexQualityStatsLookup( $loadBalancer ) |
196 | ); |
197 | } |
198 | |
199 | return $defaultContext; |
200 | } |
201 | } |