From e31c9986a17f036ec89e2ef3f04519026e42ebf3 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Fri, 6 Oct 2017 00:36:07 -0700 Subject: [PATCH] SpecialEmailUser: Don't increment pingLimiter() just for opening the page 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 | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/includes/specials/SpecialEmailuser.php b/includes/specials/SpecialEmailuser.php index 249be7f17f..30eb38d04a 100644 --- a/includes/specials/SpecialEmailuser.php +++ b/includes/specials/SpecialEmailuser.php @@ -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 ) { -- 2.20.1