Deprecates $wgRateLimitLog in favor of debug log
authorAntoine Musso <hashar@free.fr>
Thu, 27 Feb 2014 13:37:33 +0000 (14:37 +0100)
committerIAlex <codereview@emsenhuber.ch>
Tue, 4 Mar 2014 13:12:35 +0000 (13:12 +0000)
$wgRateLimitLog is meant to log rate limiting occuring in MediaWiki. The
feature was introduced by e46d19e72d3 / r9202 in 2005.  We might not
have wfDebugLog() at that time and we used error_log() with the global
pointing to a file.  A later patch converted to file_put_contents().

On Wikimedia production the variable is set to a udp:// URL, I am not
sure file_put_contents() can write to it.  Additionally the warning are
suppressed which I tend to hate.

Instead use the log bucket 'ratelimit'.

For backcompabitilibity purposes, if $wgRateLmitLog is still set:
attempt to set $wgDebugLogGroup['ratelimit'] with its value.

Change-Id: I86131c4a8053800afd9f41fa1906c998a88736c6

includes/DefaultSettings.php
includes/Setup.php
includes/User.php

index 1dae5e7..4ad2188 100644 (file)
@@ -4739,6 +4739,8 @@ $wgRateLimits = array(
 
 /**
  * Set to a filename to log rate limiter hits.
+ *
+ * @deprecated since 1.23, use $wgDebugLogGroups['ratelimit'] instead
  */
 $wgRateLimitLog = null;
 
index 0ae6e9b..209edef 100644 (file)
@@ -452,6 +452,11 @@ if ( !$wgHTCPRouting && $wgHTCPMulticastAddress ) {
        );
 }
 
+// Back compatibility for $wgRateLimitLog deprecated with 1.23
+if ( $wgRateLimitLog && ! array_key_exists( 'ratelimit', $wgDebugLogGroups ) ) {
+       $wgDebugLogGroups['ratelimit'] = $wgRateLimitLog;
+}
+
 wfProfileOut( $fname . '-defaults2' );
 wfProfileIn( $fname . '-misc1' );
 
index 0b28f66..e728323 100644 (file)
@@ -1602,7 +1602,7 @@ class User {
                        return false;
                }
 
-               global $wgMemc, $wgRateLimitLog;
+               global $wgMemc;
                wfProfileIn( __METHOD__ );
 
                $limits = $wgRateLimits[$action];
@@ -1665,12 +1665,7 @@ class User {
                        // Already pinged?
                        if ( $count ) {
                                if ( $count >= $max ) {
-                                       wfDebug( __METHOD__ . ": tripped! $key at $count $summary\n" );
-                                       if ( $wgRateLimitLog ) {
-                                               wfSuppressWarnings();
-                                               file_put_contents( $wgRateLimitLog, wfTimestamp( TS_MW ) . ' ' . wfWikiID() . ': ' . $this->getName() . " tripped $key at $count $summary\n", FILE_APPEND );
-                                               wfRestoreWarnings();
-                                       }
+                                       wfDebugLog( 'ratelimit', $this->getName() . " tripped! $key at $count $summary");
                                        $triggered = true;
                                } else {
                                        wfDebug( __METHOD__ . ": ok. $key at $count $summary\n" );