WMDE-Fisch has uploaded a new change for review.

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

Change subject: Echo notifications for successful mentions
......................................................................

Echo notifications for successful mentions

Adds new notification type and icon for successful mentions.
Complements existing test to consider successful mentions.

Bug: T139623

Change-Id: I7a77b40e8b14c95cadb9023065ee916247feacf9
---
M Echo.php
M autoload.php
M i18n/en.json
M i18n/qqq.json
M includes/DiscussionParser.php
R includes/formatters/MentionStatusPresentationModel.php
A modules/icons/mention-success.svg
M tests/phpunit/DiscussionParserTest.php
A tests/phpunit/revision_txt/747747750.txt
9 files changed, 147 insertions(+), 19 deletions(-)


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

diff --git a/Echo.php b/Echo.php
index cfb7cbc..302be5e 100644
--- a/Echo.php
+++ b/Echo.php
@@ -212,6 +212,10 @@
                'web' => true,
                'email' => false
        ),
+       'mention-success' => array(
+               'web' => true,
+               'email' => false
+       ),
 );
 
 // Definitions of the different types of notification delivery that are 
possible.
@@ -307,6 +311,10 @@
                'priority' => 4,
                'tooltip' => 'echo-pref-tooltip-mention-failure',
        );
+       $wgEchoNotificationCategories['mention-success'] = array(
+               'priority' => 4,
+               'tooltip' => 'echo-pref-tooltip-mention-success',
+       );
 }
 
 $echoIconPath = "Echo/modules/icons";
@@ -347,6 +355,9 @@
        ),
        'mention-failure' => array(
                'path' => "$echoIconPath/mention-failure.svg",
+       ),
+       'mention-success' => array(
+               'path' => "$echoIconPath/mention-success.svg",
        ),
        'reviewed' => array(
                'path' => "$echoIconPath/reviewed.svg",
@@ -447,7 +458,7 @@
                ),
                'group' => 'negative',
                'section' => 'alert',
-               'presentation-model' => 'EchoMentionFailurePresentationModel',
+               'presentation-model' => 'EchoMentionStatusPresentationModel',
        ),
        'mention-too-many' => array(
                EchoAttributeManager::ATTR_LOCATORS => array(
@@ -456,7 +467,7 @@
                'category' => 'mention-failure',
                'group' => 'negative',
                'section' => 'alert',
-               'presentation-model' => 'EchoMentionFailurePresentationModel',
+               'presentation-model' => 'EchoMentionStatusPresentationModel',
        ),
        'mention-multiple-sections' => array(
                EchoAttributeManager::ATTR_LOCATORS => array(
@@ -465,7 +476,20 @@
                'category' => 'mention-failure',
                'group' => 'negative',
                'section' => 'alert',
-               'presentation-model' => 'EchoMentionFailurePresentationModel',
+               'presentation-model' => 'EchoMentionStatusPresentationModel',
+       ),
+       'mention-success' => array(
+               EchoAttributeManager::ATTR_LOCATORS => array(
+                       array( 'EchoUserLocator::locateEventAgent' ),
+               ),
+               'category' => 'mention-success',
+               'bundle' => array(
+                       'web' => true,
+                       'expandable' => true,
+               ),
+               'group' => 'positive',
+               'section' => 'alert',
+               'presentation-model' => 'EchoMentionStatusPresentationModel',
        ),
        'user-rights' => array(
                EchoAttributeManager::ATTR_LOCATORS => array(
@@ -535,6 +559,7 @@
 $wgDefaultUserOptions['echo-subscriptions-email-user-rights'] = true;
 $wgDefaultUserOptions['echo-subscriptions-web-article-linked'] = false;
 $wgDefaultUserOptions['echo-subscriptions-web-mention-failure'] = false;
+$wgDefaultUserOptions['echo-subscriptions-web-mention-success'] = false;
 
 // Echo Configuration for EventLogging
 $wgEchoConfig = array(
diff --git a/autoload.php b/autoload.php
index 721255a..152db8e 100644
--- a/autoload.php
+++ b/autoload.php
@@ -60,7 +60,7 @@
        'EchoIteratorDecorator' => __DIR__ . 
'/includes/iterator/IteratorDecorator.php',
        'EchoLocalCache' => __DIR__ . '/includes/cache/LocalCache.php',
        'EchoMentionPresentationModel' => __DIR__ . 
'/includes/formatters/MentionPresentationModel.php',
-       'EchoMentionFailurePresentationModel' => __DIR__ . 
'/includes/formatters/MentionFailurePresentationModel.php',
+       'EchoMentionStatusPresentationModel' => __DIR__ . 
'/includes/formatters/MentionStatusPresentationModel.php',
        'EchoModelFormatter' => __DIR__ . 
'/includes/formatters/EchoModelFormatter.php',
        'EchoModerationController' => __DIR__ . 
'/includes/controller/ModerationController.php',
        'EchoMultipleIterator' => __DIR__ . 
'/includes/iterator/MultipleIterator.php',
diff --git a/i18n/en.json b/i18n/en.json
index e0ffcbc..449a2a3 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -65,6 +65,7 @@
        "echo-category-title-reverted": "Edit {{PLURAL:$1|revert|reverts}}",
        "echo-category-title-mention": "{{PLURAL:$1|Mention|Mentions}}",
        "echo-category-title-mention-failure": "Failed 
{{PLURAL:$1|mention|mentions}}",
+       "echo-category-title-mention-success": "Successful 
{{PLURAL:$1|mention|mentions}}",
        "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}}",
@@ -74,6 +75,7 @@
        "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-mention-failure": "Notify me when my edits fail to 
mention users.",
+       "echo-pref-tooltip-mention-success": "Notify me when my edits 
successfully mention users.",
        "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-error-no-formatter": "No formatting defined for notification.",
@@ -150,6 +152,7 @@
        "notification-header-mention-failure-too-many": "{{GENDER:$2|Your}} 
mentions were not sent because they exceeded the limit of $3.",
        "notification-header-mention-failure-multiple-sections": 
"{{GENDER:$2|Your}} {{PLURAL:$4|mentions|0=mention}} for \"$3\" {{PLURAL:$4|and 
$4 other were|and $4 others were|0=was}} not sent because {{GENDER:$2|you 
changed}} multiple sections.",
        "notification-header-mention-failure-bundle": "$3 mentions 
{{GENDER:$2|you made}} on the <strong>$4</strong> talk page were not sent.",
+       "notification-header-mention-success": "{{GENDER:$2|You}} successfully 
mentioned \"$3\"{{PLURAL:$4| and another user| and $4 other users|0=}}.",
        "notification-compact-header-mention-failure-user-unknown": 
"<strong>Unknown user:</strong> \"$1\"",
        "notification-compact-header-mention-failure-user-anonymous": 
"<strong>Anonymous user:</strong> \"$1\"",
        "notification-header-user-rights-add-only": "{{GENDER:$4|Your}} user 
rights were {{GENDER:$1|changed}}. You have been added to: $2.",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 5e02402..f8a38f6 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -57,6 +57,7 @@
        "echo-category-title-reverted": "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-mention": "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|Mention}}",
        "echo-category-title-mention-failure": "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.",
+       "echo-category-title-mention-success": "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.",
        "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}}",
@@ -66,6 +67,7 @@
        "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-mention-failure": "This is a short description of 
the mention failure notification category.\n{{Related|Echo-pref-tooltip}}",
+       "echo-pref-tooltip-mention-success": "This is a short description of 
the mention failure 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-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.",
@@ -142,6 +144,7 @@
        "notification-header-mention-failure-too-many": "Header text for a 
notification when your mention has failed because you tried to mention too many 
users.\n* $2 - user's name for use in GENDER.\n* $3 - max number of mentions 
allowed; uses standard number formatting",
        "notification-header-mention-failure-multiple-sections": "Header text 
for a notification when your mention has failed because you edited multiple 
sections.\n* $2 - user's name for use in GENDER.\n* $3 - username that was not 
mentioned.\n* $4 - number of additional failed mentions; uses standard number 
formatting and used for PLURAL.",
        "notification-header-mention-failure-bundle": "Header text for a 
bundled notification when multiple mentions failed.\n* $2 - user's name for use 
in GENDER.\n* $3 - number of mentions; uses standard number formatting and used 
for PLURAL.\n* $4 - talk page title.",
+       "notification-header-mention-success": "Header text for a notification 
when your mention was successful.\n* $2 - user's name for use in GENDER.\n* $3 
- username that was mentioned.",
        "notification-compact-header-mention-failure-user-unknown": "Compact 
header text for a notification when your mention has failed because the user 
was not found.\n* $1 - username that was not found.",
        "notification-compact-header-mention-failure-user-anonymous": "Compact 
header text for a notification when your mention has failed because the user is 
an anonymous IP.\n* $1 - username that is anonymous.",
        "notification-header-user-rights-add-only": "Notifications header 
message when a user is added to groups.  Parameters:\n* $1 - the raw username 
of the person who made the user rights change, can be used for GENDER 
support\n* $2 - a localized list of the groups that were added\n* $3 - the 
number of groups that were added, can be used for PLURAL\n* $4 - name of the 
user viewing the notification, can be used for GENDER",
diff --git a/includes/DiscussionParser.php b/includes/DiscussionParser.php
index 34efef4..17b20ae 100644
--- a/includes/DiscussionParser.php
+++ b/includes/DiscussionParser.php
@@ -288,6 +288,21 @@
                        ),
                        'agent' => $agent,
                ) );
+
+               if ( $wgEchoMentionStatusNotifications ) {
+                       $firstValidMention = self::getPrimaryMentionUserName( 
$userMentions );
+                       EchoEvent::create( array(
+                               'type' => 'mention-success',
+                               'title' => $title,
+                               'extra' => array(
+                                       'subject-name' => $firstValidMention,
+                                       'mention-number' => count( 
$userMentions['validMentions'] ),
+                                       'section-title' => $header,
+                                       'notifyAgent' => true
+                               ),
+                               'agent' => $agent,
+                       ) );
+               }
        }
 
        static function getPrimaryMentionUserName( $userMentions ) {
diff --git a/includes/formatters/MentionFailurePresentationModel.php 
b/includes/formatters/MentionStatusPresentationModel.php
similarity index 86%
rename from includes/formatters/MentionFailurePresentationModel.php
rename to includes/formatters/MentionStatusPresentationModel.php
index 36a9ae0..665294d 100644
--- a/includes/formatters/MentionFailurePresentationModel.php
+++ b/includes/formatters/MentionStatusPresentationModel.php
@@ -9,10 +9,13 @@
  *
  * @license GNU GPL v2+
  */
-class EchoMentionFailurePresentationModel extends EchoEventPresentationModel {
+class EchoMentionStatusPresentationModel extends EchoEventPresentationModel {
        use EchoPresentationModelSectionTrait;
 
        public function getIconType() {
+               if ( $this->isMentionsSuccess() ) {
+                       return 'mention-success';
+               }
                return 'mention-failure';
        }
 
@@ -25,6 +28,13 @@
 
                if ( $this->isMultipleSectionFailure() ) {
                        $msg = $this->getMessageWithAgent( 
'notification-header-mention-failure-multiple-sections' );
+                       $msg->params( $this->getSubjectName() );
+                       $msg->numParams( $this->getMentionNumber() - 1 );
+                       return $msg;
+               }
+
+               if ( $this->isMentionsSuccess() ) {
+                       $msg = $this->getMessageWithAgent( 
'notification-header-mention-success' );
                        $msg->params( $this->getSubjectName() );
                        $msg->numParams( $this->getMentionNumber() - 1 );
                        return $msg;
@@ -100,6 +110,10 @@
                return $this->event->getExtraParam( 'mention-number', 1 );
        }
 
+       private function isMentionsSuccess() {
+               return $this->getType() === 'mention-success';
+       }
+
        private function isTooManyMentionsFailure() {
                return $this->getType() === 'mention-too-many';
        }
diff --git a/modules/icons/mention-success.svg 
b/modules/icons/mention-success.svg
new file mode 100644
index 0000000..5cfcabf
--- /dev/null
+++ b/modules/icons/mention-success.svg
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<svg xmlns="http://www.w3.org/2000/svg"; width="30" height="30" viewBox="0 0 
213.37759 149.36432">
+    <path d="M32.007 149.364h181.37l-32.006-32.006V0H0v117.358c0 18.137 13.87 
32.006 32.007 32.006z" fill="#00af8a"/><path d="M134.904 42.575L78.27 99.207 
49.955 70.89l-8.495 8.495 36.811 36.81 
73.622-73.621c-4.53-4.531-12.459-4.531-16.99 0z" fill="#fff"/>
+</svg>
\ No newline at end of file
diff --git a/tests/phpunit/DiscussionParserTest.php 
b/tests/phpunit/DiscussionParserTest.php
index 380ff8c..e747718 100644
--- a/tests/phpunit/DiscussionParserTest.php
+++ b/tests/phpunit/DiscussionParserTest.php
@@ -304,6 +304,47 @@
                                ),
                                'precondition' => 'isParserFunctionsInstalled',
                        ),
+               );
+       }
+
+       /**
+        * @dataProvider generateEventsForRevisionData
+        */
+       public function testGenerateEventsForRevision( $newId, $oldId, 
$username, $lang, $pages, $title, $expected, $precondition = '' ) {
+               if ( $precondition !== '' ) {
+                       $result = $this->$precondition();
+                       if ( $result !== true ) {
+                               $this->markTestSkipped( $result );
+
+                               return;
+                       }
+               }
+
+               $revision = $this->setupTestRevisionsForEventGeneration( 
$newId, $oldId, $username, $lang, $pages, $title );
+               $events = array();
+               $this->setupEventCallbackForEventGeneration(
+                       function ( EchoEvent $event ) use ( &$events ) {
+                               $events[] = array(
+                                       'type' => $event->getType(),
+                                       'agent' => 
$event->getAgent()->getName(),
+                                       'section-title' => 
$event->getExtraParam( 'section-title' ),
+                               );
+                               return false;
+                       }
+               );
+
+               $this->setMwGlobals( array(
+                       // disable mention failure and success notifications
+                       'wgEchoMentionStatusNotifications' => false,
+               ) );
+
+               EchoDiscussionParser::generateEventsForRevision( $revision );
+
+               $this->assertEquals( $expected, $events );
+       }
+
+       public function provider_generateEventsForRevision_mentionStatus() {
+               return array(
                        array(
                                'new' => 747747748,
                                'old' => 747747747,
@@ -348,24 +389,34 @@
                                'title' => 'UTPage',
                                'expected' => array(),
                        ),
+                       array(
+                               'new' => 747747750,
+                               'old' => 747747747,
+                               'username' => 'Admin',
+                               'lang' => 'en',
+                               'pages' => array(),
+                               'title' => 'UTPage',
+                               'expected' => array(
+                                       array(
+                                               'type' => 'mention',
+                                               'agent' => 'Admin',
+                                               'section-title' => 'Hello 
Users',
+                                       ),
+                                       array(
+                                               'type' => 'mention-success',
+                                               'agent' => 'Admin',
+                                               'section-title' => 'Hello 
Users',
+                                       ),
+                               ),
+                       ),
                );
        }
 
        /**
-        * @dataProvider generateEventsForRevisionData
+        * @dataProvider provider_generateEventsForRevision_mentionStatus
         */
-       public function testGenerateEventsForRevision( $newId, $oldId, 
$username, $lang, $pages, $title, $expected, $precondition = '' ) {
-               if ( $precondition !== '' ) {
-                       $result = $this->$precondition();
-                       if ( $result !== true ) {
-                               $this->markTestSkipped( $result );
-
-                               return;
-                       }
-               }
-
+       public function testGenerateEventsForRevision_mentionStatus( $newId, 
$oldId, $username, $lang, $pages, $title, $expected ) {
                $revision = $this->setupTestRevisionsForEventGeneration( 
$newId, $oldId, $username, $lang, $pages, $title );
-
                $events = array();
                $this->setupEventCallbackForEventGeneration(
                        function ( EchoEvent $event ) use ( &$events ) {
@@ -378,8 +429,10 @@
                        }
                );
 
-               // enable mention failure and success notifications
-               $this->setMwGlobals( 'wgEchoMentionStatusNotifications', true );
+               $this->setMwGlobals( array(
+                       // enable mention failure and success notifications
+                       'wgEchoMentionStatusNotifications' => true,
+               ) );
 
                EchoDiscussionParser::generateEventsForRevision( $revision );
 
diff --git a/tests/phpunit/revision_txt/747747750.txt 
b/tests/phpunit/revision_txt/747747750.txt
new file mode 100644
index 0000000..3dbacfb
--- /dev/null
+++ b/tests/phpunit/revision_txt/747747750.txt
@@ -0,0 +1,11 @@
+== Hello World ==
+
+Hello!
+
+== Hello Users ==
+
+Try to mention existing user:
+
+[[User:Test11]]
+
+[[:User:Admin|Admin]] 13:22, 23 June 2016 (UTC)
\ No newline at end of file

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

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

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

Reply via email to