Sbisson has uploaded a new change for review.

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

Change subject: Flow notification presentation models
......................................................................

Flow notification presentation models

* new-topic
* post-edited
* post-reply
* topic-renamed

Bug: T116845
Change-Id: Ic64688253d0a96d5160bf10c1cfc1269e4df3857
---
M autoload.php
M i18n/en.json
M i18n/qqq.json
M includes/Notifications/Controller.php
A includes/Notifications/NewTopicPresentationModel.php
M includes/Notifications/Notifications.php
A includes/Notifications/PostEditedPresentationModel.php
A includes/Notifications/PostReplyPresentationModel.php
A includes/Notifications/TopicRenamedPresentationModel.php
9 files changed, 269 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow 
refs/changes/12/251512/1

diff --git a/autoload.php b/autoload.php
index a7391bc..c6fe845 100644
--- a/autoload.php
+++ b/autoload.php
@@ -245,6 +245,7 @@
        'Flow\\Model\\WikiReference' => __DIR__ . 
'/includes/Model/WikiReference.php',
        'Flow\\Model\\Workflow' => __DIR__ . '/includes/Model/Workflow.php',
        'Flow\\NewTopicFormatter' => __DIR__ . 
'/includes/Notifications/Formatter.php',
+       'Flow\\NewTopicPresentationModel' => __DIR__ . 
'/includes/Notifications/NewTopicPresentationModel.php',
        'Flow\\NotificationController' => __DIR__ . 
'/includes/Notifications/Controller.php',
        'Flow\\NotificationFormatter' => __DIR__ . 
'/includes/Notifications/Formatter.php',
        'Flow\\NotificationsUserLocator' => __DIR__ . 
'/includes/Notifications/UserLocator.php',
@@ -266,6 +267,8 @@
        'Flow\\Parsoid\\ReferenceExtractor' => __DIR__ . 
'/includes/Parsoid/ReferenceExtractor.php',
        'Flow\\Parsoid\\ReferenceFactory' => __DIR__ . 
'/includes/Parsoid/ReferenceFactory.php',
        'Flow\\Parsoid\\Utils' => __DIR__ . '/includes/Parsoid/Utils.php',
+       'Flow\\PostEditedPresentationModel' => __DIR__ . 
'/includes/Notifications/PostEditedPresentationModel.php',
+       'Flow\\PostReplyPresentationModel' => __DIR__ . 
'/includes/Notifications/PostReplyPresentationModel.php',
        'Flow\\RecoverableErrorHandler' => __DIR__ . 
'/includes/RecoverableErrorHandler.php',
        'Flow\\ReferenceClarifier' => __DIR__ . 
'/includes/ReferenceClarifier.php',
        'Flow\\Repository\\MultiGetList' => __DIR__ . 
'/includes/Repository/MultiGetList.php',
@@ -377,6 +380,7 @@
        'Flow\\Tests\\TemplatingTest' => __DIR__ . 
'/tests/phpunit/TemplatingTest.php',
        'Flow\\Tests\\UrlGeneratorTest' => __DIR__ . 
'/tests/phpunit/UrlGeneratorTest.php',
        'Flow\\Tests\\WatchedTopicItemTest' => __DIR__ . 
'/tests/phpunit/WatchedTopicItemsTest.php',
+       'Flow\\TopicRenamedPresentationModel' => __DIR__ . 
'/includes/Notifications/TopicRenamedPresentationModel.php',
        'Flow\\UrlGenerator' => __DIR__ . '/includes/UrlGenerator.php',
        'Flow\\Utils\\NamespaceIterator' => __DIR__ . 
'/includes/Utils/NamespaceIterator.php',
        'Flow\\Utils\\PagesWithPropertyIterator' => __DIR__ . 
'/includes/Utils/PagesWithPropertyIterator.php',
diff --git a/i18n/en.json b/i18n/en.json
index 7ae5033..f57d3d7 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -268,6 +268,11 @@
        "flow-notification-reply-bundle": "<span class=\"plainlinks 
mw-echo-title-heading\">[$4 $2]</span><br />$1 and $5 
{{PLURAL:$6|other|others}} {{GENDER:$1|responded}} on '''$3'''.",
        "flow-notification-edit": "<span class=\"plainlinks 
mw-echo-title-heading\">[$6 $2]</span><br />$1 has {{GENDER:$1|edited}} your 
<span class=\"plainlinks\">[$5 post]</span> 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\".",
+       "notification-header-flow-new-topic": "$4",
+       "notification-body-flow-new-topic": "$1 {{GENDER:$2|created}} a new 
topic on $3",
+       "notification-header-flow-post-reply": "$4",
+       "notification-body-flow-post-reply": "$1 {{GENDER:$2|responded}} on $3",
+       "notification-header-flow-topic-renamed": "$1 {{GENDER:$2|changed}} the 
title of \"$3\" to \"$4\" on $5",
        "flow-notification-newtopic": "<span class=\"mw-echo-title-heading 
plainlinks\">[$5 $4]</span><br />$1 {{GENDER:$1|created}} a new topic on 
'''$3'''.",
        "flow-notification-newtopic-bundle": "{{PLURAL:$1|$1 new topic|$1 new 
topics|250=250+ new topics}} on '''<span class=\"plainlinks\">[$3 
$2]</span>'''",
        "flow-notification-rename": "$1 {{GENDER:$1|changed}} the title of 
<span class=\"plainlinks\">[$2 $3]</span> to \"$4\" on [[$5|$6]].",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 2bdfc67..80e769d 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -276,6 +276,11 @@
        "flow-notification-reply-bundle": "Notification text for when a user 
receives replies from multiple users on the same topic.\n\nParameters:\n* $1 - 
username of the person who replied\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 
post\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-reply-email-batch-bundle-body}}\n{{Related|Flow-notification}}",
        "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* $6 - 
permanent URL for the topic\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}}",
+       "notification-header-flow-new-topic": "Notification header text for 
when a new topic is created. Parameters:\n$1 - the formatted username of the 
user who created the topic\n* $2 - the username for gender purposes\n* $3 - 
title of the Flow board\n* $4 - title of the 
topic.\n{{Related|Flow-notification}}",
+       "notification-body-flow-new-topic": "Notification body text for when a 
new topic is created. Parameters:\n$1 - the formatted username of the user who 
created the topic\n* $2 - the username for gender purposes\n* $3 - title of the 
Flow board\n* $4 - title of the topic.\n{{Related|Flow-notification}}",
+       "notification-header-flow-post-reply": "Notification header text for 
when there is a reply on a topic. Parameters:\n$1 - the formatted username of 
the user who replied to the topic\n* $2 - the username for gender purposes\n* 
$3 - title of the Flow board\n* $4 - title of the 
topic.\n{{Related|Flow-notification}}",
+       "notification-body-flow-post-reply": "Notification body text for when 
there is a reply on a topic. Parameters:\n$1 - the formatted username of the 
user who replied to the topic\n* $2 - the username for gender purposes\n* $3 - 
title of the Flow board\n* $4 - title of the 
topic.\n{{Related|Flow-notification}}",
+       "notification-header-flow-topic-renamed": "Notification header text for 
when a topic is renamed. Parameters:\n$1 - the formatted username of the user 
who renamed the topic\n* $2 - the username for gender purposes\n* $3 - old 
title of the topic\n* $4 - new title of the topic\n* $5 - title of the Flow 
board.\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 - Fully qualified url to 
view the created 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* $3 - Fully qualified url to view the 
related board sorted by newest topics.\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}}",
diff --git a/includes/Notifications/Controller.php 
b/includes/Notifications/Controller.php
index a610318..01e7a80 100644
--- a/includes/Notifications/Controller.php
+++ b/includes/Notifications/Controller.php
@@ -114,8 +114,9 @@
 
                        break;
                        case 'flow-topic-renamed':
+                               $previousRevision = 
$revision->getCollection()->getPrevRevision( $revision );
                                $extraData += array(
-                                       'old-subject' => 
$this->language->truncate( trim( $topicRevision->getContent( 'wikitext' ) ), 
200 ),
+                                       'old-subject' => 
$this->language->truncate( trim( $previousRevision->getContent( 'wikitext' ) ), 
200 ),
                                        'new-subject' => 
$this->language->truncate( trim( $revision->getContent( 'wikitext' ) ), 200 ),
                                );
                        break;
diff --git a/includes/Notifications/NewTopicPresentationModel.php 
b/includes/Notifications/NewTopicPresentationModel.php
new file mode 100644
index 0000000..2d1807e
--- /dev/null
+++ b/includes/Notifications/NewTopicPresentationModel.php
@@ -0,0 +1,41 @@
+<?php
+
+namespace Flow;
+
+use EchoEventPresentationModel;
+
+class NewTopicPresentationModel extends EchoEventPresentationModel {
+
+       public function canRender() {
+               return (bool)$this->event->getTitle();
+       }
+
+       public function getIconType() {
+               return 'flow-discussion';
+       }
+
+       public function getPrimaryLink() {
+               /** @var UrlGenerator $urlGenerator */
+               $urlGenerator = Container::get( 'url_generator' );
+               $url = $urlGenerator->boardLink( $this->event->getTitle(), 
'newest' )->getFullURL();
+               $text = $this->msg( 'flow-notification-link-text-view-topic' 
)->text();
+               return array( $url, $text );
+       }
+
+       public function getHeaderMessage() {
+               $msg = parent::getHeaderMessage();
+               $msg->params( $this->event->getTitle()->getPrefixedText() );
+               $msg->params( $this->event->getExtraParam( 'topic-title' ) );
+               return $msg;
+       }
+
+       public function getBodyMessage() {
+               $msg = $this->msg( 'notification-body-flow-new-topic' );
+               list( $formattedName, $genderName ) = 
$this->getAgentForOutput();
+               $msg->params( $formattedName, $genderName );
+               $msg->params( $this->event->getTitle()->getPrefixedText() );
+               $msg->params( $this->event->getExtraParam( 'topic-title' ) );
+               return $msg;
+       }
+
+}
\ No newline at end of file
diff --git a/includes/Notifications/Notifications.php 
b/includes/Notifications/Notifications.php
index d92d315..63b8e61 100644
--- a/includes/Notifications/Notifications.php
+++ b/includes/Notifications/Notifications.php
@@ -11,6 +11,7 @@
 
 $notifications = array(
        'flow-new-topic' => array(
+               'presentation-model' => 'Flow\\NewTopicPresentationModel',
                'formatter-class' => 'Flow\NewTopicFormatter',
                'user-locators' => array(
                        'EchoUserLocator::locateUsersWatchingTitle',
@@ -37,6 +38,7 @@
                'email-body-batch-bundle-params' => array( 'event-count', 
'title', 'new-topics-permalink' ),
        ) + $notificationTemplate,
        'flow-post-reply' => array(
+               'presentation-model' => 'Flow\\PostReplyPresentationModel',
                'user-locators' => array(
                        
'Flow\\NotificationsUserLocator::locateUsersWatchingTopic',
                ),
@@ -60,6 +62,7 @@
                'email-body-batch-bundle-params' => array( 'agent', 'subject', 
'title', 'agent-other-display', 'agent-other-count' ),
        ) + $notificationTemplate,
        'flow-post-edited' => array(
+               'presentation-model' => 'Flow\\PostEditedPresentationModel',
                'primary-link' => array(
                        'message' => 'flow-notification-link-text-view-post',
                        'destination' => 'flow-post'
@@ -80,6 +83,7 @@
                'email-body-batch-bundle-params' => array( 'agent', 'subject', 
'title', 'agent-other-display', 'agent-other-count' ),
        ) + $notificationTemplate,
        'flow-topic-renamed' => array(
+               'presentation-model' => 'Flow\\TopicRenamedPresentationModel',
                'primary-link' => array(
                        'message' => 'flow-notification-link-text-view-post',
                        'destination' => 'flow-post'
diff --git a/includes/Notifications/PostEditedPresentationModel.php 
b/includes/Notifications/PostEditedPresentationModel.php
new file mode 100644
index 0000000..eb00eee
--- /dev/null
+++ b/includes/Notifications/PostEditedPresentationModel.php
@@ -0,0 +1,72 @@
+<?php
+
+namespace Flow;
+
+use EchoEventPresentationModel;
+use Flow\Model\UUID;
+use Title;
+
+class PostEditedPresentationModel extends EchoEventPresentationModel {
+
+       public function canRender() {
+               $validTitle = (bool)$this->event->getTitle();
+               $validWorkflowId = $this->event->getExtraParam( 
'topic-workflow' ) instanceof UUID;
+               $validPostId = $this->event->getExtraParam( 'post-id' ) 
instanceof UUID;
+               return $validTitle && $validWorkflowId && $validPostId;
+       }
+
+       public function getIconType() {
+               return 'flow-discussion';
+       }
+
+       public function getPrimaryLink() {
+               $url = $this->getPostLinkUrl();
+               $text = $this->msg( 'flow-notification-link-text-view-post' 
)->text();
+               return array( $url, $text );
+       }
+
+       public function getHeaderMessage() {
+               $msg = parent::getHeaderMessage();
+               $msg->params( $this->event->getTitle()->getPrefixedText() );
+               $msg->params( $this->event->getExtraParam( 'topic-title' ) );
+               return $msg;
+       }
+
+       public function getBodyMessage() {
+               $msg = $this->msg( 'notification-body-flow-post-reply' );
+               list( $formattedName, $genderName ) = 
$this->getAgentForOutput();
+               $msg->params( $formattedName, $genderName );
+               $msg->params( $this->event->getTitle()->getPrefixedText() );
+               $msg->params( $this->event->getExtraParam( 'topic-title' ) );
+               return $msg;
+       }
+
+       /**
+        * Return a full url of following format:
+        *   
https://<site>/wiki/Topic:<topicId>?topic_showPostId=<postId>&fromnotif=1#flow-post-<postId>
+        * @todo: Generate a url to the first unread post of a topic when we 
figure out bundling in the new email formatter.
+        * @return string
+        */
+       protected function getPostLinkUrl() {
+               /** @var UUID $workflowId */
+               $workflowId = $this->event->getExtraParam( 'topic-workflow' );
+               /** @var UUID $postId */
+               $postId = $this->event->getExtraParam( 'post-id' );
+
+               $title = Title::makeTitleSafe(
+                       NS_TOPIC,
+                       $workflowId->getAlphadecimal(),
+                       'flow-post-' . $postId->getAlphadecimal()
+               );
+
+               $url = $title->getFullURL(
+                       array(
+                               'topic_showPostId' => 
$postId->getAlphadecimal(),
+                               'fromnotif' => 1,
+                       )
+               );
+
+               return $url;
+       }
+
+}
diff --git a/includes/Notifications/PostReplyPresentationModel.php 
b/includes/Notifications/PostReplyPresentationModel.php
new file mode 100644
index 0000000..f569e74
--- /dev/null
+++ b/includes/Notifications/PostReplyPresentationModel.php
@@ -0,0 +1,72 @@
+<?php
+
+namespace Flow;
+
+use EchoEventPresentationModel;
+use Flow\Model\UUID;
+use Title;
+
+class PostReplyPresentationModel extends EchoEventPresentationModel {
+
+       public function canRender() {
+               $validTitle = (bool)$this->event->getTitle();
+               $validWorkflowId = $this->event->getExtraParam( 
'topic-workflow' ) instanceof UUID;
+               $validPostId = $this->event->getExtraParam( 'post-id' ) 
instanceof UUID;
+               return $validTitle && $validWorkflowId && $validPostId;
+       }
+
+       public function getIconType() {
+               return 'flow-discussion';
+       }
+
+       public function getPrimaryLink() {
+               $url = $this->getPostLinkUrl();
+               $text = $this->msg( 'flow-notification-link-text-view-post' 
)->text();
+               return array( $url, $text );
+       }
+
+       public function getHeaderMessage() {
+               $msg = parent::getHeaderMessage();
+               $msg->params( $this->event->getTitle()->getPrefixedText() );
+               $msg->params( $this->event->getExtraParam( 'topic-title' ) );
+               return $msg;
+       }
+
+       public function getBodyMessage() {
+               $msg = $this->msg( 'notification-body-flow-post-reply' );
+               list( $formattedName, $genderName ) = 
$this->getAgentForOutput();
+               $msg->params( $formattedName, $genderName );
+               $msg->params( $this->event->getTitle()->getPrefixedText() );
+               $msg->params( $this->event->getExtraParam( 'topic-title' ) );
+               return $msg;
+       }
+
+       /**
+        * Return a full url of following format:
+        *   
https://<site>/wiki/Topic:<topicId>?topic_showPostId=<postId>&fromnotif=1#flow-post-<postId>
+        * @todo: Generate a url to the first unread post of a topic when we 
figure out bundling in the new email formatter.
+        * @return string
+        */
+       protected function getPostLinkUrl() {
+               /** @var UUID $workflowId */
+               $workflowId = $this->event->getExtraParam( 'topic-workflow' );
+               /** @var UUID $postId */
+               $postId = $this->event->getExtraParam( 'post-id' );
+
+               $title = Title::makeTitleSafe(
+                       NS_TOPIC,
+                       $workflowId->getAlphadecimal(),
+                       'flow-post-' . $postId->getAlphadecimal()
+               );
+
+               $url = $title->getFullURL(
+                       array(
+                               'topic_showPostId' => 
$postId->getAlphadecimal(),
+                               'fromnotif' => 1,
+                       )
+               );
+
+               return $url;
+       }
+
+}
diff --git a/includes/Notifications/TopicRenamedPresentationModel.php 
b/includes/Notifications/TopicRenamedPresentationModel.php
new file mode 100644
index 0000000..8b967e3
--- /dev/null
+++ b/includes/Notifications/TopicRenamedPresentationModel.php
@@ -0,0 +1,64 @@
+<?php
+
+namespace Flow;
+
+use EchoEventPresentationModel;
+use Flow\Model\UUID;
+use Title;
+
+class TopicRenamedPresentationModel extends EchoEventPresentationModel {
+
+       public function canRender() {
+               $validTitle = (bool)$this->event->getTitle();
+               $validWorkflowId = $this->event->getExtraParam( 
'topic-workflow' ) instanceof UUID;
+               $validPostId = $this->event->getExtraParam( 'post-id' ) 
instanceof UUID;
+               return $validTitle && $validWorkflowId && $validPostId;
+       }
+
+       public function getIconType() {
+               return 'flow-discussion';
+       }
+
+       public function getPrimaryLink() {
+               $url = $this->getPostLinkUrl();
+               $text = $this->msg( 'flow-notification-link-text-view-post' 
)->text();
+               return array( $url, $text );
+       }
+
+       public function getHeaderMessage() {
+               $msg = parent::getHeaderMessage();
+               $msg->params( $this->event->getExtraParam( 'old-subject' ) );
+               $msg->params( $this->event->getExtraParam( 'new-subject' ) );
+               $msg->params( $this->event->getTitle()->getPrefixedText() );
+               return $msg;
+       }
+
+       /**
+        * Return a full url of following format:
+        *   
https://<site>/wiki/Topic:<topicId>?topic_showPostId=<postId>&fromnotif=1#flow-post-<postId>
+        * @todo: Generate a url to the first unread post of a topic when we 
figure out bundling in the new email formatter.
+        * @return string
+        */
+       protected function getPostLinkUrl() {
+               /** @var UUID $workflowId */
+               $workflowId = $this->event->getExtraParam( 'topic-workflow' );
+               /** @var UUID $postId */
+               $postId = $this->event->getExtraParam( 'post-id' );
+
+               $title  = Title::makeTitleSafe(
+                       NS_TOPIC,
+                       $workflowId->getAlphadecimal(),
+                       'flow-post-' . $postId->getAlphadecimal()
+               );
+
+               $url = $title->getFullURL(
+                       array(
+                               'topic_showPostId' => 
$postId->getAlphadecimal(),
+                               'fromnotif' => 1,
+                       )
+               );
+
+               return $url;
+       }
+
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic64688253d0a96d5160bf10c1cfc1269e4df3857
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Sbisson <[email protected]>

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

Reply via email to