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