Werdna has uploaded a new change for review.
https://gerrit.wikimedia.org/r/80159
Change subject: Work in Progress: Replace condition limit with a time limit.
......................................................................
Work in Progress: Replace condition limit with a time limit.
Change-Id: I6b6b3718d417f48496825062cd11b3ea611accd3
---
M AbuseFilter.class.php
M AbuseFilter.php
2 files changed, 38 insertions(+), 4 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/AbuseFilter
refs/changes/59/80159/1
diff --git a/AbuseFilter.class.php b/AbuseFilter.class.php
index 488521c..9fd6258 100644
--- a/AbuseFilter.class.php
+++ b/AbuseFilter.class.php
@@ -6,6 +6,7 @@
public static $modifyCache = array();
public static $condLimitEnabled = true;
public static $condCount = 0;
+ public static $startTime = false;
public static $filters = array();
public static $tagsToSet = array();
public static $history_mappings = array(
@@ -277,11 +278,35 @@
public static function triggerLimiter( $val = 1 ) {
self::$condCount += $val;
- global $wgAbuseFilterConditionLimit;
+ global $wgAbuseFilterConditionLimit,
+ $wgAbuseFilterTimeLimit;
- if ( self::$condLimitEnabled && self::$condCount >
$wgAbuseFilterConditionLimit ) {
+ if (
+ self::$condLimitEnabled &&
+ $wgAbuseFilterConditionLimit > 0 &&
+ self::$condCount > $wgAbuseFilterConditionLimit) {
throw new MWException( 'Condition limit reached.' );
}
+
+ $time = self::getMicroTime();
+
+ if (
+ $wgAbuseFilterTimeLimit &&
+ ( $time - self::$startTime ) > $wgAbuseFilterTimeLimit
+ ) {
+ throw new MWException( "Time limit reached." );
+ }
+ }
+
+ public static function getMicroTime() {
+ if ( function_exists( 'getrusage' ) ) {
+ $rusage = getrusage();
+ $time = $rusage['ru_utime.tv_usec'] * 1e3;
+ } else {
+ $time = microtime( true );
+ }
+
+ return $time;
}
public static function disableConditionLimit() {
@@ -844,6 +869,9 @@
// Add vars from extensions
wfRunHooks( 'AbuseFilter-filterAction', array( &$vars, $title )
);
+ // Store start time
+ self::$startTime = self::getMicroTime();
+
// Set context
$vars->setVar( 'context', 'filter' );
$vars->setVar( 'timestamp', time() );
@@ -853,6 +881,8 @@
$filter_matched = self::checkAllFilters( $vars, $group );
$matched_filters = array_keys( array_filter( $filter_matched )
);
+
+ self::$startTime = false;
// Short-cut any remaining code if no filters were hit.
if ( count( $matched_filters ) == 0 ) {
@@ -1501,12 +1531,13 @@
* @param $group
*/
public static function recordStats( $filters, $group = 'default' ) {
- global $wgAbuseFilterConditionLimit, $wgMemc;
+ global $wgAbuseFilterConditionLimit, $wgMemc,
$wgAbuseFilterTimeLimit;
wfProfileIn( __METHOD__ );
// Figure out if we've triggered overflows and blocks.
- $overflow_triggered = ( self::$condCount >
$wgAbuseFilterConditionLimit );
+ $overflow_triggered = ( self::$condCount >
$wgAbuseFilterConditionLimit ) ||
+ ( self::getMicroTime() - self::$startTime ) >
$wgAbuseFilterTimeLimit;
// Store some keys...
$overflow_key = self::filterLimitReachedKey();
diff --git a/AbuseFilter.php b/AbuseFilter.php
index 1b0a55a..25cb9a8 100644
--- a/AbuseFilter.php
+++ b/AbuseFilter.php
@@ -171,6 +171,9 @@
$wgAbuseFilterConditionLimit = 1000;
+// Allowed user time, in milliseconds, for the running of all filters
+$wgAbuseFilterTimeLimit = 1000;
+
// Disable filters if they match more than X edits, constituting more than Y%
of the last Z edits, if they have been changed in the last S seconds
$wgAbuseFilterEmergencyDisableThreshold['default'] = 0.05;
$wgAbuseFilterEmergencyDisableCount['default'] = 2;
--
To view, visit https://gerrit.wikimedia.org/r/80159
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6b6b3718d417f48496825062cd11b3ea611accd3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/AbuseFilter
Gerrit-Branch: master
Gerrit-Owner: Werdna <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits