Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 211
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
FeatureManagerFactory
0.00% covered (danger)
0.00%
0 / 211
0.00% covered (danger)
0.00%
0 / 2
12
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 createFeatureManager
0.00% covered (danger)
0.00%
0 / 210
0.00% covered (danger)
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
23namespace MediaWiki\Skins\Vector\FeatureManagement;
24
25use MediaWiki\Context\IContextSource;
26use MediaWiki\Skins\Vector\ConfigHelper;
27use MediaWiki\Skins\Vector\Constants;
28use MediaWiki\Skins\Vector\FeatureManagement\Requirements\DynamicConfigRequirement;
29use MediaWiki\Skins\Vector\FeatureManagement\Requirements\LimitedWidthContentRequirement;
30use MediaWiki\Skins\Vector\FeatureManagement\Requirements\LoggedInRequirement;
31use MediaWiki\Skins\Vector\FeatureManagement\Requirements\OverridableConfigRequirement;
32use MediaWiki\Skins\Vector\FeatureManagement\Requirements\UserPreferenceRequirement;
33use MediaWiki\User\Options\UserOptionsLookup;
34
35/**
36 * A simple feature manager factory.
37 *
38 * @unstable
39 *
40 * @package MediaWiki\Skins\Vector\FeatureManagement
41 * @internal
42 */
43class FeatureManagerFactory {
44
45    public function __construct(
46        private readonly ConfigHelper $configHelper,
47        private readonly UserOptionsLookup $userOptionsLookup,
48    ) {
49    }
50
51    public function createFeatureManager( IContextSource $context ): FeatureManager {
52        $featureManager = new FeatureManager( $this->configHelper, $this->userOptionsLookup, $context );
53
54        $request = $context->getRequest();
55        $config = $context->getConfig();
56        $user = $context->getUser();
57        $title = $context->getTitle();
58
59        $featureManager->registerRequirement(
60            new DynamicConfigRequirement(
61                $config,
62                Constants::CONFIG_KEY_FULLY_INITIALISED,
63                Constants::REQUIREMENT_FULLY_INITIALISED
64            )
65        );
66
67        // Feature: Languages in sidebar
68        // ================================
69        $featureManager->registerRequirement(
70            new OverridableConfigRequirement(
71                $config,
72                $user,
73                $request,
74                Constants::CONFIG_KEY_LANGUAGE_IN_HEADER,
75                Constants::REQUIREMENT_LANGUAGE_IN_HEADER
76            )
77        );
78
79        // ---
80
81        $featureManager->registerFeature(
82            Constants::FEATURE_LANGUAGE_IN_HEADER,
83            [
84                Constants::REQUIREMENT_FULLY_INITIALISED,
85                Constants::REQUIREMENT_LANGUAGE_IN_HEADER,
86            ]
87        );
88
89        // Feature: T293470: Language in main page header
90        // ================================
91        $featureManager->registerRequirement(
92            new OverridableConfigRequirement(
93                $config,
94                $user,
95                $request,
96                Constants::CONFIG_LANGUAGE_IN_MAIN_PAGE_HEADER,
97                Constants::REQUIREMENT_LANGUAGE_IN_MAIN_PAGE_HEADER
98            )
99        );
100
101        $featureManager->registerSimpleRequirement(
102            Constants::REQUIREMENT_IS_MAIN_PAGE,
103            $title ? $title->isMainPage() : false
104        );
105
106        $featureManager->registerFeature(
107            Constants::FEATURE_LANGUAGE_IN_MAIN_PAGE_HEADER,
108            [
109                Constants::REQUIREMENT_FULLY_INITIALISED,
110                Constants::REQUIREMENT_IS_MAIN_PAGE,
111                Constants::REQUIREMENT_LANGUAGE_IN_HEADER,
112                Constants::REQUIREMENT_LANGUAGE_IN_MAIN_PAGE_HEADER
113            ]
114        );
115
116        // Feature: Page tools pinned
117        // ================================
118        $featureManager->registerRequirement(
119            new LoggedInRequirement(
120                $user,
121                Constants::REQUIREMENT_LOGGED_IN
122            )
123        );
124
125        $featureManager->registerRequirement(
126            new UserPreferenceRequirement(
127                $user,
128                $this->userOptionsLookup,
129                Constants::PREF_KEY_PAGE_TOOLS_PINNED,
130                Constants::REQUIREMENT_PAGE_TOOLS_PINNED,
131                $request,
132                $title
133            )
134        );
135
136        $featureManager->registerFeature(
137            Constants::FEATURE_PAGE_TOOLS_PINNED,
138            [
139                Constants::REQUIREMENT_FULLY_INITIALISED,
140                Constants::REQUIREMENT_LOGGED_IN,
141                Constants::REQUIREMENT_PAGE_TOOLS_PINNED
142            ]
143        );
144
145        // Feature: Table of Contents pinned
146        // ================================
147        $featureManager->registerRequirement(
148            new UserPreferenceRequirement(
149                $user,
150                $this->userOptionsLookup,
151                Constants::PREF_KEY_TOC_PINNED,
152                Constants::REQUIREMENT_TOC_PINNED,
153                $request,
154                $title
155            )
156        );
157
158        $featureManager->registerFeature(
159            Constants::FEATURE_TOC_PINNED,
160            [
161                Constants::REQUIREMENT_FULLY_INITIALISED,
162                Constants::REQUIREMENT_TOC_PINNED
163            ]
164        );
165
166        // Feature: Main menu pinned
167        // ================================
168        $featureManager->registerRequirement(
169            new UserPreferenceRequirement(
170                $user,
171                $this->userOptionsLookup,
172                Constants::PREF_KEY_MAIN_MENU_PINNED,
173                Constants::REQUIREMENT_MAIN_MENU_PINNED,
174                $request,
175                $title
176            )
177        );
178
179        $featureManager->registerFeature(
180            Constants::FEATURE_MAIN_MENU_PINNED,
181            [
182                Constants::REQUIREMENT_FULLY_INITIALISED,
183                Constants::REQUIREMENT_LOGGED_IN,
184                Constants::REQUIREMENT_MAIN_MENU_PINNED
185            ]
186        );
187
188        // Feature: Max Width (skin)
189        // ================================
190        $featureManager->registerRequirement(
191            new UserPreferenceRequirement(
192                $user,
193                $this->userOptionsLookup,
194                Constants::PREF_KEY_LIMITED_WIDTH,
195                Constants::REQUIREMENT_LIMITED_WIDTH,
196                $request,
197                $title
198            )
199        );
200        $featureManager->registerFeature(
201            Constants::FEATURE_LIMITED_WIDTH,
202            [
203                Constants::REQUIREMENT_FULLY_INITIALISED,
204                Constants::REQUIREMENT_LIMITED_WIDTH
205            ]
206        );
207
208        // Feature: Max Width (content)
209        // ================================
210        $featureManager->registerRequirement(
211            new LimitedWidthContentRequirement(
212                $config,
213                $this->configHelper,
214                $request,
215                $title
216            )
217        );
218        $featureManager->registerFeature(
219            Constants::FEATURE_LIMITED_WIDTH_CONTENT,
220            [
221                Constants::REQUIREMENT_FULLY_INITIALISED,
222                Constants::REQUIREMENT_LIMITED_WIDTH_CONTENT,
223            ]
224        );
225
226        // Feature: T343928: Feature Font Size.
227        // ================================
228        $featureManager->registerRequirement(
229            new UserPreferenceRequirement(
230                $user,
231                $this->userOptionsLookup,
232                Constants::PREF_KEY_FONT_SIZE,
233                Constants::REQUIREMENT_FONT_SIZE,
234                $request,
235                $title
236            )
237        );
238
239        // Register 'custom-font-size' as the default requirement
240        $featureManager->registerFeature(
241            Constants::FEATURE_FONT_SIZE,
242            [
243                Constants::REQUIREMENT_FULLY_INITIALISED,
244                Constants::REQUIREMENT_FONT_SIZE
245            ]
246        );
247
248        // Feature: Appearance menu pinned
249        // ================================
250        $featureManager->registerRequirement(
251            new UserPreferenceRequirement(
252                $user,
253                $this->userOptionsLookup,
254                Constants::PREF_KEY_APPEARANCE_PINNED,
255                Constants::REQUIREMENT_APPEARANCE_PINNED,
256                $request,
257                $title
258            )
259        );
260
261        $featureManager->registerFeature(
262            Constants::FEATURE_APPEARANCE_PINNED,
263            [
264                Constants::REQUIREMENT_FULLY_INITIALISED,
265                Constants::REQUIREMENT_APPEARANCE_PINNED
266            ]
267        );
268
269        // Feature: Night mode (T355065)
270        // ============================================
271        $featureManager->registerRequirement(
272            new OverridableConfigRequirement(
273                $config,
274                $user,
275                $request,
276                Constants::CONFIG_KEY_NIGHT_MODE,
277                Constants::REQUIREMENT_NIGHT_MODE
278            )
279        );
280
281        $featureManager->registerFeature(
282            Constants::FEATURE_NIGHT_MODE,
283            [
284                Constants::REQUIREMENT_FULLY_INITIALISED,
285                Constants::REQUIREMENT_NIGHT_MODE
286            ]
287        );
288
289        // Preference: Night mode (T355065)
290        // ============================================
291        $featureManager->registerRequirement(
292            new UserPreferenceRequirement(
293                $user,
294                $this->userOptionsLookup,
295                Constants::PREF_KEY_NIGHT_MODE,
296                Constants::REQUIREMENT_PREF_NIGHT_MODE,
297                $request,
298                $title
299            )
300        );
301
302        $featureManager->registerFeature(
303            Constants::PREF_NIGHT_MODE,
304            [
305                Constants::REQUIREMENT_FULLY_INITIALISED,
306                Constants::REQUIREMENT_NIGHT_MODE,
307                Constants::REQUIREMENT_PREF_NIGHT_MODE
308            ]
309        );
310
311        return $featureManager;
312    }
313
314}