Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 58 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
CommunityConfigurationHooks | |
0.00% |
0 / 58 |
|
0.00% |
0 / 4 |
380 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
onCommunityConfigurationSchemaBeforeEditor | |
0.00% |
0 / 28 |
|
0.00% |
0 / 1 |
110 | |||
isCalledFromBrokenTest | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
onCommunityConfigurationProvider_initList | |
0.00% |
0 / 25 |
|
0.00% |
0 / 1 |
42 |
1 | <?php |
2 | |
3 | namespace GrowthExperiments\Config; |
4 | |
5 | use GrowthExperiments\Config\Schemas\CommunityUpdatesSchema; |
6 | use GrowthExperiments\LevelingUp\LevelingUpManager; |
7 | use MediaWiki\Config\Config; |
8 | use MediaWiki\Extension\CommunityConfiguration\Hooks\CommunityConfigurationProvider_initListHook; |
9 | use MediaWiki\Extension\CommunityConfiguration\Hooks\CommunityConfigurationSchemaBeforeEditorHook; |
10 | use MediaWiki\Extension\CommunityConfiguration\Provider\IConfigurationProvider; |
11 | |
12 | class CommunityConfigurationHooks implements |
13 | CommunityConfigurationSchemaBeforeEditorHook, |
14 | CommunityConfigurationProvider_initListHook |
15 | { |
16 | |
17 | private Config $config; |
18 | |
19 | public function __construct( Config $config ) { |
20 | $this->config = $config; |
21 | } |
22 | |
23 | /** |
24 | * @inheritDoc |
25 | */ |
26 | public function onCommunityConfigurationSchemaBeforeEditor( |
27 | IConfigurationProvider $provider, array &$rootSchema |
28 | ) { |
29 | switch ( $provider->getId() ) { |
30 | case 'Mentorship': |
31 | if ( !$this->config->get( 'GEPersonalizedPraiseBackendEnabled' ) ) { |
32 | unset( |
33 | $rootSchema['properties']['GEPersonalizedPraiseDays'], |
34 | $rootSchema['properties']['GEPersonalizedPraiseDefaultNotificationsFrequency'], |
35 | $rootSchema['properties']['GEPersonalizedPraiseMaxEdits'], |
36 | $rootSchema['properties']['GEPersonalizedPraiseMinEdits'] |
37 | ); |
38 | } |
39 | break; |
40 | case 'GrowthSuggestedEdits': |
41 | if ( !$this->config->get( 'GELinkRecommendationsFrontendEnabled' ) ) { |
42 | // HACK: for T370611. This should be removed asap, ideally before end of August 2024. |
43 | $rootSchema['properties']['link_recommendation'] |
44 | ['properties']['disabled']['disabled-true-hack-T370611'] = true; |
45 | } |
46 | if ( !$this->config->get( 'GENewcomerTasksLinkRecommendationsEnabled' ) ) { |
47 | unset( $rootSchema['properties']['link_recommendation'] ); |
48 | } |
49 | if ( !$this->config->get( 'GENewcomerTasksImageRecommendationsEnabled' ) ) { |
50 | unset( $rootSchema['properties']['image_recommendation'] ); |
51 | } |
52 | if ( !$this->config->get( 'GENewcomerTasksSectionImageRecommendationsEnabled' ) ) { |
53 | unset( $rootSchema['properties']['section_image_recommendation'] ); |
54 | } |
55 | break; |
56 | case 'GrowthHomepage': |
57 | if ( !LevelingUpManager::isEnabledForAnyone( $this->config ) ) { |
58 | unset( |
59 | $rootSchema['properties']['GELevelingUpGetStartedMaxTotalEdits'], |
60 | $rootSchema['properties']['GELevelingUpKeepGoingNotificationThresholds'], |
61 | ); |
62 | } |
63 | break; |
64 | } |
65 | } |
66 | |
67 | private function isCalledFromBrokenTest() { |
68 | if ( !defined( 'MW_PHPUNIT_TEST' ) ) { |
69 | return false; |
70 | } |
71 | |
72 | $trace = ( new \RuntimeException() )->getTraceAsString(); |
73 | return str_contains( $trace, 'ApiStructureTest' ); |
74 | } |
75 | |
76 | public function onCommunityConfigurationProvider_initList( array &$providers ) { |
77 | if ( $this->config->get( 'GECommunityUpdatesEnabled' ) ) { |
78 | $providers['CommunityUpdates'] = [ |
79 | "store" => [ |
80 | "type" => "wikipage", |
81 | "args" => [ |
82 | "MediaWiki:GrowthExperimentsCommunityUpdates.json", |
83 | ], |
84 | ], |
85 | "validator" => [ |
86 | "type" => "jsonschema", |
87 | "args" => [ |
88 | CommunityUpdatesSchema::class, |
89 | ], |
90 | ], |
91 | "type" => "data", |
92 | ]; |
93 | } |
94 | if ( !$this->config->get( 'GEHomepageSuggestedEditsEnabled' ) ) { |
95 | unset( $providers['GrowthSuggestedEdits'] ); |
96 | } |
97 | if ( !$this->config->get( 'GEHelpPanelEnabled' ) ) { |
98 | unset( $providers['HelpPanel'] ); |
99 | } |
100 | |
101 | // HACK: Do not break ApiStructureTest |
102 | // TODO: Figure out why ApiStructureTest is failing with a validator defined here and |
103 | // remove this (T380585) |
104 | if ( |
105 | array_key_exists( 'GrowthSuggestedEdits', $providers ) && |
106 | $this->isCalledFromBrokenTest() |
107 | ) { |
108 | $providers['GrowthSuggestedEdits']['validator'] = [ |
109 | 'type' => 'noop', |
110 | ]; |
111 | } |
112 | } |
113 | } |