Merge "Prevent new users from being sent emails"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Fri, 8 Dec 2017 23:34:49 +0000 (23:34 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 8 Dec 2017 23:34:49 +0000 (23:34 +0000)
includes/DefaultSettings.php
includes/specials/SpecialEmailuser.php
includes/user/User.php
languages/i18n/en.json
languages/i18n/qqq.json

index 6fe74fa..a7b34a1 100644 (file)
@@ -5147,6 +5147,7 @@ $wgGroupPermissions['user']['sendemail'] = true;
 $wgGroupPermissions['user']['applychangetags'] = true;
 $wgGroupPermissions['user']['changetags'] = true;
 $wgGroupPermissions['user']['editcontentmodel'] = true;
+$wgGroupPermissions['user']['sendemail-new-users'] = true;
 
 // Implicit group for accounts that pass $wgAutoConfirmAge
 $wgGroupPermissions['autoconfirmed']['autoconfirmed'] = true;
index 30eb38d..d57ba09 100644 (file)
@@ -224,15 +224,45 @@ 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 ) {
                        $blacklist = $target->getOption( 'email-blacklist', [] );
                        if ( $blacklist ) {
                                $lookup = CentralIdLookup::factory();
index 37a80f2..a4dfb2b 100644 (file)
@@ -179,6 +179,7 @@ class User implements IDBAccessObject, UserIdentity {
                'reupload-shared',
                'rollback',
                'sendemail',
+               'sendemail-new-users',
                'siteadmin',
                'suppressionlog',
                'suppressredirect',
index 4b65fbc..1c2bab9 100644 (file)
        "right-siteadmin": "Lock and unlock the database",
        "right-override-export-depth": "Export pages including linked pages up to a depth of 5",
        "right-sendemail": "Send email to other users",
+       "right-sendemail-new-users": "Send email to users with no logged actions",
        "right-managechangetags": "Create and (de)activate [[Special:Tags|tags]]",
        "right-applychangetags": "Apply [[Special:Tags|tags]] along with one's changes",
        "right-changetags": "Add and remove arbitrary [[Special:Tags|tags]] on individual revisions and log entries",
index 8952caf..3fcbece 100644 (file)
        "right-siteadmin": "{{doc-right|siteadmin}}",
        "right-override-export-depth": "{{doc-right|override-export-depth}}",
        "right-sendemail": "{{doc-right|sendemail}}",
+       "right-sendemail-new-users": "{{doc-right|sendemail-new-users}}",
        "right-managechangetags": "{{doc-right|managechangetags}}",
        "right-applychangetags": "{{doc-right|applychangetags}}",
        "right-changetags": "{{doc-right|changetags}}",