-
Notifications
You must be signed in to change notification settings - Fork 0
/
BetaFeatureEverywhere.hooks.php
53 lines (41 loc) · 1.71 KB
/
BetaFeatureEverywhere.hooks.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
class BetaFeatureEverywhereHooks {
/**
* Handler for UserLoadOptions
* @param User $user
* @param array $options
* @return array $options
*/
static function everywhere( $user, &$options) {
global $wgDefaultUserOptions, $wgHiddenPrefs, $wgBetaFeaturesEverywhere;
global $wgBetaFeaturesWhitelist, $wgBetaFeaturesWhitelistLoggedIn, $wgUser;
$features = array(
'betafeatures-vector-compact-personal-bar',
'betafeatures-vector-typography-update',
'betafeatures-vector-fixedheader',
'visualeditor-enable',
'popups',
);
// $wgBetaFeaturesWhitelist should contain features whitelisted for everyone
// $wgBetaFeaturesWhitelistLoggedIn should contain all features whitelisted for logged in users
// Why this magic works: https://github.com/wikimedia/mediawiki-extensions-BetaFeatures/blob/3beab25f9d28e99b8d2ee2186c28125c3e0dcf80/includes/BetaFeaturesUtil.php#L35
if( isset($wgBetaFeaturesWhitelist) && is_array($wgBetaFeaturesWhitelist) &&
isset($wgBetaFeaturesWhitelistLoggedIn) && is_array($wgBetaFeaturesWhitelistLoggedIn) &&
$wgUser->isLoggedIn()
) {
$wgBetaFeaturesWhitelist = array_merge($wgBetaFeaturesWhitelist, $wgBetaFeaturesWhitelistLoggedIn);
}
if(isset($wgBetaFeaturesEverywhere) && is_array($wgBetaFeaturesEverywhere)) {
$features = array_merge($wgBetaFeaturesEverywhere, $features);
}
foreach($features as $feature) {
if( isset($wgDefaultUserOptions[$feature]) ) {
// Set feature on/off for also logged in users
$options[$feature] = $wgDefaultUserOptions[$feature];
// Hide feature from preferences
$wgHiddenPrefs[] = $feature;
}
}
return $options;
}
}