Cicalese has submitted this change and it was merged.

Change subject: Add support for Echo notifications.
......................................................................


Add support for Echo notifications.

Requires REL1_27 of Echo for notification support. If Echo is not
installed, works on MediaWiki 1.25+.

Change-Id: I83b1cebaed2cdbffcf14992d95b80ccd1f94e637
---
M extension.json
M i18n/en.json
M i18n/qqq.json
M includes/ApiCSPostComment.php
M includes/Comment.php
M includes/CommentStreamsHooks.php
A includes/EchoCSFormatter.php
A includes/EchoCSReplyPresentationModel.php
A includes/EchoCSWatchedPresentationModel.php
9 files changed, 441 insertions(+), 14 deletions(-)

Approvals:
  Cicalese: Verified; Looks good to me, approved



diff --git a/extension.json b/extension.json
index 49bc55b..19c0369 100644
--- a/extension.json
+++ b/extension.json
@@ -1,6 +1,6 @@
 {
        "name": "CommentStreams",
-       "version": "2.1",
+       "version": "3.0",
        "author": [
                "[http://www.mediawiki.org/wiki/User:Jji Jason Ji]",
                "[http://www.mediawiki.org/wiki/User:Cindy.cicalese Cindy 
Cicalese]"
@@ -81,7 +81,11 @@
                "ApiCSPostComment": "includes/ApiCSPostComment.php",
                "ApiCSQueryComment": "includes/ApiCSQueryComment.php",
                "ApiCSEditComment": "includes/ApiCSEditComment.php",
-               "ApiCSDeleteComment": "includes/ApiCSDeleteComment.php"
+               "ApiCSDeleteComment": "includes/ApiCSDeleteComment.php",
+               "EchoCSFormatter": "includes/EchoCSFormatter.php",
+               "EchoCSReplyPresentationModel": 
"includes/EchoCSReplyPresentationModel.php",
+               "EchoCSWatchedPresentationModel":
+                       "includes/EchoCSWatchedPresentationModel.php"
        },
        "APIModules": {
                "csPostComment": "ApiCSPostComment",
@@ -99,7 +103,8 @@
                "BeforePageDisplay": 
"CommentStreamsHooks::addCommentsAndInitializeJS",
                "ShowSearchHitTitle": "CommentStreamsHooks::showSearchHitTitle",
                "smwInitProperties": "CommentStreamsHooks::initProperties",
-               "SMWStore::updateDataBefore": "CommentStreamsHooks::updateData"
+               "SMWStore::updateDataBefore": "CommentStreamsHooks::updateData",
+               "BeforeCreateEchoEvent": 
"CommentStreamsHooks::onBeforeCreateEchoEvent"
        },
        "callback" : "CommentStreamsHooks::onRegistration",
        "config": {
diff --git a/i18n/en.json b/i18n/en.json
index 3995216..72623ed 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -64,5 +64,17 @@
        "commentstreams-datetext-postedon": "Posted on",
        "commentstreams-datetext-lasteditedon": "Last edited on",
        "commentstreams-title-field-placeholder": "Enter title...",
-       "commentstreams-body-field-placeholder": "Enter new comment text..."
+       "commentstreams-body-field-placeholder": "Enter new comment text...",
+       "echo-category-title-commentstreams-notification-category":
+               "New comments and replies",
+       "notification-header-commentstreams-comment-on-watched-page": "$1 
{{GENDER:$4|commented}} <i>$2</i> on <i>$3</i>, which {{GENDER:$5|you}} are 
watching.",
+       "notification-header-commentstreams-reply-on-watched-page": "$1 
{{GENDER:$4|replied}} to <i>$2</i> on <i>$3</i>, which {{GENDER:$5|you}} are 
watching.",
+       "notification-header-commentstreams-reply-to-author": "$1 
{{GENDER:$4|replied}} to {{GENDER:$5|your}} comment <i>$2</i> on <i>$3</i>.",
+       "commentstreams-email-subject-message-comment-on-watched-page": 
"Somebody has commented on a page you are watching",
+       "commentstreams-email-body-message-comment-on-watched-page": "$2 has 
commented \"$3\" on $4, a page you are watching. Click the link to visit the 
page: $5. The comment is:\n\n$6",
+       "commentstreams-email-subject-message-reply-on-watched-page": "Somebody 
has replied to a comment on a page you are watching",
+       "commentstreams-email-body-message-reply-on-watched-page": "$2 has 
replied to \"$3\" on $4, a page you are watching. Click the link to visit the 
page: $5. The reply is:\n\n$6",
+       "commentstreams-email-subject-message-reply-to-author": "Somebody has 
replied to one of your comments",
+       "commentstreams-email-body-message-reply-to-author": "$2 has replied to 
your comment \"$3\" on $4. Click the link to visit the page: $5. The reply 
is:\n\n$6",
+       "notification-commentstreams-page": "Visit page"
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index f697177..b0e3401 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -64,5 +64,16 @@
        "commentstreams-datetext-postedon": "User interface date text",
        "commentstreams-datetext-lasteditedon": "User interface date text",
        "commentstreams-title-field-placeholder": "Text field placeholder text",
-       "commentstreams-body-field-placeholder": "Text field placeholder text"
+       "commentstreams-body-field-placeholder": "Text field placeholder text",
+       "echo-category-title-commentstreams-notification-category": "Name of 
category on Prefences/Notifications page for CommentStreams notifications",
+       "notification-header-commentstreams-comment-on-watched-page": 
"Flyout-specific format for displaying notification header of a new comment on 
a watched page.\n\nParameters:\n* $1 - the formatted username of the person who 
commented.\n* $2 - the comment title.\n* $3 - the display name of the page 
being commented on.\n* $4 - the username of the person who commented (for 
gender).\n* $5 - the username of the viewing user (for gender).",
+       "notification-header-commentstreams-reply-on-watched-page": 
"Flyout-specific format for displaying notification header of a new reply on a 
watched page.\n\nParameters:\n* $1 - the formatted username of the person who 
commented.\n* $2 - the comment title.\n* $3 - the display name of the page 
being commented on.\n* $4 - the username of the person who commented (for 
gender).\n* $5 - the username of the viewing user (for gender).",
+       "notification-header-commentstreams-reply-to-author": "Flyout-specific 
format for displaying notification header of a reply to a comment by the 
user.\n\nParameters:\n* $1 - the formatted username of the person who 
commented.\n* $2 - the comment title.\n* $3 - the display name of the page 
being commented on.\n* $4 - the username of the person who commented (for 
gender).\n* $5 - the username of the viewing user (for gender).",
+       "commentstreams-email-subject-message-comment-on-watched-page": "Echo 
email subject.",
+       "commentstreams-email-body-message-comment-on-watched-page": "Echo 
email body.\n\nParameters:\n*$1 - the username of the user authoring the new 
comment.\n* $2 - the display name of the comment author.\n* $3 - the title of 
the comment.\n* $4 - the display title of the page being commented on.\n* $5 - 
a link to that page.\n* $6 - the wikitext of the new comment.",
+       "commentstreams-email-subject-message-reply-on-watched-page": "Echo 
email subject.",
+       "commentstreams-email-body-message-reply-on-watched-page": "Echo email 
body.\n\nParameters:\n*$1 - the username of the user authoring the new 
comment.\n* $2 - the display name of the comment author.\n* $3 - the title of 
the comment.\n* $4 - the display title of the page being commented on.\n* $5 - 
a link to that page.\n* $6 - the wikitext of the new comment.",
+       "commentstreams-email-subject-message-reply-to-author": "Echo email 
subject.",
+       "commentstreams-email-body-message-reply-to-author": "Echo email 
body.\n\nParameters:\n*$1 - the username of the user authoring the new 
comment.\n* $2 - the display name of the comment author.\n* $3 - the title of 
the comment.\n* $4 - the display title of the page being commented on.\n* $5 - 
a link to that page.\n* $6 - the wikitext of the new comment.",
+       "notification-commentstreams-page": "Visit page"
 }
diff --git a/includes/ApiCSPostComment.php b/includes/ApiCSPostComment.php
index 11026be..c00b7bc 100644
--- a/includes/ApiCSPostComment.php
+++ b/includes/ApiCSPostComment.php
@@ -62,7 +62,7 @@
                                        
'commentstreams-api-error-post-parentpagedoesnotexist' );
                        }
                        $parent_comment = Comment::newFromWikiPage( 
$parent_page );
-                       if ( $parent_comment->getAssociatedId() !== (integer) 
$associatedid ) {
+                       if ( $parent_comment->getAssociatedId() !== 
(integer)$associatedid ) {
                                $this->dieCustomUsageMessage(
                                        
'commentstreams-api-error-post-associatedpageidmismatch' );
                        }
@@ -83,6 +83,8 @@
 
                $this->getResult()->addValue( null, $this->getModuleName(),
                        $comment->getJSON() );
+
+               $this->sendNotifications( $comment, $associated_page );
        }
 
        /**
@@ -117,6 +119,78 @@
        }
 
        /**
+        * Send Echo notifications if Echo is installed.
+        *
+        * @param Comment $comment the comment to send notifications for
+        * @param WikiPage $associated_page the associated page for the comment
+        * @return not used
+        */
+       private function sendNotifications( $comment, $associated_page ) {
+               if ( !class_exists( 'EchoEvent' ) ) {
+                       return;
+               }
+
+               $parent_id = $comment->getParentId();
+               if ( is_null( $parent_id ) ) {
+                       $comment_title = $comment->getCommentTitle();
+               } else {
+                       $parent_page = WikiPage::newFromId( $parent_id );
+                       if ( is_null( $parent_page ) ) {
+                               return;
+                       }
+                       $parent_comment = Comment::newFromWikiPage( 
$parent_page );
+                       if ( is_null( $parent_comment ) ) {
+                               return;
+                       } else {
+                               $comment_title = 
$parent_comment->getCommentTitle();
+                       }
+               }
+
+               $associated_page_display_title =
+                       $associated_page->getTitle()->getPrefixedText();
+               if ( class_exists( 'PageProps' ) ) {
+                       $associated_title = $associated_page->getTitle();
+                       $values = PageProps::getInstance()->getProperties( 
$associated_title,
+                               'displaytitle' );
+                       if ( array_key_exists( 
$associated_title->getArticleID(), $values ) ) {
+                               $associated_page_display_title =
+                                       
$values[$associated_title->getArticleID()];
+                       }
+               }
+
+               $extra = [
+                       'comment' => $comment->getId(),
+                       'comment_author_username' => $comment->getUsername(),
+                       'comment_author_display_name' => 
$comment->getUserDisplayNameUnlinked(),
+                       'comment_title' => $comment_title,
+                       'associated_page_display_title' => 
$associated_page_display_title,
+                       'comment_wikitext' => $comment->getWikitext()
+               ];
+
+               if ( !is_null( $parent_id ) ) {
+                       EchoEvent::create( [
+                               'type' => 
'commentstreams-reply-on-watched-page',
+                               'title' => $associated_page->getTitle(),
+                               'extra' => $extra,
+                               'agent' => $this->getUser()
+                       ] );
+                       EchoEvent::create( [
+                               'type' => 'commentstreams-reply-to-author',
+                               'title' => $associated_page->getTitle(),
+                               'extra' => $extra,
+                               'agent' => $this->getUser()
+                       ] );
+               } else {
+                       EchoEvent::create( [
+                               'type' => 
'commentstreams-comment-on-watched-page',
+                               'title' => $associated_page->getTitle(),
+                               'extra' => $extra,
+                               'agent' => $this->getUser()
+                       ] );
+               }
+       }
+
+       /**
         * die with a custom usage message
         * @param string $message_name the name of the custom message
         */
diff --git a/includes/Comment.php b/includes/Comment.php
index d80ffde..cefbd57 100644
--- a/includes/Comment.php
+++ b/includes/Comment.php
@@ -103,7 +103,7 @@
                $success = false;
                while ( !$success ) {
                        $index = wfRandomString();
-                       $title = Title::newFromText( (string) $index, 
NS_COMMENTSTREAMS );
+                       $title = Title::newFromText( (string)$index, 
NS_COMMENTSTREAMS );
                        if ( !$title->isDeletedQuick() && !$title->exists() ) {
                                $wikipage = new WikiPage( $title );
                                $status = $wikipage->doEditContent( $content, 
'', EDIT_NEW, false,
@@ -167,10 +167,10 @@
                        __METHOD__
                );
                if ( $result ) {
-                       $this->assoc_page_id = (integer) $result->assoc_page_id;
+                       $this->assoc_page_id = (integer)$result->assoc_page_id;
                        $this->parent_page_id = $result->parent_page_id;
                        if ( !is_null( $this->parent_page_id ) ) {
-                               $this->parent_page_id = (integer) 
$this->parent_page_id;
+                               $this->parent_page_id = 
(integer)$this->parent_page_id;
                        }
                        $this->comment_title = $result->comment_title;
                        $this->loaded = true;
@@ -187,10 +187,10 @@
         */
        private function loadFromValues( $assoc_page_id, $parent_page_id,
                $comment_title ) {
-               $this->assoc_page_id = (integer) $assoc_page_id;
+               $this->assoc_page_id = (integer)$assoc_page_id;
                $this->parent_page_id = $parent_page_id;
                if ( !is_null( $this->parent_page_id ) ) {
-                       $this->parent_page_id = (integer) $this->parent_page_id;
+                       $this->parent_page_id = (integer)$this->parent_page_id;
                }
                $this->comment_title = $comment_title;
                $this->loaded = true;
@@ -288,10 +288,18 @@
        }
 
        /**
-        * @return string username of the author of this comment
+        * @return string display name of the author of this comment linked to
+        * the user's user page if it exists
         */
        public function getUserDisplayName() {
                return self::getDisplayNameFromUser( $this->getUser() );
+       }
+
+       /**
+        * @return string display name of the author of this comment
+        */
+       public function getUserDisplayNameUnlinked() {
+               return self::getDisplayNameFromUser( $this->getUser(), false );
        }
 
        /**
@@ -549,9 +557,11 @@
         * return the text to use to represent the user at the top of a comment
         *
         * @param User $user the user
+        * @param boolean $linked whether to link the display name to the user 
page,
+        * if it exists
         * @return string display name for user
         */
-       public static function getDisplayNameFromUser( $user ) {
+       public static function getDisplayNameFromUser( $user, $linked = true ) {
                $userpage = $user->getUserPage();
                $displayname = null;
                if ( !is_null( 
$GLOBALS['wgCommentStreamsUserRealNamePropertyName'] ) ) {
@@ -573,7 +583,7 @@
                if ( is_null( $displayname ) || strlen( $displayname ) == 0 ) {
                        $displayname = $user->getName();
                }
-               if ( $userpage->exists() ) {
+               if ( $linked && $userpage->exists() ) {
                        $displayname = Linker::link( $userpage, $displayname );
                }
                return $displayname;
@@ -641,4 +651,33 @@
                }
                return null;
        }
+
+       /**
+        * Used by Echo to locate the author of a comment being replied to.
+        * @param EchoEvent $event the Echo event
+        * @return array array mapping user id to User object
+        */
+       public static function locateParentCommentAuthor( $event ) {
+               $users = [];
+               $id = $event->getExtraParam( 'comment' );
+               $wikipage = WikiPage::newFromId( $id );
+               if ( !is_null( $wikipage ) ) {
+                       $comment = Comment::newFromWikiPage( $wikipage );
+                       if ( !is_null( $comment ) ) {
+                               $parent_id = $comment->getParentId();
+                               if ( !is_null( $parent_id ) ) {
+                                       $parent_wikipage = WikiPage::newFromId( 
$parent_id );
+                                       if ( !is_null( $parent_wikipage ) ) {
+                                               $parent_comment = 
Comment::newFromWikiPage( $parent_wikipage );
+                                               if ( !is_null( $parent_comment 
) ) {
+                                                       $user = 
$parent_comment->getUser();
+                                                       $userid = 
$user->getId();
+                                                       $users[$userid] = $user;
+                                               }
+                                       }
+                               }
+                       }
+               }
+               return $users;
+       }
 }
diff --git a/includes/CommentStreamsHooks.php b/includes/CommentStreamsHooks.php
index cfec455..7bdb07e 100644
--- a/includes/CommentStreamsHooks.php
+++ b/includes/CommentStreamsHooks.php
@@ -334,4 +334,83 @@
                }
                return true;
        }
+
+       /**
+        * @param array &$notifications notifications
+        * @param array &$notificationCategories notification categories
+        * @param array &$icons notification icons
+        */
+       public static function onBeforeCreateEchoEvent( &$notifications,
+               &$notificationCategories, &$icons ) {
+               $notificationCategories['commentstreams-notification-category'] 
= [
+                       'priority' => 3
+               ];
+
+               $notifications['commentstreams-comment-on-watched-page'] = [
+                       'category' => 'commentstreams-notification-category',
+                       'group' => 'positive',
+                       'section' => 'alert',
+                       'presentation-model' => 
EchoCSWatchedPresentationModel::class,
+                       'formatter-class' => EchoCSFormatter::class,
+                       'title-message' => 'title-message',
+                       'email-subject-message' =>
+                               
'commentstreams-email-subject-message-comment-on-watched-page',
+                       'email-body-batch-message' =>
+                               
'commentstreams-email-body-message-comment-on-watched-page',
+                       'email-body-batch-params' => [
+                               'comment_author_username',
+                               'comment_author_display_name',
+                               'comment_title',
+                               'associated_page_display_title',
+                               'titlelink',
+                               'comment_wikitext'
+                       ],
+                       'user-locators' => [ 
'EchoUserLocator::locateUsersWatchingTitle' ]
+               ];
+
+               $notifications['commentstreams-reply-on-watched-page'] = [
+                       'category' => 'commentstreams-notification-category',
+                       'group' => 'positive',
+                       'section' => 'alert',
+                       'presentation-model' => 
EchoCSWatchedPresentationModel::class,
+                       'formatter-class' => EchoCSFormatter::class,
+                       'title-message' => 'title-message',
+                       'email-subject-message' =>
+                               
'commentstreams-email-subject-message-reply-on-watched-page',
+                       'email-body-batch-message' =>
+                               
'commentstreams-email-body-message-reply-on-watched-page',
+                       'email-body-batch-params' => [
+                               'comment_author_username',
+                               'comment_author_display_name',
+                               'comment_title',
+                               'associated_page_display_title',
+                               'titlelink',
+                               'comment_wikitext'
+                       ],
+                       'user-locators' => [ 
'EchoUserLocator::locateUsersWatchingTitle' ],
+                       'user-filters' => [ 
'Comment::locateParentCommentAuthor' ]
+               ];
+
+               $notifications['commentstreams-reply-to-author'] = [
+                       'category' => 'commentstreams-notification-category',
+                       'group' => 'positive',
+                       'section' => 'alert',
+                       'presentation-model' => 
EchoCSReplyPresentationModel::class,
+                       'formatter-class' => EchoCSFormatter::class,
+                       'title-message' => 'title-message',
+                       'email-subject-message' =>
+                               
'commentstreams-email-subject-message-reply-to-author',
+                       'email-body-batch-message' =>
+                               
'commentstreams-email-body-message-reply-to-author',
+                       'email-body-batch-params' => [
+                               'comment_author_username',
+                               'comment_author_display_name',
+                               'comment_title',
+                               'associated_page_display_title',
+                               'titlelink',
+                               'comment_wikitext'
+                       ],
+                       'user-locators' => [ 
'Comment::locateParentCommentAuthor' ]
+               ];
+       }
 }
diff --git a/includes/EchoCSFormatter.php b/includes/EchoCSFormatter.php
new file mode 100644
index 0000000..4ec0aa9
--- /dev/null
+++ b/includes/EchoCSFormatter.php
@@ -0,0 +1,50 @@
+<?php
+/*
+ * Copyright (c) 2016 The MITRE Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+class EchoCSFormatter extends EchoBasicFormatter {
+
+       /**
+        * @param EchoEvent $event the event for which the notification is being
+        * formatted
+        * @param string $param the parameter being formatted
+        * @param Message $message Message the message object to add the 
parameter to
+        * @param User $user the user the notification is being sent to
+        */
+       protected function processParam( $event, $param, $message, $user ) {
+               if ( $param === 'comment_author_username' ) {
+                       $message->params( $event->getExtraParam( 
'comment_author_username' ) );
+               } elseif ( $param === 'comment_author_display_name' ) {
+                       $message->params( $event->getExtraParam(
+                               'comment_author_display_name' ) );
+               } elseif ( $param === 'associated_page_display_title' ) {
+                       $message->params( $event->getExtraParam(
+                               'associated_page_display_title' ) );
+               } elseif ( $param === 'comment_title' ) {
+                       $message->params( $event->getExtraParam( 
'comment_title' ) );
+               } elseif ( $param === 'comment_wikitext' ) {
+                       $message->params( $event->getExtraParam( 
'comment_wikitext' ) );
+               } else {
+                       parent::processParam( $event, $param, $message, $user );
+               }
+       }
+}
diff --git a/includes/EchoCSReplyPresentationModel.php 
b/includes/EchoCSReplyPresentationModel.php
new file mode 100644
index 0000000..66927ba
--- /dev/null
+++ b/includes/EchoCSReplyPresentationModel.php
@@ -0,0 +1,75 @@
+<?php
+/*
+ * Copyright (c) 2016 The MITRE Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+class EchoCSReplyPresentationModel extends EchoEventPresentationModel {
+
+       /**
+        * @return string The symbolic icon name as defined in 
$wgEchoNotificationIcons
+        */
+       public function getIconType() {
+               return 'chat';
+       }
+
+       /**
+        * Array of primary link details, with possibly-relative URL & label.
+        *
+        * @return array|bool Array of link data, or false for no link:
+        *                    ['url' => (string) url, 'label' => (string) link 
text (non-escaped)]
+        */
+       public function getPrimaryLink() {
+               return [
+                       'url' => $this->event->getTitle()->getFullURL(),
+                       'label' => $this->msg( 
'notification-commentstreams-page' )
+               ];
+       }
+
+       /**
+        * Get a message object and add the performer's name as
+        * a parameter. It is expected that subclasses will override
+        * this.
+        *
+        * @return Message
+        */
+       public function getHeaderMessage() {
+               $msg = $this->msg( 
'notification-header-commentstreams-reply-to-author' );
+               $msg->params( $this->event->getExtraParam(
+                       'comment_author_display_name' ) );
+               $msg->params( $this->event->getExtraParam( 'comment_title' ) );
+               $msg->params( $this->event->getExtraParam(
+                       'associated_page_display_title' ) );
+               $msg->params( $this->event->getExtraParam(
+                       'comment_author_username' ) );
+               $msg->params( $this->getViewingUserForGender() );
+               return $msg;
+       }
+
+       /**
+        * If this function returns false, no other methods will be called
+        * on the object.
+        *
+        * @return bool
+        */
+       public function canRender() {
+               return !is_null( $this->event->getTitle() );
+       }
+}
diff --git a/includes/EchoCSWatchedPresentationModel.php 
b/includes/EchoCSWatchedPresentationModel.php
new file mode 100644
index 0000000..5f64a42
--- /dev/null
+++ b/includes/EchoCSWatchedPresentationModel.php
@@ -0,0 +1,82 @@
+<?php
+/*
+ * Copyright (c) 2016 The MITRE Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+class EchoCSWatchedPresentationModel extends EchoEventPresentationModel {
+
+       /**
+        * @return string The symbolic icon name as defined in 
$wgEchoNotificationIcons
+        */
+       public function getIconType() {
+               return 'chat';
+       }
+
+       /**
+        * Array of primary link details, with possibly-relative URL & label.
+        *
+        * @return array|bool Array of link data, or false for no link:
+        *                    ['url' => (string) url, 'label' => (string) link 
text (non-escaped)]
+        */
+       public function getPrimaryLink() {
+               return [
+                       'url' => $this->event->getTitle()->getFullURL(),
+                       'label' => $this->msg( 
'notification-commentstreams-page' )
+               ];
+       }
+
+       /**
+        * Get a message object and add the performer's name as
+        * a parameter. It is expected that subclasses will override
+        * this.
+        *
+        * @return Message
+        */
+       public function getHeaderMessage() {
+               $reply = $this->event->getExtraParam( 'reply' );
+               if ( $reply ) {
+                       $msg = $this->msg(
+                               
'notification-header-commentstreams-reply-on-watched-page' );
+               } else {
+                       $msg = $this->msg(
+                               
'notification-header-commentstreams-comment-on-watched-page' );
+               }
+               $msg->params( $this->event->getExtraParam(
+                       'comment_author_display_name' ) );
+               $msg->params( $this->event->getExtraParam( 'comment_title' ) );
+               $msg->params( $this->event->getExtraParam(
+                       'associated_page_display_title' ) );
+               $msg->params( $this->event->getExtraParam(
+                       'comment_author_username' ) );
+               $msg->params( $this->getViewingUserForGender() );
+               return $msg;
+       }
+
+       /**
+        * If this function returns false, no other methods will be called
+        * on the object.
+        *
+        * @return bool
+        */
+       public function canRender() {
+               return !is_null( $this->event->getTitle() );
+       }
+}

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I83b1cebaed2cdbffcf14992d95b80ccd1f94e637
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/CommentStreams
Gerrit-Branch: master
Gerrit-Owner: Cicalese <[email protected]>
Gerrit-Reviewer: Cicalese <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>

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

Reply via email to