mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-27 23:40:19 +00:00
Properly integrate $wgAbuseFilterValidGroups
The concept of different AbuseFilter groups had not properly been integrated, but should be now: - The total number of matches is now group-specific - .. Which will also fix the emergency shutdown calculations - And a portion of incorrect code (involving $logged_local_filters) has been fixed (action != group) Change-Id: I091199a9d74aee47dcb3d8942394a28e0ffd3234
This commit is contained in:
parent
0f8926348a
commit
0c174aec42
|
@ -441,7 +441,7 @@ class AbuseFilter {
|
|||
}
|
||||
|
||||
// Update statistics, and disable filters which are over-blocking.
|
||||
self::recordStats( $filter_matched );
|
||||
self::recordStats( $filter_matched, $group );
|
||||
|
||||
wfProfileOut( __METHOD__ );
|
||||
|
||||
|
@ -769,9 +769,10 @@ class AbuseFilter {
|
|||
/**
|
||||
* @param $vars AbuseFilterVariableHolder
|
||||
* @param $title Title
|
||||
* @param $group string
|
||||
* @return bool
|
||||
*/
|
||||
public static function filterAction( $vars, $title ) {
|
||||
public static function filterAction( $vars, $title, $group = 'default' ) {
|
||||
global $wgUser, $wgTitle, $wgRequest;
|
||||
|
||||
wfProfileIn( __METHOD__ );
|
||||
|
@ -789,7 +790,7 @@ class AbuseFilter {
|
|||
|
||||
$dbr = wfGetDB( DB_SLAVE );
|
||||
|
||||
$filter_matched = self::checkAllFilters( $vars );
|
||||
$filter_matched = self::checkAllFilters( $vars, $group );
|
||||
|
||||
$matched_filters = array_keys( array_filter( $filter_matched ) );
|
||||
|
||||
|
@ -821,7 +822,7 @@ class AbuseFilter {
|
|||
$log_template['afl_user_text'] = $vars->getVar( 'accountname' )->toString();
|
||||
}
|
||||
|
||||
self::addLogEntries( $actions_taken, $log_template, $action, $vars );
|
||||
self::addLogEntries( $actions_taken, $log_template, $action, $vars, $group );
|
||||
|
||||
$error_msg = $error_msg == '' ? true : $error_msg;
|
||||
|
||||
|
@ -839,7 +840,7 @@ class AbuseFilter {
|
|||
* @param $vars AbuseFilterVariableHolder
|
||||
* @return mixed
|
||||
*/
|
||||
public static function addLogEntries( $actions_taken, $log_template, $action, $vars ) {
|
||||
public static function addLogEntries( $actions_taken, $log_template, $action, $vars, $group = 'default' ) {
|
||||
wfProfileIn( __METHOD__ );
|
||||
$dbw = wfGetDB( DB_MASTER );
|
||||
|
||||
|
@ -864,7 +865,7 @@ class AbuseFilter {
|
|||
$log_rows[] = $thisLog;
|
||||
|
||||
if ( !$globalIndex ) {
|
||||
$logged_local_filters[$filter] = $action;
|
||||
$logged_local_filters[] = $filter;
|
||||
}
|
||||
|
||||
// Global logging
|
||||
|
@ -932,7 +933,7 @@ class AbuseFilter {
|
|||
// Update hit-counter.
|
||||
$dbw->update( 'abuse_filter',
|
||||
array( 'af_hit_count=af_hit_count+1' ),
|
||||
array( 'af_id' => array_keys( $logged_local_filters ) ),
|
||||
array( 'af_id' => $logged_local_filters ),
|
||||
__METHOD__
|
||||
);
|
||||
}
|
||||
|
@ -967,8 +968,8 @@ class AbuseFilter {
|
|||
$vars->setVar( 'local_log_ids', $local_log_ids );
|
||||
|
||||
// Check for emergency disabling.
|
||||
$total = $wgMemc->get( AbuseFilter::filterUsedKey() );
|
||||
self::checkEmergencyDisable( $logged_local_filters, $total );
|
||||
$total = $wgMemc->get( AbuseFilter::filterUsedKey( $group ) );
|
||||
self::checkEmergencyDisable( $group, $logged_local_filters, $total );
|
||||
|
||||
wfProfileOut( __METHOD__ . '-hitstats' );
|
||||
|
||||
|
@ -1409,8 +1410,9 @@ class AbuseFilter {
|
|||
/**
|
||||
* Update statistics, and disable filters which are over-blocking.
|
||||
* @param $filters
|
||||
* @param $group
|
||||
*/
|
||||
public static function recordStats( $filters ) {
|
||||
public static function recordStats( $filters, $group = 'default' ) {
|
||||
global $wgAbuseFilterConditionLimit, $wgMemc;
|
||||
|
||||
wfProfileIn( __METHOD__ );
|
||||
|
@ -1420,7 +1422,7 @@ class AbuseFilter {
|
|||
|
||||
// Store some keys...
|
||||
$overflow_key = self::filterLimitReachedKey();
|
||||
$total_key = self::filterUsedKey();
|
||||
$total_key = self::filterUsedKey( $group );
|
||||
|
||||
$total = $wgMemc->get( $total_key );
|
||||
|
||||
|
@ -1449,18 +1451,19 @@ class AbuseFilter {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param $group
|
||||
* @param $filters
|
||||
* @param $total
|
||||
*/
|
||||
public static function checkEmergencyDisable( $filters, $total ) {
|
||||
public static function checkEmergencyDisable( $group, $filters, $total ) {
|
||||
global $wgAbuseFilterEmergencyDisableThreshold, $wgAbuseFilterEmergencyDisableCount,
|
||||
$wgAbuseFilterEmergencyDisableAge, $wgMemc;
|
||||
|
||||
foreach ( $filters as $filter => $action ) {
|
||||
foreach ( $filters as $filter ) {
|
||||
// determine emergency disable values for this action
|
||||
$emergencyDisableThreshold = self::getEmergencyValue( $wgAbuseFilterEmergencyDisableThreshold, $action );
|
||||
$filterEmergencyDisableCount = self::getEmergencyValue( $wgAbuseFilterEmergencyDisableCount, $action );
|
||||
$emergencyDisableAge = self::getEmergencyValue( $wgAbuseFilterEmergencyDisableAge, $action );
|
||||
$emergencyDisableThreshold = self::getEmergencyValue( $wgAbuseFilterEmergencyDisableThreshold, $group );
|
||||
$filterEmergencyDisableCount = self::getEmergencyValue( $wgAbuseFilterEmergencyDisableCount, $group );
|
||||
$emergencyDisableAge = self::getEmergencyValue( $wgAbuseFilterEmergencyDisableAge, $group );
|
||||
|
||||
// Increment counter
|
||||
$matchCount = $wgMemc->get( self::filterMatchesKey( $filter ) );
|
||||
|
@ -1497,11 +1500,11 @@ class AbuseFilter {
|
|||
|
||||
/**
|
||||
* @param array $emergencyValue
|
||||
* @param string $action
|
||||
* @param string $group
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getEmergencyValue( array $emergencyValue, $action ) {
|
||||
return isset( $emergencyValue[$action] ) ? $emergencyValue[$action] : $emergencyValue['default'];
|
||||
public static function getEmergencyValue( array $emergencyValue, $group ) {
|
||||
return isset( $emergencyValue[$group] ) ? $emergencyValue[$group] : $emergencyValue['default'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1512,10 +1515,11 @@ class AbuseFilter {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $group The filter's group (as defined in $wgAbuseFilterValidGroups)
|
||||
* @return String
|
||||
*/
|
||||
public static function filterUsedKey() {
|
||||
return wfMemcKey( 'abusefilter', 'stats', 'total' );
|
||||
public static function filterUsedKey( $group = null ) {
|
||||
return wfMemcKey( 'abusefilter', 'stats', 'total', $group );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -373,7 +373,7 @@ class AbuseFilterViewEdit extends AbuseFilterView {
|
|||
// Statistics
|
||||
global $wgMemc;
|
||||
$matches_count = $wgMemc->get( AbuseFilter::filterMatchesKey( $filter ) );
|
||||
$total = $wgMemc->get( AbuseFilter::filterUsedKey() );
|
||||
$total = $wgMemc->get( AbuseFilter::filterUsedKey( $row->af_group ) );
|
||||
|
||||
if ( $total > 0 ) {
|
||||
$matches_percent = sprintf( '%.2f', 100 * $matches_count / $total );
|
||||
|
|
|
@ -138,11 +138,14 @@ class AbuseFilterViewList extends AbuseFilterView {
|
|||
}
|
||||
|
||||
function showStatus() {
|
||||
global $wgMemc, $wgAbuseFilterConditionLimit;
|
||||
global $wgMemc, $wgAbuseFilterConditionLimit, $wgAbuseFilterValidGroups;
|
||||
|
||||
$overflow_count = (int)$wgMemc->get( AbuseFilter::filterLimitReachedKey() );
|
||||
$match_count = (int) $wgMemc->get( AbuseFilter::filterMatchesKey() );
|
||||
$total_count = (int)$wgMemc->get( AbuseFilter::filterUsedKey() );
|
||||
$total_count = 0;
|
||||
foreach ( $wgAbuseFilterValidGroups as $group ) {
|
||||
$total_count += (int)$wgMemc->get( AbuseFilter::filterUsedKey( $group ) );
|
||||
}
|
||||
|
||||
if ( $total_count > 0 ) {
|
||||
$overflow_percent = sprintf( "%.2f", 100 * $overflow_count / $total_count );
|
||||
|
|
Loading…
Reference in a new issue