Bartosz Dziewoński has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/282387

Change subject: Add $wgAbuseFilterProfile to enable filter profiling
......................................................................

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
---
M AbuseFilter.class.php
M AbuseFilter.php
M Views/AbuseFilterViewEdit.php
M i18n/en.json
M i18n/qqq.json
5 files changed, 22 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/AbuseFilter 
refs/changes/87/282387/1

diff --git a/AbuseFilter.class.php b/AbuseFilter.class.php
index b2b64bd..92dd2f8 100755
--- a/AbuseFilter.class.php
+++ b/AbuseFilter.class.php
@@ -521,10 +521,12 @@
         * @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 @@
                        $result = false;
                }
 
-               if ( $profile ) {
+               if ( $profile && $wgAbuseFilterProfile ) {
                        $endTime = microtime( true );
                        $endConds = self::$condCount;
 
diff --git a/AbuseFilter.php b/AbuseFilter.php
index 12a8fc6..d225e59 100644
--- a/AbuseFilter.php
+++ b/AbuseFilter.php
@@ -239,3 +239,6 @@
 // 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 dac4680..7e0ff52 100755
--- a/Views/AbuseFilterViewEdit.php
+++ b/Views/AbuseFilterViewEdit.php
@@ -387,17 +387,22 @@
 
                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 1cfc7cc..3093e17 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -127,7 +127,8 @@
        "abusefilter-edit-subtitle-new": "Creating filter",
        "abusefilter-edit-oldwarning": "<strong>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.</strong> 
&bull;\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 bbbde05..3a505f2 100755
--- 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.",

-- 
To view, visit https://gerrit.wikimedia.org/r/282387
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1ecaedd7489b264ed621309b6fbfb63b9287a437
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/AbuseFilter
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to