From b39ce8f791aaca2f24188ed54978865d3f149c12 Mon Sep 17 00:00:00 2001 From: David Barratt Date: Tue, 14 Nov 2017 16:49:52 -0500 Subject: [PATCH] Allow users to prevent new users from sending them email. Users now have the option to prevent Newbie users from sending them emails. Bug: T138165 Change-Id: I5d5332e50971fbcd1fa630d6bd03bdf757a9d1f1 --- includes/DefaultSettings.php | 1 + includes/Preferences.php | 16 +++++++++---- .../fields/HTMLUsersMultiselectField.php | 8 +++++++ includes/specials/SpecialEmailuser.php | 13 +++++++--- languages/i18n/en.json | 1 + languages/i18n/qqq.json | 1 + resources/Resources.php | 1 + ...awiki.special.preferences.personalEmail.js | 24 +++++++++++++++++++ 8 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 resources/src/mediawiki.special/mediawiki.special.preferences.personalEmail.js diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index a7b34a17b1..e50b7a7db1 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -4851,6 +4851,7 @@ $wgDefaultUserOptions = [ 'editfont' => 'monospace', 'editondblclick' => 0, 'editsectiononrightclick' => 0, + 'email-allow-new-users' => 1, 'enotifminoredits' => 0, 'enotifrevealaddr' => 0, 'enotifusertalkpages' => 1, diff --git a/includes/Preferences.php b/includes/Preferences.php index 878462db21..33a975d104 100644 --- a/includes/Preferences.php +++ b/includes/Preferences.php @@ -534,12 +534,22 @@ class Preferences { if ( $config->get( 'EnableUserEmail' ) && $user->isAllowed( 'sendemail' ) ) { $defaultPreferences['disablemail'] = [ + 'id' => 'wpAllowEmail', 'type' => 'toggle', 'invert' => true, 'section' => 'personal/email', 'label-message' => 'allowemail', 'disabled' => $disableEmailPrefs, ]; + + $defaultPreferences['email-allow-new-users'] = [ + 'id' => 'wpAllowEmailFromNewUsers', + 'type' => 'toggle', + 'section' => 'personal/email', + 'label-message' => 'email-allow-new-users-label', + 'disabled' => $disableEmailPrefs, + ]; + $defaultPreferences['ccmeonemails'] = [ 'type' => 'toggle', 'section' => 'personal/email', @@ -547,10 +557,7 @@ class Preferences { 'disabled' => $disableEmailPrefs, ]; - if ( $config->get( 'EnableUserEmailBlacklist' ) - && !$disableEmailPrefs - && !(bool)$user->getOption( 'disablemail' ) - ) { + if ( $config->get( 'EnableUserEmailBlacklist' ) ) { $lookup = CentralIdLookup::factory(); $ids = $user->getOption( 'email-blacklist', [] ); $names = $ids ? $lookup->namesFromCentralIds( $ids, $user ) : []; @@ -560,6 +567,7 @@ class Preferences { 'label-message' => 'email-blacklist-label', 'section' => 'personal/email', 'default' => implode( "\n", $names ), + 'disabled' => $disableEmailPrefs, ]; } } diff --git a/includes/htmlform/fields/HTMLUsersMultiselectField.php b/includes/htmlform/fields/HTMLUsersMultiselectField.php index f094745f5d..46cc6d3116 100644 --- a/includes/htmlform/fields/HTMLUsersMultiselectField.php +++ b/includes/htmlform/fields/HTMLUsersMultiselectField.php @@ -56,6 +56,14 @@ class HTMLUsersMultiselectField extends HTMLUserTextField { public function getInputOOUI( $value ) { $params = [ 'name' => $this->mName ]; + if ( isset( $this->mParams['id'] ) ) { + $params['id'] = $this->mParams['id']; + } + + if ( isset( $this->mParams['disabled'] ) ) { + $params['disabled'] = $this->mParams['disabled']; + } + if ( isset( $this->mParams['default'] ) ) { $params['default'] = $this->mParams['default']; } diff --git a/includes/specials/SpecialEmailuser.php b/includes/specials/SpecialEmailuser.php index d57ba09465..06ca04f5cd 100644 --- a/includes/specials/SpecialEmailuser.php +++ b/includes/specials/SpecialEmailuser.php @@ -238,9 +238,8 @@ class SpecialEmailUser extends UnlistedSpecialPage { return 'nowikiemail'; } - if ( - $target->getEditCount() === 0 - && ( $sender === null || !$sender->isAllowed( 'sendemail-new-users' ) ) + if ( $target->getEditCount() === 0 && + ( $sender === null || !$sender->isAllowed( 'sendemail-new-users' ) ) ) { // Determine if target has any other logged actions. $dbr = wfGetDB( DB_REPLICA ); @@ -262,6 +261,14 @@ class SpecialEmailUser extends UnlistedSpecialPage { } } + 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 ) { diff --git a/languages/i18n/en.json b/languages/i18n/en.json index 1c2bab9b1c..5e7c8cb6b8 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -1064,6 +1064,7 @@ "timezoneregion-indian": "Indian Ocean", "timezoneregion-pacific": "Pacific Ocean", "allowemail": "Allow other users to email me", + "email-allow-new-users-label": "Allow emails from brand-new users", "email-blacklist-label": "Prohibit these users from emailing me:", "prefs-searchoptions": "Search", "prefs-namespaces": "Namespaces", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index a527ed0927..f3f44c8eb5 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -1259,6 +1259,7 @@ "timezoneregion-indian": "Used in \"Time zone\" listbox in [[Special:Preferences#mw-prefsection-datetime|preferences]], \"date and time\" tab.\n{{Related|Timezoneregion}}", "timezoneregion-pacific": "Used in \"Time zone\" listbox in [[Special:Preferences#mw-prefsection-datetime|preferences]], \"date and time\" tab.\n{{Related|Timezoneregion}}", "allowemail": "Used in [[Special:Preferences]] > {{int:prefs-personal}} > {{int:email}}.", + "email-allow-new-users-label": "Used in [[Special:Preferences]] > {{int:prefs-prohibit}} > {{int:email}}.", "email-blacklist-label": "Used in [[Special:Preferences]] > {{int:prefs-prohibit}} > {{int:email}}.", "prefs-searchoptions": "{{Identical|Search}}", "prefs-namespaces": "Shown as legend of the second fieldset of the tab 'Search' in [[Special:Preferences]]\n{{Identical|Namespace}}", diff --git a/resources/Resources.php b/resources/Resources.php index 3d075e29b8..b4944298d2 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -2117,6 +2117,7 @@ return [ 'resources/src/mediawiki.special/mediawiki.special.preferences.convertmessagebox.js', 'resources/src/mediawiki.special/mediawiki.special.preferences.tabs.js', 'resources/src/mediawiki.special/mediawiki.special.preferences.timezone.js', + 'resources/src/mediawiki.special/mediawiki.special.preferences.personalEmail.js', ], 'messages' => [ 'prefs-tabs-navigation-hint', diff --git a/resources/src/mediawiki.special/mediawiki.special.preferences.personalEmail.js b/resources/src/mediawiki.special/mediawiki.special.preferences.personalEmail.js new file mode 100644 index 0000000000..f934d59e1e --- /dev/null +++ b/resources/src/mediawiki.special/mediawiki.special.preferences.personalEmail.js @@ -0,0 +1,24 @@ +/*! + * JavaScript for Special:Preferences: Email preferences better UX + */ +( function ( $ ) { + $( function () { + var allowEmail, allowEmailFromNewUsers; + + allowEmail = $( '#wpAllowEmail' ); + allowEmailFromNewUsers = $( '#wpAllowEmailFromNewUsers' ); + + function toggleDisabled() { + if ( allowEmail.is( ':checked' ) && allowEmail.is( ':enabled' ) ) { + allowEmailFromNewUsers.prop( 'disabled', false ); + } else { + allowEmailFromNewUsers.prop( 'disabled', true ); + } + } + + if ( allowEmail ) { + allowEmail.on( 'change', toggleDisabled ); + toggleDisabled(); + } + } ); +}( jQuery ) ); -- 2.20.1