r46376 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r46375‎ | r46376 | r46377 >
Date:20:18, 27 January 2009
Author:werdna
Status:ok
Tags:
Comment:
Soften emergency disable feature, by making it only block restricted actions, rather than disabling the whole filter.
Modified paths:
  • /trunk/extensions/AbuseFilter/AbuseFilter.class.php (modified) (history)
  • /trunk/extensions/AbuseFilter/AbuseFilter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/AbuseFilter/AbuseFilter.php
@@ -84,3 +84,4 @@
8585 $wgAbuseFilterStyleVersion = 2;
8686
8787 $wgAbuseFilterRestrictedActions = array( 'block', 'degroup' );
 88+
Index: trunk/extensions/AbuseFilter/AbuseFilter.class.php
@@ -192,14 +192,19 @@
193193 public static function executeFilterActions( $filters, $title, $vars ) {
194194 $dbr = wfGetDB( DB_SLAVE );
195195 // Retrieve the consequences.
196 - $res = $dbr->select( 'abuse_filter_action', '*', array( 'afa_filter' => $filters ), __METHOD__ );
 196+ $res = $dbr->select( array('abuse_filter_action', 'abuse_filter'), '*', array( 'af_id' => $filters ), __METHOD__, array(), array( 'abuse_filter_action' => array('LEFT JOIN', 'afa_filter=af_id') ) );
197197
198198 $actionsByFilter = array_fill_keys( $filters, array() );
199199 $actionsTaken = array_fill_keys( $filters, array() );
200200
201201 // Categorise consequences by filter.
 202+ global $wgAbuseFilterRestrictedActions;
202203 while ( $row = $dbr->fetchObject( $res ) ) {
203 - $actionsByFilter[$row->afa_filter][$row->afa_consequence] = array( 'action' => $row->afa_consequence, 'parameters' => explode( "\n", $row->afa_parameters ) );
 204+ if ( $row->af_throttled && in_array( $row->afa_consequence, $wgAbuseFilterRestrictedActions ) ) {
 205+ ## Don't do the action
 206+ } else {
 207+ $actionsByFilter[$row->afa_filter][$row->afa_consequence] = array( 'action' => $row->afa_consequence, 'parameters' => explode( "\n", $row->afa_parameters ) );
 208+ }
204209 }
205210
206211 wfLoadExtensionMessages( 'AbuseFilter' );
@@ -560,7 +565,7 @@
561566 return; // The rest will only apply if a filter was triggered.
562567 }
563568
564 - self::checkEmergencyDisable( $filters );
 569+ self::checkEmergencyDisable( $filters, $total );
565570
566571 // Increment trigger counter
567572 if ($filter_triggered) {
@@ -573,7 +578,7 @@
574579 $dbw->update( 'abuse_filter', array( 'af_hit_count=af_hit_count+1' ), array( 'af_id' => array_keys( array_filter( $filters ) ) ), __METHOD__ );
575580 }
576581
577 - public static function checkEmergencyDisable( $filters ) {
 582+ public static function checkEmergencyDisable( $filters, $total ) {
578583 global $wgAbuseFilterEmergencyDisableThreshold, $wgAbuseFilterEmergencyDisableCount, $wgAbuseFilterEmergencyDisableAge, $wgMemc;
579584
580585 foreach( $filters as $filter => $matched ) {
@@ -593,10 +598,10 @@
594599 $filter_age = wfTimestamp( TS_UNIX, self::$filters[$filter]->af_timestamp );
595600 $throttle_exempt_time = $filter_age + $wgAbuseFilterEmergencyDisableAge;
596601
597 - if ($throttle_exempt_time > time() && $matchCount > $wgAbuseFilterEmergencyDisableCount && ($matchCount / $total) > $wgAbuseFilterEmergencyDisableThreshold) {
 602+ if ($total && $throttle_exempt_time > time() && $matchCount > $wgAbuseFilterEmergencyDisableCount && ($matchCount / $total) > $wgAbuseFilterEmergencyDisableThreshold) {
598603 // More than $wgAbuseFilterEmergencyDisableCount matches, constituting more than $wgAbuseFilterEmergencyDisableThreshold (a fraction) of last few edits. Disable it.
599604 $dbw = wfGetDB( DB_MASTER );
600 - $dbw->update( 'abuse_filter', array( 'af_enabled' => 0, 'af_throttled' => 1 ), array( 'af_id' => $filter ), __METHOD__ );
 605+ $dbw->update( 'abuse_filter', array( 'af_throttled' => 1 ), array( 'af_id' => $filter ), __METHOD__ );
601606 }
602607 }
603608 }

Status & tagging log