jenkins-bot has submitted this change and it was merged.

Change subject: Bundle new-topic notifications
......................................................................


Bundle new-topic notifications

Better would be to teach Echo how to bundle things in different ways, but for
now this is a reasonable first step.

Currently bundled output messages are only enabled when more than one
user triggeres those events.  This works great for messages like:

    User X posts on your talk page

When the bundle would say:

    User X and 0 others posted on your talk page

But bundled messages that display a count of events, like:

    N new topics were posted to X

will want to use the bundled messaging any time the event count
is > 1, regardless of the number of users performing the event.

This patch makes the flow-new-topic notifications use the second method.

Change-Id: I3e95d82d5e5ee8f896b53082ec2bbd309c5681f5
---
M Flow.php
M i18n/en.json
M i18n/qqq.json
M includes/Notifications/Controller.php
M includes/Notifications/Formatter.php
M includes/Notifications/Notifications.php
6 files changed, 69 insertions(+), 3 deletions(-)

Approvals:
  EBernhardson: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/Flow.php b/Flow.php
index e39423b..9749f26 100755
--- a/Flow.php
+++ b/Flow.php
@@ -84,6 +84,7 @@
 $wgAutoloadClasses['Flow\OccupationController'] = $dir . 
'includes/TalkpageManager.php';
 $wgAutoloadClasses['Flow\TalkpageManager'] = $dir . 
'includes/TalkpageManager.php';
 $wgAutoloadClasses['Flow\NotificationFormatter'] = $dir . 
'includes/Notifications/Formatter.php';
+$wgAutoloadClasses['Flow\NewTopicFormatter'] = $dir . 
'includes/Notifications/Formatter.php';
 $wgAutoloadClasses['Flow\NotificationController'] = $dir . 
'includes/Notifications/Controller.php';
 $wgAutoloadClasses['Flow\NotificationsUserLocator'] = $dir . 
'includes/Notifications/UserLocator.php';
 $wgAutoloadClasses['Flow\SpamFilter\Controller'] = $dir . 
'includes/SpamFilter/Controller.php';
diff --git a/i18n/en.json b/i18n/en.json
index b4f0ff2..c7b3676 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -220,6 +220,7 @@
     "flow-notification-edit": "$1 {{GENDER:$1|edited}} a <span 
class=\"plainlinks\">[$5 post]</span> in \"$2\" on [[$3|$4]].",
     "flow-notification-edit-bundle": "$1 and $5 {{PLURAL:$6|other|others}} 
{{GENDER:$1|edited}} a <span class=\"plainlinks\">[$4 post]</span> in \"$2\" on 
\"$3\".",
     "flow-notification-newtopic": "<span 
class=\"mw-echo-title-heading\">$4</span><br />$1 {{GENDER:$1|created}} a <span 
class=\"plainlinks\">[$5 new topic]</span> on '''$3'''.",
+    "flow-notification-newtopic-bundle": "{{PLURAL:$1|$1|250=250+}} new 
{{PLURAL:$1|topic|topics}} on '''$2'''",
     "flow-notification-rename": "$1 {{GENDER:$1|changed}} the title of <span 
class=\"plainlinks\">[$2 $3]</span> to \"$4\" on [[$5|$6]].",
     "flow-notification-mention": "$1 {{GENDER:$1|mentioned}} {{GENDER:$5|you}} 
in {{GENDER:$1|his|her|their}} <span class=\"plainlinks\">[$2 post]</span> in 
\"$3\" on \"$4\".",
     "flow-notification-link-text-view-post": "View post",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index e52d0b0..2932aff 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -224,6 +224,7 @@
        "flow-notification-edit": "Notification text for when a user's post is 
edited. Parameters:\n* $1 - username of the person who edited the post\n* $2 - 
title of the topic\n* $3 - title for the Flow board\n* $4 - title for the page 
that the Flow board is attached to\n* $5 - permanent URL for the 
post\n{{Related|Flow-notification}}",
        "flow-notification-edit-bundle": "Notification text for when a user 
receives post edits from multiple users on the same topic.\n\nParameters:\n* $1 
- username of the person who edited post\n* $2 - title of the topic\n* $3 - 
title for the page that the Flow board is attached to\n* $4 - permantent URL 
for the topic\n* $5 - the count of other action performers, could be number or 
{{msg-mw|Echo-notification-count}}. e.g. 7 others or 99+ others\n* $6 - a 
number used for plural support\nSee also:\n* 
{{msg-mw|Flow-notification-edit-email-batch-bundle-body}}\n{{Related|Flow-notification}}",
        "flow-notification-newtopic": "Notification text for when a new topic 
is created. Parameters:\n* $1 - username of the person who created the topic\n* 
$2 - (Unused) title for the Flow board\n* $3 - title for the page that the Flow 
board is attached to\n* $4 - title of the topic\n* $5 - permanent URL for the 
topic\n{{Related|Flow-notification}}",
+       "flow-notification-newtopic-bundle": "Notification text for when 
multiple new topics are created on the same page. Parameters:\n* $1 - The 
number of topics that were created. This value is capped to 250. When this 
value is 250 it means 250 or more topics have been created.\n* $2 - The title 
of the page the topics were created on\n{{Related|Flow-notification}}",
        "flow-notification-rename": "Notification text for when the subject of 
a topic is changed. Parameters:\n* $1 - username of the person who edited the 
title, can be used for GENDER\n* $2 - permalink to the topic\n* $3 - old topic 
subject\n* $4 - new topic subject\n* $5 - title for the Flow board\n* $6 - 
title for the page that the Flow board is attached 
to\n{{Related|Flow-notification}}",
        "flow-notification-mention": "{{doc-singularthey}}\nNotification text 
for when a user is mentioned in another conversation. Parameters:\n* $1 - 
username of the person who made the post, can be used for GENDER\n* $2 - 
permalink to the post\n* $3 - title of the topic\n* $4 - title for the page 
that the Flow board is attached to\n* $5 - username of the person who receives 
the notification, can be used for GENDER\n{{Related|Flow-notification}}",
        "flow-notification-link-text-view-post": "Label for button that links 
to a flow post.",
diff --git a/includes/Notifications/Controller.php 
b/includes/Notifications/Controller.php
index 901cde7..8c83f51 100644
--- a/includes/Notifications/Controller.php
+++ b/includes/Notifications/Controller.php
@@ -381,10 +381,16 @@
         */
        public static function onEchoGetBundleRules( $event, &$bundleString ) {
                switch ( $event->getType() ) {
+                       case 'flow-new-topic':
+                               $board = $event->getExtraParam( 
'board-workflow' );
+                               if ( $board instanceof UUID ) {
+                                       $bundleString = $event->getType() . '-' 
. $board->getAlphadecimal();
+                               }
+                       break;
+
                        case 'flow-post-reply':
                        case 'flow-post-edited':
-                               $extra = $event->getExtra();
-                               $topic = $extra['topic-workflow'];
+                               $topic = $event->getExtraParam( 
'topic-workflow' );
                                if ( $topic instanceof UUID ) {
                                        $bundleString = $event->getType() . '-' 
. $topic->getAlphadecimal();
                                }
diff --git a/includes/Notifications/Formatter.php 
b/includes/Notifications/Formatter.php
index bcef08a..c920709 100644
--- a/includes/Notifications/Formatter.php
+++ b/includes/Notifications/Formatter.php
@@ -130,6 +130,13 @@
                                }
                                break;
 
+                       case 'flow-new-topics':
+                               $title  = $event->getTitle();
+                               if ( $title ) {
+                                       $anchor = $urlGenerator->boardLink( 
$title, 'newest' );
+                               }
+                               break;
+
                        default:
                                return parent::getLinkParams( $event, $user, 
$destination );
                }
@@ -179,3 +186,43 @@
                return false;
        }
 }
+
+/**
+ * @FIXME - Move bundle iterator logic into a centralized place in Echo and
+ * introduce bundle type param like 'agent', 'page', 'event' so child formatter
+ * only needs to specify what iterator to use
+ */
+class NewTopicFormatter extends NotificationFormatter {
+
+       /**
+        * New Topic user 'event' as the iterator
+        */
+       protected function generateBundleData( $event, $user, $type ) {
+               $data = $this->getRawBundleData( $event, $user, $type );
+
+               if ( !$data ) {
+                       return;
+               }
+
+               // bundle event is excluding base event
+               $this->bundleData['event-count'] = count( $data ) + 1;
+               $this->bundleData['use-bundle']  = 
$this->bundleData['event-count'] > 1;
+       }
+
+       /**
+        * @param $event EchoEvent
+        * @param $param string
+        * @param $message Message
+        * @param $user User
+        */
+       protected function processParam( $event, $param, $message, $user ) {
+               switch ( $param ) {
+                       case 'event-count':
+                               $message->numParams( 
$this->bundleData['event-count'] );
+                               break;
+                       default:
+                               parent::processParam( $event, $param, $message, 
$user );
+                               break;
+               }
+       }
+}
diff --git a/includes/Notifications/Notifications.php 
b/includes/Notifications/Notifications.php
index f4f3be5..0d2c415 100644
--- a/includes/Notifications/Notifications.php
+++ b/includes/Notifications/Notifications.php
@@ -11,20 +11,30 @@
 
 $notifications = array(
        'flow-new-topic' => array(
+               'formatter-class' => 'Flow\NewTopicFormatter',
                'user-locators' => array(
                        'EchoUserLocator::locateUsersWatchingTitle',
                        'EchoUserLocator::locateTalkPageOwner'
                ),
                'primary-link' => array(
                        'message' => 'flow-notification-link-text-view-topic',
-                       'destination' => 'flow-topic'
+                       'destination' => 'flow-new-topics'
                ),
                'title-message' => 'flow-notification-newtopic',
                'title-params' => array( 'agent', 'flow-title', 'title', 
'subject', 'topic-permalink' ),
+               'bundle' => array(
+                       'web' => true,
+                       'email' => true,
+               ),
+               'bundle-type' => 'event',
+               'bundle-message' => 'flow-notification-newtopic-bundle',
+               'bundle-params' => array( 'event-count', 'title' ),
                'email-subject-message' => 
'flow-notification-newtopic-email-subject',
                'email-subject-params' => array( 'agent', 'title' ),
                'email-body-batch-message' => 
'flow-notification-newtopic-email-batch-body',
                'email-body-batch-params' => array( 'agent', 'subject', 'title' 
),
+               'email-body-batch-bundle-message' => 
'flow-notification-newtopic-bundle',
+               'email-body-batch-bundle-params' => array( 'event-count', 
'title' ),
        ) + $notificationTemplate,
        'flow-post-reply' => array(
                'user-locators' => array(

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I3e95d82d5e5ee8f896b53082ec2bbd309c5681f5
Gerrit-PatchSet: 12
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>
Gerrit-Reviewer: Bsitu <[email protected]>
Gerrit-Reviewer: EBernhardson <[email protected]>
Gerrit-Reviewer: Matthias Mullie <[email protected]>
Gerrit-Reviewer: SG <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to