Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 243 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
FeatureManagerFactory | |
0.00% |
0 / 243 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
createFeatureManager | |
0.00% |
0 / 242 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | /** |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License as published by |
6 | * the Free Software Foundation; either version 2 of the License, or |
7 | * (at your option) any later version. |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License along |
15 | * with this program; if not, write to the Free Software Foundation, Inc., |
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | * http://www.gnu.org/copyleft/gpl.html |
18 | * |
19 | * @file |
20 | * @since 1.42 |
21 | */ |
22 | |
23 | namespace MediaWiki\Skins\Vector\FeatureManagement; |
24 | |
25 | use MediaWiki\Context\IContextSource; |
26 | use MediaWiki\Skins\Vector\Constants; |
27 | use MediaWiki\Skins\Vector\FeatureManagement\Requirements\DynamicConfigRequirement; |
28 | use MediaWiki\Skins\Vector\FeatureManagement\Requirements\LimitedWidthContentRequirement; |
29 | use MediaWiki\Skins\Vector\FeatureManagement\Requirements\LoggedInRequirement; |
30 | use MediaWiki\Skins\Vector\FeatureManagement\Requirements\OverridableConfigRequirement; |
31 | use MediaWiki\Skins\Vector\FeatureManagement\Requirements\UserPreferenceRequirement; |
32 | use MediaWiki\User\Options\UserOptionsLookup; |
33 | |
34 | /** |
35 | * A simple feature manager factory. |
36 | * |
37 | * @unstable |
38 | * |
39 | * @package MediaWiki\Skins\Vector\FeatureManagement |
40 | * @internal |
41 | */ |
42 | class FeatureManagerFactory { |
43 | |
44 | private UserOptionsLookup $userOptionsLookup; |
45 | |
46 | public function __construct( |
47 | UserOptionsLookup $userOptionsLookup |
48 | ) { |
49 | $this->userOptionsLookup = $userOptionsLookup; |
50 | } |
51 | |
52 | public function createFeatureManager( IContextSource $context ): FeatureManager { |
53 | $featureManager = new FeatureManager( $this->userOptionsLookup, $context ); |
54 | |
55 | $request = $context->getRequest(); |
56 | $config = $context->getConfig(); |
57 | $user = $context->getUser(); |
58 | $title = $context->getTitle(); |
59 | |
60 | $featureManager->registerRequirement( |
61 | new DynamicConfigRequirement( |
62 | $config, |
63 | Constants::CONFIG_KEY_FULLY_INITIALISED, |
64 | Constants::REQUIREMENT_FULLY_INITIALISED |
65 | ) |
66 | ); |
67 | |
68 | // Feature: Languages in sidebar |
69 | // ================================ |
70 | $featureManager->registerRequirement( |
71 | new OverridableConfigRequirement( |
72 | $config, |
73 | $user, |
74 | $request, |
75 | Constants::CONFIG_KEY_LANGUAGE_IN_HEADER, |
76 | Constants::REQUIREMENT_LANGUAGE_IN_HEADER |
77 | ) |
78 | ); |
79 | |
80 | // --- |
81 | |
82 | $featureManager->registerFeature( |
83 | Constants::FEATURE_LANGUAGE_IN_HEADER, |
84 | [ |
85 | Constants::REQUIREMENT_FULLY_INITIALISED, |
86 | Constants::REQUIREMENT_LANGUAGE_IN_HEADER, |
87 | ] |
88 | ); |
89 | |
90 | // Feature: T293470: Language in main page header |
91 | // ================================ |
92 | $featureManager->registerRequirement( |
93 | new OverridableConfigRequirement( |
94 | $config, |
95 | $user, |
96 | $request, |
97 | Constants::CONFIG_LANGUAGE_IN_MAIN_PAGE_HEADER, |
98 | Constants::REQUIREMENT_LANGUAGE_IN_MAIN_PAGE_HEADER |
99 | ) |
100 | ); |
101 | |
102 | $featureManager->registerSimpleRequirement( |
103 | Constants::REQUIREMENT_IS_MAIN_PAGE, |
104 | $title ? $title->isMainPage() : false |
105 | ); |
106 | |
107 | $featureManager->registerFeature( |
108 | Constants::FEATURE_LANGUAGE_IN_MAIN_PAGE_HEADER, |
109 | [ |
110 | Constants::REQUIREMENT_FULLY_INITIALISED, |
111 | Constants::REQUIREMENT_IS_MAIN_PAGE, |
112 | Constants::REQUIREMENT_LANGUAGE_IN_HEADER, |
113 | Constants::REQUIREMENT_LANGUAGE_IN_MAIN_PAGE_HEADER |
114 | ] |
115 | ); |
116 | |
117 | // Feature: Sticky header |
118 | // ================================ |
119 | $featureManager->registerRequirement( |
120 | new OverridableConfigRequirement( |
121 | $config, |
122 | $user, |
123 | $request, |
124 | Constants::CONFIG_STICKY_HEADER, |
125 | Constants::REQUIREMENT_STICKY_HEADER |
126 | ) |
127 | ); |
128 | |
129 | $featureManager->registerFeature( |
130 | Constants::FEATURE_STICKY_HEADER, |
131 | [ |
132 | Constants::REQUIREMENT_FULLY_INITIALISED, |
133 | Constants::REQUIREMENT_STICKY_HEADER |
134 | ] |
135 | ); |
136 | |
137 | // Feature: Page tools pinned |
138 | // ================================ |
139 | $featureManager->registerRequirement( |
140 | new LoggedInRequirement( |
141 | $user, |
142 | Constants::REQUIREMENT_LOGGED_IN |
143 | ) |
144 | ); |
145 | |
146 | $featureManager->registerRequirement( |
147 | new UserPreferenceRequirement( |
148 | $user, |
149 | $this->userOptionsLookup, |
150 | Constants::PREF_KEY_PAGE_TOOLS_PINNED, |
151 | Constants::REQUIREMENT_PAGE_TOOLS_PINNED, |
152 | $request, |
153 | $title |
154 | ) |
155 | ); |
156 | |
157 | $featureManager->registerFeature( |
158 | Constants::FEATURE_PAGE_TOOLS_PINNED, |
159 | [ |
160 | Constants::REQUIREMENT_FULLY_INITIALISED, |
161 | Constants::REQUIREMENT_LOGGED_IN, |
162 | Constants::REQUIREMENT_PAGE_TOOLS_PINNED |
163 | ] |
164 | ); |
165 | |
166 | // Feature: Table of Contents pinned |
167 | // ================================ |
168 | $featureManager->registerRequirement( |
169 | new UserPreferenceRequirement( |
170 | $user, |
171 | $this->userOptionsLookup, |
172 | Constants::PREF_KEY_TOC_PINNED, |
173 | Constants::REQUIREMENT_TOC_PINNED, |
174 | $request, |
175 | $title |
176 | ) |
177 | ); |
178 | |
179 | $featureManager->registerFeature( |
180 | Constants::FEATURE_TOC_PINNED, |
181 | [ |
182 | Constants::REQUIREMENT_FULLY_INITIALISED, |
183 | Constants::REQUIREMENT_TOC_PINNED |
184 | ] |
185 | ); |
186 | |
187 | // Feature: Main menu pinned |
188 | // ================================ |
189 | $featureManager->registerRequirement( |
190 | new UserPreferenceRequirement( |
191 | $user, |
192 | $this->userOptionsLookup, |
193 | Constants::PREF_KEY_MAIN_MENU_PINNED, |
194 | Constants::REQUIREMENT_MAIN_MENU_PINNED, |
195 | $request, |
196 | $title |
197 | ) |
198 | ); |
199 | |
200 | $featureManager->registerFeature( |
201 | Constants::FEATURE_MAIN_MENU_PINNED, |
202 | [ |
203 | Constants::REQUIREMENT_FULLY_INITIALISED, |
204 | Constants::REQUIREMENT_LOGGED_IN, |
205 | Constants::REQUIREMENT_MAIN_MENU_PINNED |
206 | ] |
207 | ); |
208 | |
209 | // Feature: Max Width (skin) |
210 | // ================================ |
211 | $featureManager->registerRequirement( |
212 | new UserPreferenceRequirement( |
213 | $user, |
214 | $this->userOptionsLookup, |
215 | Constants::PREF_KEY_LIMITED_WIDTH, |
216 | Constants::REQUIREMENT_LIMITED_WIDTH, |
217 | $request, |
218 | $title |
219 | ) |
220 | ); |
221 | $featureManager->registerFeature( |
222 | Constants::FEATURE_LIMITED_WIDTH, |
223 | [ |
224 | Constants::REQUIREMENT_FULLY_INITIALISED, |
225 | Constants::REQUIREMENT_LIMITED_WIDTH |
226 | ] |
227 | ); |
228 | |
229 | // Feature: Max Width (content) |
230 | // ================================ |
231 | $featureManager->registerRequirement( |
232 | new LimitedWidthContentRequirement( |
233 | $config, |
234 | $request, |
235 | $title |
236 | ) |
237 | ); |
238 | $featureManager->registerFeature( |
239 | Constants::FEATURE_LIMITED_WIDTH_CONTENT, |
240 | [ |
241 | Constants::REQUIREMENT_FULLY_INITIALISED, |
242 | Constants::REQUIREMENT_LIMITED_WIDTH_CONTENT, |
243 | ] |
244 | ); |
245 | |
246 | // Feature: T343928: Feature Font Size. |
247 | // ================================ |
248 | $featureManager->registerRequirement( |
249 | new UserPreferenceRequirement( |
250 | $user, |
251 | $this->userOptionsLookup, |
252 | Constants::PREF_KEY_FONT_SIZE, |
253 | Constants::REQUIREMENT_FONT_SIZE, |
254 | $request, |
255 | $title |
256 | ) |
257 | ); |
258 | |
259 | // Register 'custom-font-size' as the default requirement |
260 | $featureManager->registerFeature( |
261 | Constants::FEATURE_FONT_SIZE, |
262 | [ |
263 | Constants::REQUIREMENT_FULLY_INITIALISED, |
264 | Constants::REQUIREMENT_FONT_SIZE |
265 | ] |
266 | ); |
267 | |
268 | // Feature: T345363: Appearance menu |
269 | // ============================================ |
270 | $featureManager->registerRequirement( |
271 | new OverridableConfigRequirement( |
272 | $config, |
273 | $user, |
274 | $request, |
275 | Constants::CONFIG_KEY_APPEARANCE, |
276 | Constants::REQUIREMENT_APPEARANCE |
277 | ) |
278 | ); |
279 | |
280 | $featureManager->registerFeature( |
281 | Constants::FEATURE_APPEARANCE, |
282 | [ |
283 | Constants::REQUIREMENT_FULLY_INITIALISED, |
284 | Constants::REQUIREMENT_APPEARANCE |
285 | ] |
286 | ); |
287 | |
288 | // Feature: Appearance menu pinned |
289 | // ================================ |
290 | $featureManager->registerRequirement( |
291 | new UserPreferenceRequirement( |
292 | $user, |
293 | $this->userOptionsLookup, |
294 | Constants::PREF_KEY_APPEARANCE_PINNED, |
295 | Constants::REQUIREMENT_APPEARANCE_PINNED, |
296 | $request, |
297 | $title |
298 | ) |
299 | ); |
300 | |
301 | $featureManager->registerFeature( |
302 | Constants::FEATURE_APPEARANCE_PINNED, |
303 | [ |
304 | Constants::REQUIREMENT_FULLY_INITIALISED, |
305 | Constants::REQUIREMENT_APPEARANCE, |
306 | Constants::REQUIREMENT_APPEARANCE_PINNED |
307 | ] |
308 | ); |
309 | |
310 | // Feature: Night mode (T355065) |
311 | // ============================================ |
312 | $featureManager->registerRequirement( |
313 | new OverridableConfigRequirement( |
314 | $config, |
315 | $user, |
316 | $request, |
317 | Constants::CONFIG_KEY_NIGHT_MODE, |
318 | Constants::REQUIREMENT_NIGHT_MODE |
319 | ) |
320 | ); |
321 | |
322 | $featureManager->registerFeature( |
323 | Constants::FEATURE_NIGHT_MODE, |
324 | [ |
325 | Constants::REQUIREMENT_FULLY_INITIALISED, |
326 | Constants::REQUIREMENT_NIGHT_MODE |
327 | ] |
328 | ); |
329 | |
330 | // Preference: Night mode (T355065) |
331 | // ============================================ |
332 | $featureManager->registerRequirement( |
333 | new UserPreferenceRequirement( |
334 | $user, |
335 | $this->userOptionsLookup, |
336 | Constants::PREF_KEY_NIGHT_MODE, |
337 | Constants::REQUIREMENT_PREF_NIGHT_MODE, |
338 | $request, |
339 | $title |
340 | ) |
341 | ); |
342 | |
343 | $featureManager->registerFeature( |
344 | Constants::PREF_NIGHT_MODE, |
345 | [ |
346 | Constants::REQUIREMENT_FULLY_INITIALISED, |
347 | Constants::REQUIREMENT_NIGHT_MODE, |
348 | Constants::REQUIREMENT_PREF_NIGHT_MODE |
349 | ] |
350 | ); |
351 | |
352 | return $featureManager; |
353 | } |
354 | |
355 | } |