Umherirrender has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/239582

Change subject: Add a emailuser web notification
......................................................................

Add a emailuser web notification

When a user sent an email to another user with [[Special:Emailuser]] or
action=emailuser, give a echo for the target user to be lookup in his
email programm.
This option is off by default. It is only useful as web notification,
because a email notification would go to the same address.

Bug: T56130
Change-Id: Ie279457daf51e1c34c998197ce9e76c78ee705e4
---
M Echo.php
M Hooks.php
M i18n/en.json
M i18n/qqq.json
4 files changed, 60 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo 
refs/changes/82/239582/1

diff --git a/Echo.php b/Echo.php
index fe69f12..0d8d8bf 100644
--- a/Echo.php
+++ b/Echo.php
@@ -78,6 +78,7 @@
 $wgHooks['UserSaveOptions'][] = 'EchoHooks::onUserSaveOptions';
 $wgHooks['UserClearNewTalkNotification'][] = 
'EchoHooks::onUserClearNewTalkNotification';
 $wgHooks['ParserTestTables'][] = 'EchoHooks::onParserTestTables';
+$wgHooks['EmailUserComplete'][] = 'EchoHooks::onEmailUserComplete';
 
 // Extension:UserMerge support
 $wgHooks['UserMergeAccountFields'][] = 'EchoHooks::onUserMergeAccountFields';
@@ -162,6 +163,11 @@
        'welcome' => array(
                'email' => false,
        ),
+       // No need to get a email when another user sends to me
+       'emailuser' => array(
+               'web' => true,
+               'email' => false,
+       ),
 );
 
 // Definitions of the different types of notification delivery that are 
possible.
@@ -226,6 +232,10 @@
        'mention' => array(
                'priority' => 4,
                'tooltip' => 'echo-pref-tooltip-mention',
+       ),
+       'emailuser' => array(
+               'priority' => 9,
+               'tooltip' => 'echo-pref-tooltip-emailuser',
        ),
 );
 
@@ -401,6 +411,19 @@
                'email-body-batch-params' => array( 'agent', 'user-rights-list' 
),
                'icon' => 'site',
        ),
+       'emailuser' => array(
+               'user-locators' => array(
+                       array( 'EchoUserLocator::locateFromEventExtra', array( 
'to-user-id' ) ),
+               ),
+               'category' => 'emailuser',
+               'group' => 'neutral',
+               'section' => 'alert',
+               'title-message' => 'notification-emailuser',
+               'title-params' => array( 'agent' ),
+               'flyout-message' => 'notification-emailuser-flyout',
+               'flyout-params' => array( 'agent' ),
+               'icon' => 'site',
+       ),
 );
 
 // Enable new talk page messages alert for all logged in users by default
@@ -425,6 +448,7 @@
 $wgDefaultUserOptions['echo-subscriptions-email-system'] = true;
 $wgDefaultUserOptions['echo-subscriptions-email-user-rights'] = true;
 $wgDefaultUserOptions['echo-subscriptions-web-article-linked'] = false;
+$wgDefaultUserOptions['echo-subscriptions-web-emailuser'] = false;
 
 // Echo Configuration for EventLogging
 $wgEchoConfig = array(
diff --git a/Hooks.php b/Hooks.php
index 6b005e4..f18d350 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -984,6 +984,34 @@
        }
 
        /**
+        * Handler for EmailUserComplete hook.
+        * @see https://www.mediawiki.org/wiki/Manual:Hooks/EmailUserComplete
+        * @param $address MailAddress Adress of receiving user
+        * @param $from MailAddress Adress of sending user
+        * @param $subject string Subject of the mail
+        * @param $text string Text of the mail
+        * @return bool true in all cases
+        */
+       public static function onEmailUserComplete( $address, $from, $subject, 
$text ) {
+               if ( $from->name === $address->name ) {
+                       // nothing to notify
+                       return true;
+               }
+               $userTo = User::newFromName( $address->name );
+               $userFrom = User::newFromName( $from->name );
+
+               EchoEvent::create( array(
+                       'type' => 'emailuser',
+                       'extra' => array(
+                               'to-user-id' => $userTo->getId(),
+                       ),
+                       'agent' => $userFrom,
+               ) );
+
+               return true;
+       }
+
+       /**
         * For integration with the UserMerge extension.
         *
         * @param array $updateFields
diff --git a/i18n/en.json b/i18n/en.json
index 2f60596..0372ede 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -31,11 +31,13 @@
        "echo-category-title-other": "{{PLURAL:$1|Other}}",
        "echo-category-title-system": "{{PLURAL:$1|System}}",
        "echo-category-title-user-rights": "{{PLURAL:$1|User rights change|User 
rights changes}}",
+       "echo-category-title-emailuser": "{{PLURAL:$1|Email from other 
user|Emails from other users}}",
        "echo-pref-tooltip-edit-user-talk": "Notify me when someone posts a 
message or replies on my talk page.",
        "echo-pref-tooltip-article-linked": "Notify me when someone links to a 
page I created from an article page.",
        "echo-pref-tooltip-reverted": "Notify me when someone reverts an edit I 
made, by using the undo or rollback tool.",
        "echo-pref-tooltip-mention": "Notify me when someone links to my user 
page.",
        "echo-pref-tooltip-user-rights": "Notify me when someone changes my 
user rights.",
+       "echo-pref-tooltip-emailuser": "Notify me when someone sends me an 
Email.",
        "echo-no-agent": "[Nobody]",
        "echo-no-title": "[No page]",
        "echo-error-no-formatter": "No formatting defined for notification.",
@@ -76,6 +78,8 @@
        "notification-new-user": "Welcome to {{SITENAME}}, $1! We're glad 
you're here.",
        "notification-reverted2": "Your {{PLURAL:$4|edit on [[:$2]] has|edits 
on [[:$2]] have}} been {{GENDER:$1|reverted}} by [[User:$1|$1]]. $3",
        "notification-reverted-flyout2": "Your {{PLURAL:$4|edit on $2 has|edits 
on $2 have}} been {{GENDER:$1|reverted}} by $1. $3",
+       "notification-emailuser": "[[User:$1|$1]] {{GENDER:$1|sent}} you an 
email.",
+       "notification-emailuser-flyout": "$1 {{GENDER:$1|sent}} you an email",
        "notification-edit-talk-page-email-subject2": "$1 {{GENDER:$1|left}} 
you a message on {{SITENAME}}",
        "notification-edit-talk-page-email-batch-body2": "$1 {{GENDER:$1|left}} 
a message on your talk page.",
        "notification-edit-talk-page-email-batch-body-with-section": "$1 
{{GENDER:$1|left}} a message on your talk page in \"$2\".",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 3cfe284..2db25d0 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -52,11 +52,13 @@
        "echo-category-title-other": "This is a short title for notification 
category.\n\nUsed in a list of options under the heading 
{{msg-mw|Prefs-echosubscriptions}} in Special:Preferences. As far as I can see 
this always needs to be a plural for an unspecified number.\n\nIt used to be 
used as <code>$1</code> in {{msg-mw|Echo-dismiss-message}}, but this message is 
no longer used, apparently.\n\nParameters:\n* $1 - number of messages, for 
PLURAL support\n{{Related|Echo-category-title}}\n{{Identical|Other}}",
        "echo-category-title-system": "This is a short title for notification 
category.\n\nUsed in a list of options under the heading 
{{msg-mw|Prefs-echosubscriptions}} in Special:Preferences. As far as I can see 
this always needs to be a plural for an unspecified number.\n\nIt used to be 
used as <code>$1</code> in {{msg-mw|Echo-dismiss-message}}, but this message is 
no longer used, apparently.\n\nParameters:\n* $1 - number of messages, for 
PLURAL support\n{{Related|Echo-category-title}}\n{{Identical|System}}",
        "echo-category-title-user-rights": "This is a short title for 
notification category.\n\nUsed in a list of options under the heading 
{{msg-mw|Prefs-echosubscriptions}} in Special:Preferences. As far as I can see 
this always needs to be a plural for an unspecified number.\n\nIt used to be 
used as <code>$1</code> in {{msg-mw|Echo-dismiss-message}}, but this message is 
no longer used, apparently.\n\nParameters:\n* $1 - number of messages, for 
PLURAL support\n{{Related|Echo-category-title}}",
+       "echo-category-title-emailuser": "This is a short title for 
notification category.\n\nUsed in a list of options under the heading 
{{msg-mw|Prefs-echosubscriptions}} in Special:Preferences. As far as I can see 
this always needs to be a plural for an unspecified number.\n\nIt used to be 
used as <code>$1</code> in {{msg-mw|Echo-dismiss-message}}, but this message is 
no longer used, apparently.\n\nParameters:\n* $1 - number of messages, for 
PLURAL support\n{{Related|Echo-category-title}}",
        "echo-pref-tooltip-edit-user-talk": "This is a short description of the 
edit-user-talk notification category.\n{{Related|Echo-pref-tooltip}}",
        "echo-pref-tooltip-article-linked": "This is a short description of the 
article-linked notification category.\n{{Related|Echo-pref-tooltip}}",
        "echo-pref-tooltip-reverted": "This is a short description of the 
tooltip-reverted notification category.\n{{Related|Echo-pref-tooltip}}",
        "echo-pref-tooltip-mention": "This is a short description of the 
mention notification category.\n{{Related|Echo-pref-tooltip}}",
        "echo-pref-tooltip-user-rights": "This is a short description of the 
user rights changes notification category\n{{Related|Echo-pref-tooltip}}",
+       "echo-pref-tooltip-emailuser": "This is a short description of the user 
email notification category\n{{Related|Echo-pref-tooltip}}",
        "echo-no-agent": "Shown in place of a username in a notification\n\tif 
the notification has no specified user.",
        "echo-no-title": "Shown in place of a page title in a notification if 
the notification has no specified page title.",
        "echo-error-no-formatter": "Error message displayed when no formatting 
has been defined for a notification. In other words, the extension doesn't know 
how to properly display the notification.",
@@ -97,6 +99,8 @@
        "notification-new-user": "Text of the welcome notification. 
Parameters:\n* $1 - the name of the new user\nSee also:\n* 
{{msg-mw|Guidedtour-tour-gettingstarted-start-title}}",
        "notification-reverted2": "Format for displaying notifications of a 
user's edit being reverted. Parameters:\n* $1 - the username of the person who 
reverted, plain text. Can be used for GENDER.\n* $2 - the page that was 
reverted, formatted\n* $3 - a diff link which is labeled {{msg-mw|Showdiff}}\n* 
$4 - the number of edits that were reverted. NOTE: This will only be set to 1 
or 2, with 2 actually meaning 'an unknown number greater than 
0'.\n{{Related|Notification-reverted}}",
        "notification-reverted-flyout2": "Flyout-specific format for displaying 
notifications of a user's edit being reverted.\n\nParameters:\n* $1 - the 
username of the person who reverted, plain text. Can be used for GENDER.\n* $2 
- the page that was reverted, formatted\n* $3 - a diff link which is labeled 
{{msg-mw|Showdiff}}\n* $4 - the number of edits that were reverted. NOTE: This 
will only be set to 1 or 2, with 2 actually meaning \"an unknown number greater 
than 0\".\n{{Related|Notification-reverted}}",
+       "notification-emailuser": "Format for displaying notifications of a 
user has sent an email to another user. Parameters:\n* $1 - the username of the 
person the email, plain text. Can be used for GENDER.",
+       "notification-emailuser-flyout": "Flyout-specific format for displaying 
notifications of user has sent an email to another user.\n\nParameters:\n* $1 - 
the username of the person who sent the email, plain text. Can be used for 
GENDER.",
        "notification-edit-talk-page-email-subject2": "Email subject. 
Parameters:\n* $1 - a username which can be used for gender support",
        "notification-edit-talk-page-email-batch-body2": "First line of the 
email notification for a talk page edit. The following line completes it with 
the description of the message in question, that is its edit 
summary.\n\nParameters:\n* $1 - a username (which also links to the userpage of 
the user in question, in the HTML version)\nSee also:\n* 
{{msg-mw|Notification-edit-talk-page2}}\n* 
{{msg-mw|Notification-edit-talk-page-email-subject2}}\n* 
{{msg-mw|Notification-edit-talk-page-flyout2}}",
        "notification-edit-talk-page-email-batch-body-with-section": "Email 
notification for talk page edit with new section or new comment. Parameters:\n* 
$1 - a username\n* $2 - the raw section title text",

-- 
To view, visit https://gerrit.wikimedia.org/r/239582
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie279457daf51e1c34c998197ce9e76c78ee705e4
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Umherirrender <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to