Cicalese has uploaded a new change for review.
https://gerrit.wikimedia.org/r/322129
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/EchoCSPresentationModel.php
A includes/EchoCSReplyPresentationModel.php
A includes/EchoCSWatchedPresentationModel.php
9 files changed, 338 insertions(+), 7 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CommentStreams
refs/changes/29/322129/1
diff --git a/extension.json b/extension.json
index 1c44b14..4ef923f 100644
--- a/extension.json
+++ b/extension.json
@@ -72,7 +72,11 @@
"ApiCSPostComment": "includes/ApiCSPostComment.php",
"ApiCSQueryComment": "includes/ApiCSQueryComment.php",
"ApiCSEditComment": "includes/ApiCSEditComment.php",
- "ApiCSDeleteComment": "includes/ApiCSDeleteComment.php"
+ "ApiCSDeleteComment": "includes/ApiCSDeleteComment.php",
+ "EchoCSPresentationModel":
"includes/EchoCSPresentationModel.php",
+ "EchoCSReplyPresentationModel":
"includes/EchoCSReplyPresentationModel.php",
+ "EchoCSWatchedPresentationModel":
+ "includes/EchoCSWatchedPresentationModel.php"
},
"APIModules": {
"csPostComment": "ApiCSPostComment",
@@ -90,7 +94,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 93403ee..c100563 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -58,5 +58,11 @@
"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
commented <i>$2</i> on <i>$3</i>, which you are watching.",
+ "notification-header-commentstreams-reply-on-watched-page": "$1 replied
to <i>$2</i> on <i>$3</i>, which you are watching.",
+ "notification-header-commentstreams-reply-to-author": "$1 replied to
your comment <i>$2</i> on <i>$3</i>.",
+ "notification-commentstreams-page": "Visit page"
}
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 3fd1858..3576399 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -58,5 +58,13 @@
"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 name of the
page being commented on.",
+ "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 name of the
page being commented on.",
+ "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 name of the
page being commented on."
}
diff --git a/includes/ApiCSPostComment.php b/includes/ApiCSPostComment.php
index 11026be..74685c4 100644
--- a/includes/ApiCSPostComment.php
+++ b/includes/ApiCSPostComment.php
@@ -81,6 +81,36 @@
$this->dieCustomUsageMessage(
'commentstreams-api-error-post' );
}
+ if ( class_exists( 'EchoEvent' ) ) {
+ if ( !is_null( $parentid ) ) {
+ EchoEvent::create( [
+ 'type' =>
'commentstreams-reply-on-watched-page',
+ 'title' => $associated_page->getTitle(),
+ 'extra' => [
+ 'comment' => $comment->getId()
+ ],
+ 'agent' => $this->getUser()
+ ] );
+ EchoEvent::create( [
+ 'type' =>
'commentstreams-reply-to-author',
+ 'title' => $associated_page->getTitle(),
+ 'extra' => [
+ 'comment' => $comment->getId()
+ ],
+ 'agent' => $this->getUser()
+ ] );
+ } else {
+ EchoEvent::create( [
+ 'type' =>
'commentstreams-comment-on-watched-page',
+ 'title' => $associated_page->getTitle(),
+ 'extra' => [
+ 'comment' => $comment->getId()
+ ],
+ 'agent' => $this->getUser()
+ ] );
+ }
+ }
+
$this->getResult()->addValue( null, $this->getModuleName(),
$comment->getJSON() );
}
diff --git a/includes/Comment.php b/includes/Comment.php
index d80ffde..318169d 100644
--- a/includes/Comment.php
+++ b/includes/Comment.php
@@ -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,28 @@
}
return null;
}
+
+ 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..76c7824 100644
--- a/includes/CommentStreamsHooks.php
+++ b/includes/CommentStreamsHooks.php
@@ -334,4 +334,36 @@
}
return true;
}
+
+ 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,
+ 'user-locators' => [
'EchoUserLocator::locateUsersWatchingTitle' ]
+ ];
+
+ $notifications['commentstreams-reply-on-watched-page'] = [
+ 'category' => 'commentstreams-notification-category',
+ 'group' => 'positive',
+ 'section' => 'alert',
+ 'presentation-model' =>
EchoCSWatchedPresentationModel::class,
+ '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,
+ 'user-locators' => [
'Comment::locateParentCommentAuthor' ]
+ ];
+ }
}
diff --git a/includes/EchoCSPresentationModel.php
b/includes/EchoCSPresentationModel.php
new file mode 100644
index 0000000..5e47d24
--- /dev/null
+++ b/includes/EchoCSPresentationModel.php
@@ -0,0 +1,104 @@
+<?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.
+ */
+
+abstract class EchoCSPresentationModel extends EchoEventPresentationModel {
+
+ protected $can_render = true;
+ protected $comment_author = "";
+ protected $associated_page_display_title = "";
+ protected $comment_title = "";
+ protected $parent_id = null;
+
+ /**
+ * @param EchoEvent $event
+ * @param Language|string $language
+ * @param User $user Only used for permissions checking and GENDER
+ */
+ protected function __construct( EchoEvent $event, $language, User $user
) {
+ parent::__construct( $event, $language, $user );
+
+ if ( is_null( $this->event->getTitle() ) ) {
+ $this->can_render = false;
+ return;
+ }
+
+ $id = $this->event->getExtraParam( 'comment' );
+ $wikipage = WikiPage::newFromId( $id );
+ if ( is_null( $wikipage ) ) {
+ $this->can_render = false;
+ return;
+ }
+
+ $comment = Comment::newFromWikiPage( $wikipage );
+ if ( is_null( $comment ) ) {
+ $this->can_render = false;
+ return;
+ }
+
+ $associated_id = $comment->getAssociatedId();
+ if ( is_null( $associated_id ) ) {
+ $this->can_render = false;
+ return;
+ }
+
+ $associated_wikipage = WikiPage::newFromId( $associated_id );
+ if ( is_null( $associated_wikipage ) ) {
+ $this->can_render = false;
+ return;
+ }
+
+ $this->comment_author = $comment->getUserDisplayNameUnlinked();
+
+ $this->associated_page_display_title =
+ $associated_wikipage->getTitle()->getPrefixedText();
+ if ( class_exists( 'PageProps' ) ) {
+ $associated_title = $associated_wikipage->getTitle();
+ $values = PageProps::getInstance()->getProperties(
$associated_title,
+ 'displaytitle' );
+ if ( array_key_exists(
$associated_title->getArticleID(), $values ) ) {
+ $this->associated_page_display_title =
+
$values[$associated_title->getArticleID()];
+ }
+ }
+
+ $parent_id = $comment->getParentId();
+ if ( is_null( $parent_id ) ) {
+ $this->comment_title = $comment->getCommentTitle();
+ } else {
+ $this->parent_id = $parent_id;
+ $parent_wikipage = WikiPage::newFromId( $parent_id );
+ if ( is_null( $parent_wikipage ) ) {
+ $this->can_render = false;
+ return;
+ }
+ $parent_comment = Comment::newFromWikiPage(
$parent_wikipage );
+ if ( !is_null( $parent_comment ) ) {
+ $this->comment_title =
$parent_comment->getCommentTitle();
+ }
+ }
+ }
+
+ public function canRender() {
+ return $this->can_render;
+ }
+}
diff --git a/includes/EchoCSReplyPresentationModel.php
b/includes/EchoCSReplyPresentationModel.php
new file mode 100644
index 0000000..151497c
--- /dev/null
+++ b/includes/EchoCSReplyPresentationModel.php
@@ -0,0 +1,53 @@
+<?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 EchoCSPresentationModel {
+
+ /**
+ * @param EchoEvent $event
+ * @param Language|string $language
+ * @param User $user Only used for permissions checking and GENDER
+ */
+ protected function __construct( EchoEvent $event, $language, User $user
) {
+ parent::__construct( $event, $language, $user );
+ }
+
+ public function getIconType() {
+ return 'chat';
+ }
+
+ public function getPrimaryLink() {
+ return [
+ 'url' => $this->event->getTitle()->getFullURL(),
+ 'label' => $this->msg(
'notification-commentstreams-page' )
+ ];
+ }
+
+ public function getHeaderMessage() {
+ $msg = $this->msg(
'notification-header-commentstreams-reply-to-author' );
+ $msg->params( $this->comment_author );
+ $msg->params( $this->comment_title );
+ $msg->params( $this->associated_page_display_title );
+ return $msg;
+ }
+}
diff --git a/includes/EchoCSWatchedPresentationModel.php
b/includes/EchoCSWatchedPresentationModel.php
new file mode 100644
index 0000000..71b0a76
--- /dev/null
+++ b/includes/EchoCSWatchedPresentationModel.php
@@ -0,0 +1,59 @@
+<?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 EchoCSPresentationModel {
+
+ /**
+ * @param EchoEvent $event
+ * @param Language|string $language
+ * @param User $user Only used for permissions checking and GENDER
+ */
+ protected function __construct( EchoEvent $event, $language, User $user
) {
+ parent::__construct( $event, $language, $user );
+ }
+
+ public function getIconType() {
+ return 'chat';
+ }
+
+ public function getPrimaryLink() {
+ return [
+ 'url' => $this->event->getTitle()->getFullURL(),
+ 'label' => $this->msg(
'notification-commentstreams-page' )
+ ];
+ }
+
+ public function getHeaderMessage() {
+ if ( is_null( $this->parent_id ) ) {
+ $msg = $this->msg(
+
'notification-header-commentstreams-comment-on-watched-page' );
+ } else {
+ $msg = $this->msg(
+
'notification-header-commentstreams-reply-on-watched-page' );
+ }
+ $msg->params( $this->comment_author );
+ $msg->params( $this->comment_title );
+ $msg->params( $this->associated_page_display_title );
+ return $msg;
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/322129
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I83b1cebaed2cdbffcf14992d95b80ccd1f94e637
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CommentStreams
Gerrit-Branch: master
Gerrit-Owner: Cicalese <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits