X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fspecials%2FSpecialEmailuser.php;h=06ca04f5cda0b24340fb2b9a6062bcbb97ec15c3;hb=d2b5c86eac27b0ce60076502f195b1b37d762c60;hp=249be7f17fa9a658005262d5276d3f8116830005;hpb=9ee41b116326f112782807dbd254822adc3e631e;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specials/SpecialEmailuser.php b/includes/specials/SpecialEmailuser.php index 249be7f17f..06ca04f5cd 100644 --- a/includes/specials/SpecialEmailuser.php +++ b/includes/specials/SpecialEmailuser.php @@ -224,15 +224,52 @@ class SpecialEmailUser extends UnlistedSpecialPage { wfDebug( "Target is invalid user.\n" ); return 'notarget'; - } elseif ( !$target->isEmailConfirmed() ) { + } + + if ( !$target->isEmailConfirmed() ) { wfDebug( "User has no valid email.\n" ); return 'noemail'; - } elseif ( !$target->canReceiveEmail() ) { + } + + if ( !$target->canReceiveEmail() ) { wfDebug( "User does not allow user emails.\n" ); return 'nowikiemail'; - } elseif ( $sender !== null ) { + } + + if ( $target->getEditCount() === 0 && + ( $sender === null || !$sender->isAllowed( 'sendemail-new-users' ) ) + ) { + // Determine if target has any other logged actions. + $dbr = wfGetDB( DB_REPLICA ); + $log_id = $dbr->selectField( + 'logging', + 'log_id', + [ + 'log_user' => $target->getId(), + "NOT (log_type = 'newusers' AND log_action = 'autocreate')", + ], + __METHOD__, + [ 'LIMIT' => 1 ] + ); + + if ( !$log_id ) { + wfDebug( "User has no logged actions on this wiki.\n" ); + + return 'nowikiemail'; + } + } + + if ( $sender !== null && !$target->getOption( 'email-allow-new-users' ) && + $sender->isNewbie() + ) { + wfDebug( "User does not allow user emails from new users.\n" ); + + return 'nowikiemail'; + } + + if ( $sender !== null ) { $blacklist = $target->getOption( 'email-blacklist', [] ); if ( $blacklist ) { $lookup = CentralIdLookup::factory(); @@ -280,7 +317,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 +415,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 ) {