SpecialEmailUser: Don't increment pingLimiter() just for opening the page
authorKunal Mehta <legoktm@member.fsf.org>
Fri, 6 Oct 2017 07:36:07 +0000 (00:36 -0700)
committerAnomie <bjorsch@wikimedia.org>
Mon, 23 Oct 2017 13:38:09 +0000 (13:38 +0000)
When checking whether the user can even send am email, don't increment
the rate limits since they haven't sent an email yet. Only increment it
once we're fairly sure that the email will actually get sent.

Bug: T177575
Change-Id: I3f832accd6259c040438ebee4c94847faa108ea6

includes/specials/SpecialEmailuser.php

index 249be7f..30eb38d 100644 (file)
@@ -280,7 +280,9 @@ class SpecialEmailUser extends UnlistedSpecialPage {
                        return "blockedemailuser";
                }
 
-               if ( $user->pingLimiter( 'emailuser' ) ) {
+               // Check the ping limiter without incrementing it - we'll check it
+               // again later and increment it on a successful send
+               if ( $user->pingLimiter( 'emailuser', 0 ) ) {
                        wfDebug( "Ping limiter triggered.\n" );
 
                        return 'actionthrottledtext';
@@ -376,6 +378,11 @@ class SpecialEmailUser extends UnlistedSpecialPage {
                $text .= $context->msg( 'emailuserfooter',
                        $from->name, $to->name )->inContentLanguage()->text();
 
+               // Check and increment the rate limits
+               if ( $context->getUser()->pingLimiter( 'emailuser' ) ) {
+                       throw new ThrottledError();
+               }
+
                $error = false;
                if ( !Hooks::run( 'EmailUser', [ &$to, &$from, &$subject, &$text, &$error ] ) ) {
                        if ( $error instanceof Status ) {