Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | n/a |
0 / 0 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
|||
RegistrationCallback | n/a |
0 / 0 |
n/a |
0 / 0 |
13 | n/a |
0 / 0 |
|||
onRegistration | n/a |
0 / 0 |
n/a |
0 / 0 |
13 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\AbuseFilter\Hooks\Handlers; |
4 | |
5 | use InvalidArgumentException; |
6 | |
7 | /** |
8 | * This class runs a callback when the extension is registered, right after configuration has been |
9 | * loaded (not really a hook, but almost). |
10 | * @codeCoverageIgnore Mainly deprecation warnings and other things that can be tested by running the updater |
11 | */ |
12 | class RegistrationCallback { |
13 | |
14 | public static function onRegistration(): void { |
15 | global $wgAbuseFilterProfile, |
16 | $wgAbuseFilterProfiling, $wgAbuseFilterPrivateLog, $wgAbuseFilterForceSummary, |
17 | $wgGroupPermissions, $wgAbuseFilterRestrictions, $wgAbuseFilterDisallowGlobalLocalBlocks, |
18 | $wgAbuseFilterActionRestrictions, $wgAbuseFilterLocallyDisabledGlobalActions, |
19 | $wgAbuseFilterActorTableSchemaMigrationStage; |
20 | |
21 | // @todo Remove this in a future release (added in 1.33) |
22 | if ( isset( $wgAbuseFilterProfile ) || isset( $wgAbuseFilterProfiling ) ) { |
23 | wfWarn( '$wgAbuseFilterProfile and $wgAbuseFilterProfiling have been removed and ' . |
24 | 'profiling is now enabled by default.' ); |
25 | } |
26 | |
27 | if ( isset( $wgAbuseFilterPrivateLog ) ) { |
28 | global $wgAbuseFilterLogPrivateDetailsAccess; |
29 | $wgAbuseFilterLogPrivateDetailsAccess = $wgAbuseFilterPrivateLog; |
30 | wfWarn( '$wgAbuseFilterPrivateLog has been renamed to $wgAbuseFilterLogPrivateDetailsAccess. ' . |
31 | 'Please make the change in your settings; the format is identical.' |
32 | ); |
33 | } |
34 | if ( isset( $wgAbuseFilterForceSummary ) ) { |
35 | global $wgAbuseFilterPrivateDetailsForceReason; |
36 | $wgAbuseFilterPrivateDetailsForceReason = $wgAbuseFilterForceSummary; |
37 | wfWarn( '$wgAbuseFilterForceSummary has been renamed to ' . |
38 | '$wgAbuseFilterPrivateDetailsForceReason. Please make the change in your settings; ' . |
39 | 'the format is identical.' |
40 | ); |
41 | } |
42 | |
43 | $found = false; |
44 | foreach ( $wgGroupPermissions as &$perms ) { |
45 | if ( array_key_exists( 'abusefilter-private', $perms ) ) { |
46 | $perms['abusefilter-privatedetails'] = $perms[ 'abusefilter-private' ]; |
47 | unset( $perms[ 'abusefilter-private' ] ); |
48 | $found = true; |
49 | } |
50 | if ( array_key_exists( 'abusefilter-private-log', $perms ) ) { |
51 | $perms['abusefilter-privatedetails-log'] = $perms[ 'abusefilter-private-log' ]; |
52 | unset( $perms[ 'abusefilter-private-log' ] ); |
53 | $found = true; |
54 | } |
55 | } |
56 | unset( $perms ); |
57 | |
58 | if ( $found ) { |
59 | wfWarn( 'The group permissions "abusefilter-private-log" and "abusefilter-private" have ' . |
60 | 'been renamed, respectively, to "abusefilter-privatedetails-log" and ' . |
61 | '"abusefilter-privatedetails". Please update the names in your settings.' |
62 | ); |
63 | } |
64 | |
65 | // @todo Remove this in a future release (added in 1.36) |
66 | if ( isset( $wgAbuseFilterDisallowGlobalLocalBlocks ) ) { |
67 | wfWarn( '$wgAbuseFilterDisallowGlobalLocalBlocks has been removed and replaced by ' . |
68 | '$wgAbuseFilterLocallyDisabledGlobalActions. You can now specify which actions to disable. ' . |
69 | 'If you had set the former to true, you should set to true all of the actions in ' . |
70 | '$wgAbuseFilterRestrictions (if you were manually setting the variable) or ' . |
71 | 'ConsequencesRegistry::DANGEROUS_ACTIONS. ' . |
72 | 'If you had set it to false (or left the default), just remove it from your wiki settings.' |
73 | ); |
74 | if ( $wgAbuseFilterDisallowGlobalLocalBlocks === true ) { |
75 | $wgAbuseFilterLocallyDisabledGlobalActions = [ |
76 | 'throttle' => false, |
77 | 'warn' => false, |
78 | 'disallow' => false, |
79 | 'blockautopromote' => true, |
80 | 'block' => true, |
81 | 'rangeblock' => true, |
82 | 'degroup' => true, |
83 | 'tag' => false |
84 | ]; |
85 | } |
86 | } |
87 | |
88 | // @todo Remove this in a future release (added in 1.36) |
89 | if ( isset( $wgAbuseFilterRestrictions ) ) { |
90 | wfWarn( '$wgAbuseFilterRestrictions has been renamed to $wgAbuseFilterActionRestrictions.' ); |
91 | $wgAbuseFilterActionRestrictions = $wgAbuseFilterRestrictions; |
92 | } |
93 | |
94 | // in order |
95 | $allowedStages = [ |
96 | SCHEMA_COMPAT_OLD, |
97 | SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD, |
98 | SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW, |
99 | SCHEMA_COMPAT_NEW, |
100 | ]; |
101 | if ( !in_array( $wgAbuseFilterActorTableSchemaMigrationStage, $allowedStages ) ) { |
102 | throw new InvalidArgumentException( |
103 | '$wgAbuseFilterActorTableSchemaMigrationStage must specify a supported ' . |
104 | 'combination of schema compatibility flags' |
105 | ); |
106 | } |
107 | } |
108 | |
109 | } |