Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 68 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
MobileFrontendHooks | |
0.00% |
0 / 68 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
onMobileFrontendFeaturesRegistration | |
0.00% |
0 / 65 |
|
0.00% |
0 / 1 |
6 | |||
onRequestContextCreateSkinMobile | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Minerva; |
4 | |
5 | use MediaWiki\Config\ConfigFactory; |
6 | use MobileContext; |
7 | use MobileFrontend\Features\Feature; |
8 | use MobileFrontend\Features\FeaturesManager; |
9 | use MobileFrontend\Hooks\MobileFrontendFeaturesRegistrationHook; |
10 | use MobileFrontend\Hooks\RequestContextCreateSkinMobileHook; |
11 | use RuntimeException; |
12 | use Skin; |
13 | |
14 | /** |
15 | * Hooks from MobileFrontend extension, |
16 | * which is optional to use with this skin. |
17 | */ |
18 | class MobileFrontendHooks implements |
19 | MobileFrontendFeaturesRegistrationHook, |
20 | RequestContextCreateSkinMobileHook |
21 | { |
22 | private ConfigFactory $configFactory; |
23 | private SkinOptions $skinOptions; |
24 | |
25 | public function __construct( |
26 | ConfigFactory $configFactory, |
27 | SkinOptions $skinOptions |
28 | ) { |
29 | $this->configFactory = $configFactory; |
30 | $this->skinOptions = $skinOptions; |
31 | } |
32 | |
33 | /** |
34 | * Register mobile web beta features |
35 | * @see https://www.mediawiki.org/wiki/ |
36 | * Extension:MobileFrontend/MobileFrontendFeaturesRegistration |
37 | * |
38 | * @param FeaturesManager $featuresManager |
39 | */ |
40 | public function onMobileFrontendFeaturesRegistration( FeaturesManager $featuresManager ) { |
41 | $config = $this->configFactory->makeConfig( 'minerva' ); |
42 | |
43 | try { |
44 | $featuresManager->registerFeature( |
45 | new Feature( |
46 | 'MinervaShowCategories', |
47 | 'skin-minerva', |
48 | $config->get( 'MinervaShowCategories' ) |
49 | ) |
50 | ); |
51 | $featuresManager->registerFeature( |
52 | new Feature( |
53 | 'MinervaPageIssuesNewTreatment', |
54 | 'skin-minerva', |
55 | $config->get( 'MinervaPageIssuesNewTreatment' ) |
56 | ) |
57 | ); |
58 | $featuresManager->registerFeature( |
59 | new Feature( |
60 | 'MinervaTalkAtTop', |
61 | 'skin-minerva', |
62 | $config->get( 'MinervaTalkAtTop' ) |
63 | ) |
64 | ); |
65 | $featuresManager->registerFeature( |
66 | new Feature( |
67 | 'MinervaDonateLink', |
68 | 'skin-minerva', |
69 | $config->get( 'MinervaDonateLink' ) |
70 | ) |
71 | ); |
72 | $featuresManager->registerFeature( |
73 | new Feature( |
74 | 'MinervaHistoryInPageActions', |
75 | 'skin-minerva', |
76 | $config->get( 'MinervaHistoryInPageActions' ) |
77 | ) |
78 | ); |
79 | $featuresManager->registerFeature( |
80 | new Feature( |
81 | Hooks::FEATURE_OVERFLOW_PAGE_ACTIONS, |
82 | 'skin-minerva', |
83 | $config->get( Hooks::FEATURE_OVERFLOW_PAGE_ACTIONS ) |
84 | ) |
85 | ); |
86 | $featuresManager->registerFeature( |
87 | new Feature( |
88 | 'MinervaAdvancedMainMenu', |
89 | 'skin-minerva', |
90 | $config->get( 'MinervaAdvancedMainMenu' ) |
91 | ) |
92 | ); |
93 | $featuresManager->registerFeature( |
94 | new Feature( |
95 | 'MinervaPersonalMenu', |
96 | 'skin-minerva', |
97 | $config->get( 'MinervaPersonalMenu' ) |
98 | ) |
99 | ); |
100 | $featuresManager->registerFeature( |
101 | new Feature( |
102 | 'MinervaNightMode', |
103 | 'skin-minerva', |
104 | $config->get( 'MinervaNightMode' ) |
105 | ) |
106 | ); |
107 | } catch ( RuntimeException $e ) { |
108 | // features already registered... |
109 | // due to a bug it's possible for this to run twice |
110 | // https://phabricator.wikimedia.org/T165068 |
111 | } |
112 | } |
113 | |
114 | /** |
115 | * BeforePageDisplayMobile hook handler. |
116 | * |
117 | * @param MobileContext $mobileContext |
118 | * @param Skin $skin |
119 | */ |
120 | public function onRequestContextCreateSkinMobile( |
121 | MobileContext $mobileContext, Skin $skin |
122 | ) { |
123 | $this->skinOptions->setMinervaSkinOptions( $mobileContext, $skin ); |
124 | } |
125 | } |