Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 18
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 / 18
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 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 onGetBetaFeaturePreferences
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace MediaWiki\Extension\VisualEditor;
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( 'visualeditor' );
26    }
27
28    /**
29     * Handler for the GetBetaFeaturePreferences hook, to add and hide user beta preferences as configured
30     *
31     * @param User $user
32     * @param array &$preferences
33     */
34    public function onGetBetaFeaturePreferences( User $user, array &$preferences ) {
35        if ( $this->config->get( 'VisualEditorEnableCollabBeta' ) ) {
36            $iconpath = $this->coreConfig->get( MainConfigNames::ExtensionAssetsPath ) . '/VisualEditor/images';
37
38            $preferences['visualeditor-collab'] = [
39                'version' => '1.0',
40                'label-message' => 'visualeditor-preference-collab-label',
41                'desc-message' => 'visualeditor-preference-collab-description',
42                'screenshot' => [
43                    'ltr' => "$iconpath/betafeatures-icon-collab-ltr.svg",
44                    'rtl' => "$iconpath/betafeatures-icon-collab-rtl.svg",
45                ],
46                'info-message' => 'visualeditor-preference-collab-info-link',
47                'discussion-message' => 'visualeditor-preference-collab-discussion-link',
48                'requirements' => [
49                    'javascript' => true
50                ]
51            ];
52        }
53    }
54
55}