From 337cad30d9c66bbc09e3b5577e4d54fddbacc2c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Fri, 8 Apr 2016 18:22:39 +0200 Subject: [PATCH] Add $wgAbuseFilterProfile to enable filter profiling Follow-up to b60829a60cbd3cbe58968cf3db72f87a68715567. I'll fix up message translations on Translatewiki when this is merged. Bug: T132189 Change-Id: I1ecaedd7489b264ed621309b6fbfb63b9287a437 --- AbuseFilter.class.php | 6 ++++-- AbuseFilter.php | 3 +++ Views/AbuseFilterViewEdit.php | 17 +++++++++++------ i18n/en.json | 3 ++- i18n/qqq.json | 3 ++- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/AbuseFilter.class.php b/AbuseFilter.class.php index b2b64bda8..92dd2f881 100644 --- a/AbuseFilter.class.php +++ b/AbuseFilter.class.php @@ -521,10 +521,12 @@ class AbuseFilter { * @return bool */ public static function checkFilter( $row, $vars, $profile = false, $prefix = '' ) { + global $wgAbuseFilterProfile; + $filterID = $prefix . $row->af_id; $startConds = $startTime = null; - if ( $profile ) { + if ( $profile && $wgAbuseFilterProfile ) { $startConds = self::$condCount; $startTime = microtime( true ); } @@ -548,7 +550,7 @@ class AbuseFilter { $result = false; } - if ( $profile ) { + if ( $profile && $wgAbuseFilterProfile ) { $endTime = microtime( true ); $endConds = self::$condCount; diff --git a/AbuseFilter.php b/AbuseFilter.php index 12a8fc687..d225e5904 100644 --- a/AbuseFilter.php +++ b/AbuseFilter.php @@ -239,3 +239,6 @@ $wgAbuseFilterDefaultWarningMessage = array( // Age used as cutoff when purging old IP log data. // Used by maintenance script purgeOldLogIPData.php $wgAbuseFilterLogIPMaxAge = 3 * 30 * 24 * 3600; // 3 months + +// Whether to record the time taken and number of conditions used by each filter. +$wgAbuseFilterProfile = false; diff --git a/Views/AbuseFilterViewEdit.php b/Views/AbuseFilterViewEdit.php index dac4680d3..7e0ff523d 100644 --- a/Views/AbuseFilterViewEdit.php +++ b/Views/AbuseFilterViewEdit.php @@ -387,17 +387,22 @@ class AbuseFilterViewEdit extends AbuseFilterView { if ( $filter !== 'new' ) { // Statistics - global $wgMemc; + global $wgMemc, $wgAbuseFilterProfile; $matches_count = $wgMemc->get( AbuseFilter::filterMatchesKey( $filter ) ); $total = $wgMemc->get( AbuseFilter::filterUsedKey( $row->af_group ) ); if ( $total > 0 ) { $matches_percent = sprintf( '%.2f', 100 * $matches_count / $total ); - list( $timeProfile, $condProfile ) = AbuseFilter::getFilterProfile( $filter ); - - $fields['abusefilter-edit-status-label'] = $this->msg( 'abusefilter-edit-status' ) - ->numParams( $total, $matches_count, $matches_percent, $timeProfile, $condProfile ) - ->escaped(); + if ( $wgAbuseFilterProfile ) { + list( $timeProfile, $condProfile ) = AbuseFilter::getFilterProfile( $filter ); + $fields['abusefilter-edit-status-label'] = $this->msg( 'abusefilter-edit-status-profile' ) + ->numParams( $total, $matches_count, $matches_percent, $timeProfile, $condProfile ) + ->escaped(); + } else { + $fields['abusefilter-edit-status-label'] = $this->msg( 'abusefilter-edit-status' ) + ->numParams( $total, $matches_count, $matches_percent ) + ->escaped(); + } } } diff --git a/i18n/en.json b/i18n/en.json index 1cfc7cc11..3093e172e 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -127,7 +127,8 @@ "abusefilter-edit-subtitle-new": "Creating filter", "abusefilter-edit-oldwarning": "You are editing an old version of this filter.\nThe statistics quoted are for the most recent version of the filter.\nIf you save your changes, you will overwrite all changes since the revision you are editing. •\n[[Special:AbuseFilter/history/$2|Return to this filter's history]].", "abusefilter-edit-status-label": "Statistics:", - "abusefilter-edit-status": "Of the last $1 {{PLURAL:$1|action|actions}}, this filter has matched $2 ($3%).\nOn average, its run time is $4 ms, and it consumes $5 {{PLURAL:$5|condition|conditions}} of the condition limit.", + "abusefilter-edit-status": "Of the last $1 {{PLURAL:$1|action|actions}}, this filter has matched $2 ($3%).", + "abusefilter-edit-status-profile": "Of the last $1 {{PLURAL:$1|action|actions}}, this filter has matched $2 ($3%).\nOn average, its run time is $4 ms, and it consumes $5 {{PLURAL:$5|condition|conditions}} of the condition limit.", "abusefilter-edit-throttled": "'''Warning:''' This filter was automatically disabled as a safety measure.\nIt reached the limit of matching more than $1% of actions.", "abusefilter-edit-new": "New filter", "abusefilter-edit-save": "Save filter", diff --git a/i18n/qqq.json b/i18n/qqq.json index bbbde0557..3a505f23f 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -157,7 +157,8 @@ "abusefilter-edit-subtitle-new": "Page subtitle when creating an abuse filter. Parameters:\n* $1 - (Unused) filter ID\n* $2 - (Unused) history ID\nSee also:\n* {{msg-mw|Abusefilter-edit-subtitle}} - if editing the existing filter", "abusefilter-edit-oldwarning": "Warning displayed when editing an older version of a filter. Parameters:\n* $1 - (Unused) history ID\n* $2 - filter ID", "abusefilter-edit-status-label": "Field label for abuse filter statistics.\n{{Identical|Statistics}}", - "abusefilter-edit-status": "Parameters:\n* $1 - number of actions\n* $2 - matched count\n* $3 - matched percentage\n* $4 - time (in milliseconds)\n* $5 - number of conditions", + "abusefilter-edit-status": "Parameters:\n* $1 - number of actions\n* $2 - matched count\n* $3 - matched percentage", + "abusefilter-edit-status-profile": "Parameters:\n* $1 - number of actions\n* $2 - matched count\n* $3 - matched percentage\n* $4 - time (in milliseconds)\n* $5 - number of conditions", "abusefilter-edit-throttled": "Used as warning message. Parameters:\n* $1 - threshold percentage", "abusefilter-edit-new": "Field value in case an edited filter is new.", "abusefilter-edit-save": "Submit button text to save a filter.",