Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
BetaPreferenceHooks
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 2
42
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 onGetBetaFeaturePreferences
0.00% covered (danger)
0.00%
0 / 23
0.00% covered (danger)
0.00%
0 / 1
30
1<?php
2
3namespace MediaWiki\Extension\DiscussionTools\Hooks;
4
5use MediaWiki\Config\Config;
6use MediaWiki\Config\ConfigFactory;
7use MediaWiki\Extension\BetaFeatures\Hooks\GetBetaFeaturePreferencesHook;
8use MediaWiki\MainConfigNames;
9use MediaWiki\User\User;
10
11/**
12 * Hooks from BetaFeatures extension,
13 * which is optional to use with this extension.
14 */
15class BetaPreferenceHooks implements GetBetaFeaturePreferencesHook {
16
17    private Config $coreConfig;
18    private Config $config;
19
20    public function __construct(
21        Config $coreConfig,
22        ConfigFactory $configFactory
23    ) {
24        $this->coreConfig = $coreConfig;
25        $this->config = $configFactory->makeConfig( 'discussiontools' );
26    }
27
28    /**
29     * Handler for the GetBetaFeaturePreferences hook, to add and hide user beta preferences as configured
30     */
31    public function onGetBetaFeaturePreferences( User $user, array &$preferences ) {
32        if ( $this->config->get( 'DiscussionToolsBeta' ) ) {
33            // If all configurable features are marked as 'available', the
34            // beta fetaure enables nothing, so don't show it.
35            $allAvailable = true;
36            foreach ( HookUtils::CONFIGS as $feature ) {
37                if ( $this->config->get( 'DiscussionTools_' . $feature ) !== 'available' ) {
38                    $allAvailable = false;
39                    break;
40                }
41            }
42            if ( $allAvailable ) {
43                return;
44            }
45            $iconpath = $this->coreConfig->get( MainConfigNames::ExtensionAssetsPath ) . '/DiscussionTools/images';
46            $preferences['discussiontools-betaenable'] = [
47                'version' => '1.0',
48                'label-message' => 'discussiontools-preference-label',
49                'desc-message' => 'discussiontools-preference-description',
50                'screenshot' => [
51                    'ltr' => "$iconpath/betafeatures-icon-DiscussionTools-ltr.svg",
52                    'rtl' => "$iconpath/betafeatures-icon-DiscussionTools-rtl.svg",
53                ],
54                'info-message' => 'discussiontools-preference-info-link',
55                'discussion-message' => 'discussiontools-preference-discussion-link',
56                'requirements' => [
57                    'javascript' => true
58                ]
59            ];
60        }
61    }
62
63}