mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-23 21:53:35 +00:00
Change some globals to work better with extension registration
Rename $wgAbuseFilterAvailableActions / $wgAbuseFilterRestrictedActions to $wgAbuseFilterActions / $wgAbuseFilterRestrictions and make them an associative array instead of a plain one, as that works more sanely with extension registration. (The renaming helps to give more useful errors to sites using the old config.) Change-Id: I790d39c2849922d7daf7479f298cd90cf30af129
This commit is contained in:
parent
d527574d2b
commit
6a2627e944
|
@ -705,10 +705,10 @@ class AbuseFilter {
|
|||
);
|
||||
|
||||
// Categorise consequences by filter.
|
||||
global $wgAbuseFilterRestrictedActions;
|
||||
global $wgAbuseFilterRestrictions;
|
||||
foreach ( $res as $row ) {
|
||||
if ( $row->af_throttled
|
||||
&& in_array( $row->afa_consequence, $wgAbuseFilterRestrictedActions )
|
||||
&& !empty( $wgAbuseFilterRestrictions[$row->afa_consequence] )
|
||||
) {
|
||||
# Don't do the action
|
||||
} elseif ( $row->afa_filter != $row->af_id ) {
|
||||
|
@ -744,7 +744,7 @@ class AbuseFilter {
|
|||
|
||||
$messages = array();
|
||||
|
||||
global $wgOut, $wgAbuseFilterDisallowGlobalLocalBlocks, $wgAbuseFilterRestrictedActions;
|
||||
global $wgOut, $wgAbuseFilterDisallowGlobalLocalBlocks, $wgAbuseFilterRestrictions;
|
||||
foreach ( $actionsByFilter as $filter => $actions ) {
|
||||
// Special-case handling for warnings.
|
||||
$parsed_public_comments = $wgOut->parseInline(
|
||||
|
@ -775,9 +775,7 @@ class AbuseFilter {
|
|||
}
|
||||
|
||||
if ( $wgAbuseFilterDisallowGlobalLocalBlocks && $global_filter ) {
|
||||
foreach ( $wgAbuseFilterRestrictedActions as $blockingAction ) {
|
||||
unset( $actions[$blockingAction] );
|
||||
}
|
||||
$actions = array_diff_key( $actions, array_filter( $wgAbuseFilterRestrictions ) );
|
||||
}
|
||||
|
||||
if ( !empty( $actions['warn'] ) ) {
|
||||
|
@ -812,7 +810,7 @@ class AbuseFilter {
|
|||
}
|
||||
|
||||
// prevent double warnings
|
||||
if ( count( array_intersect( array_keys( $actions ), $wgAbuseFilterRestrictedActions ) ) > 0 &&
|
||||
if ( count( array_intersect_key( $actions, array_filter( $wgAbuseFilterRestrictions ) ) ) > 0 &&
|
||||
!empty( $actions['disallow'] )
|
||||
) {
|
||||
unset( $actions['disallow'] );
|
||||
|
@ -1880,8 +1878,8 @@ class AbuseFilter {
|
|||
}
|
||||
}
|
||||
|
||||
global $wgAbuseFilterAvailableActions;
|
||||
foreach ( $wgAbuseFilterAvailableActions as $action ) {
|
||||
global $wgAbuseFilterActions;
|
||||
foreach ( array_filter( $wgAbuseFilterActions ) as $action => $_ ) {
|
||||
if ( !isset( $actions1[$action] ) && !isset( $actions2[$action] ) ) {
|
||||
// They're both unset
|
||||
} elseif ( isset( $actions1[$action] ) && isset( $actions2[$action] ) ) {
|
||||
|
|
|
@ -7,6 +7,20 @@ class AbuseFilterHooks {
|
|||
// So far, all of the error message out-params for these hooks accept HTML.
|
||||
// Hooray!
|
||||
|
||||
/**
|
||||
* Called right after configuration has been loaded.
|
||||
*/
|
||||
public static function onRegistration() {
|
||||
global $wgAbuseFilterAvailableActions, $wgAbuseFilterRestrictedActions;
|
||||
|
||||
if ( isset( $wgAbuseFilterAvailableActions ) || isset( $wgAbuseFilterRestrictedActions ) ) {
|
||||
wfWarn( '$wgAbuseFilterAvailableActions and $wgAbuseFilterRestrictedActions have been'
|
||||
. 'removed. Please use $wgAbuseFilterActions and $wgAbuseFilterRestrictions'
|
||||
. 'instead. The format is the same except the action names are the keys of the'
|
||||
. 'array and the values are booleans.' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point for the APIEditBeforeSave hook.
|
||||
*
|
||||
|
|
|
@ -32,11 +32,13 @@ if ( function_exists( 'wfLoadExtension' ) ) {
|
|||
// This code is never executed.
|
||||
|
||||
/**
|
||||
* The possible actions that can be taken by abuse filters. Additional possible actions:
|
||||
* 'rangeblock'
|
||||
* @var string[]
|
||||
* The possible actions that can be taken by abuse filters.
|
||||
*
|
||||
* @var array [action name => is enabled?] At the end of setup, false values will be filtered out
|
||||
*/
|
||||
$wgAbuseFilterAvailableActions = [ /* See extension.json */ ];
|
||||
$wgAbuseFilterActions = [ /* See extension.json */ ];
|
||||
|
||||
$wgAbuseFilterAvailableActions = 'REMOVED'; // use $wgAbuseFilterActions instead
|
||||
|
||||
/**
|
||||
* The maximum number of 'conditions' that can be used each time the filters are run against a
|
||||
|
@ -58,10 +60,14 @@ $wgAbuseFilterEmergencyDisableAge['default'] = 86400; // One day.
|
|||
$wgAbuseFilterParserClass = 'AbuseFilterParser';
|
||||
|
||||
/**
|
||||
* Users must have the "abusefilter-modify-restricted" user right as well as "abusefilter-modify"
|
||||
* in order to create or modify filters which carry out these actions.
|
||||
* Do users need "abusefilter-modify-restricted" user right as well as "abusefilter-modify"
|
||||
* in order to create or modify filters which carry out this action?
|
||||
*
|
||||
* @var array action name => is restricted?
|
||||
*/
|
||||
$wgAbuseFilterRestrictedActions = [ /* See extension.json */ ];
|
||||
$wgAbuseFilterRestrictions = [ /* See extension.json */ ];
|
||||
|
||||
$wgAbuseFilterRestrictedActions = 'REMOVED'; // use $wgAbuseFilterRestrictions instead
|
||||
|
||||
/**
|
||||
* Allows to configure the extension to send hit notifications to Special:RecentChanges or UDP.
|
||||
|
|
|
@ -84,16 +84,13 @@ class AbuseFilterViewEdit extends AbuseFilterView {
|
|||
}
|
||||
|
||||
// Check for restricted actions
|
||||
global $wgAbuseFilterRestrictedActions;
|
||||
$allActions = array_keys( array_merge(
|
||||
array_filter( $actions ),
|
||||
array_filter( $origActions )
|
||||
) );
|
||||
|
||||
if (
|
||||
count( array_intersect(
|
||||
$wgAbuseFilterRestrictedActions,
|
||||
$allActions
|
||||
global $wgAbuseFilterRestrictions;
|
||||
if ( count( array_intersect_key(
|
||||
array_filter( $wgAbuseFilterRestrictions ),
|
||||
array_merge(
|
||||
array_filter( $actions ),
|
||||
array_filter( $origActions )
|
||||
)
|
||||
) )
|
||||
&& !$user->isAllowed( 'abusefilter-modify-restricted' )
|
||||
) {
|
||||
|
@ -166,10 +163,10 @@ class AbuseFilterViewEdit extends AbuseFilterView {
|
|||
}
|
||||
|
||||
// Actions
|
||||
global $wgAbuseFilterAvailableActions;
|
||||
global $wgAbuseFilterActions;
|
||||
$deadActions = array();
|
||||
$actionsRows = array();
|
||||
foreach ( $wgAbuseFilterAvailableActions as $action ) {
|
||||
foreach ( array_filter( $wgAbuseFilterActions ) as $action => $_ ) {
|
||||
// Check if it's set
|
||||
$enabled = isset( $actions[$action] ) && (bool)$actions[$action];
|
||||
|
||||
|
@ -560,16 +557,18 @@ class AbuseFilterViewEdit extends AbuseFilterView {
|
|||
* @return HTML text for an action editor.
|
||||
*/
|
||||
function buildConsequenceEditor( $row, $actions ) {
|
||||
global $wgAbuseFilterAvailableActions;
|
||||
global $wgAbuseFilterActions;
|
||||
|
||||
$enabledActions = array_filter( $wgAbuseFilterActions );
|
||||
|
||||
$setActions = array();
|
||||
foreach ( $wgAbuseFilterAvailableActions as $action ) {
|
||||
foreach ( $enabledActions as $action => $_ ) {
|
||||
$setActions[$action] = array_key_exists( $action, $actions );
|
||||
}
|
||||
|
||||
$output = '';
|
||||
|
||||
foreach ( $wgAbuseFilterAvailableActions as $action ) {
|
||||
foreach ( $enabledActions as $action => $_ ) {
|
||||
MediaWiki\suppressWarnings();
|
||||
$params = $actions[$action]['parameters'];
|
||||
MediaWiki\restoreWarnings();
|
||||
|
@ -588,9 +587,9 @@ class AbuseFilterViewEdit extends AbuseFilterView {
|
|||
* @return string
|
||||
*/
|
||||
function buildConsequenceSelector( $action, $set, $parameters, $row ) {
|
||||
global $wgAbuseFilterAvailableActions, $wgMainCacheType;
|
||||
global $wgAbuseFilterActions, $wgMainCacheType;
|
||||
|
||||
if ( !in_array( $action, $wgAbuseFilterAvailableActions ) ) {
|
||||
if ( empty( $wgAbuseFilterActions[$action] ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
|
@ -947,9 +946,9 @@ class AbuseFilterViewEdit extends AbuseFilterView {
|
|||
$row->af_global = $request->getBool( 'wpFilterGlobal' ) && $wgAbuseFilterIsCentral;
|
||||
|
||||
// Actions
|
||||
global $wgAbuseFilterAvailableActions;
|
||||
global $wgAbuseFilterActions;
|
||||
$actions = array();
|
||||
foreach ( $wgAbuseFilterAvailableActions as $action ) {
|
||||
foreach ( array_filter( $wgAbuseFilterActions ) as $action => $_ ) {
|
||||
// Check if it's set
|
||||
$enabled = $request->getBool( 'wpFilterAction' . ucfirst( $action ) );
|
||||
|
||||
|
|
|
@ -165,6 +165,7 @@
|
|||
"localBasePath": "modules",
|
||||
"remoteExtPath": "AbuseFilter/modules"
|
||||
},
|
||||
"callback": "AbuseFilterHooks::onRegistration",
|
||||
"Hooks": {
|
||||
"EditFilterMergedContent": "AbuseFilterHooks::onEditFilterMergedContent",
|
||||
"GetAutoPromoteGroups": "AbuseFilterHooks::onGetAutoPromoteGroups",
|
||||
|
@ -188,16 +189,18 @@
|
|||
},
|
||||
"config": {
|
||||
"@doc": "see AbuseFilter.php",
|
||||
"AbuseFilterAvailableActions": [
|
||||
"flag",
|
||||
"throttle",
|
||||
"warn",
|
||||
"disallow",
|
||||
"blockautopromote",
|
||||
"block",
|
||||
"degroup",
|
||||
"tag"
|
||||
],
|
||||
"AbuseFilterActions": {
|
||||
"flag": true,
|
||||
"throttle": true,
|
||||
"warn": true,
|
||||
"disallow": true,
|
||||
"blockautopromote": true,
|
||||
"block": true,
|
||||
"rangeblock": false,
|
||||
"degroup": true,
|
||||
"tag": true,
|
||||
"_merge_strategy": "array_plus"
|
||||
},
|
||||
"AbuseFilterConditionLimit": 1000,
|
||||
"AbuseFilterEmergencyDisableThreshold": {
|
||||
"default": 0.05,
|
||||
|
@ -212,12 +215,18 @@
|
|||
"_merge_strategy": "array_plus"
|
||||
},
|
||||
"AbuseFilterParserClass": "AbuseFilterParser",
|
||||
"AbuseFilterRestrictedActions": [
|
||||
"block",
|
||||
"degroup",
|
||||
"blockautopromote",
|
||||
"rangeblock"
|
||||
],
|
||||
"AbuseFilterRestrictions": {
|
||||
"flag": false,
|
||||
"throttle": false,
|
||||
"warn": false,
|
||||
"disallow": false,
|
||||
"blockautopromote": true,
|
||||
"block": true,
|
||||
"rangeblock": true,
|
||||
"degroup": true,
|
||||
"tag": false,
|
||||
"_merge_strategy": "array_plus"
|
||||
},
|
||||
"AbuseFilterNotifications": false,
|
||||
"AbuseFilterNotificationsPrivate": false,
|
||||
"AbuseFilterCentralDB": null,
|
||||
|
|
Loading…
Reference in a new issue