Glaisher has uploaded a new change for review.

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

Change subject: Cleanup notification sent for new issues
......................................................................

Cleanup notification sent for new issues

NOTE: This is a BREAKING CHANGE. All previous notifications will
have to be purged from the table as they are not supported. This is
not backwards-compatible as this is still in beta status and I don't
want to keep code just for supporting those old notifications (probably
only in development instances).

* Escape raw HTML
* Add secondary link
* Add payload ("summary")
* Set category so that prefs are actually used
* Add agent info
* Expand i18n messages documentation
* Set default user options (web and email) for this newsletter
* Remove redundant code; just use code provided by Echo

Bug: T116382
Change-Id: Iaca3a3d88b08adf74333aeaf6b328fc35fe65b97
---
M Newsletter.hooks.php
M extension.json
M i18n/en.json
M i18n/qqq.json
M includes/Echo/EchoNewsletterFormatter.php
M includes/Echo/EchoNewsletterUserLocator.php
M includes/specials/SpecialNewsletter.php
7 files changed, 44 insertions(+), 27 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Newsletter 
refs/changes/76/255076/1

diff --git a/Newsletter.hooks.php b/Newsletter.hooks.php
index 84719e4..551f7d1 100755
--- a/Newsletter.hooks.php
+++ b/Newsletter.hooks.php
@@ -19,20 +19,26 @@
                );
 
                $notifications['newsletter-announce'] = array(
+                       'category' => 'newsletter',
+                       'section' => 'alert',
                        'primary-link' => array(
                                'message' => 
'newsletter-notification-link-text-new-issue',
                                'destination' => 'new-issue'
+                       ),
+                       'secondary-link' => array(
+                               'message' => 
'newsletter-notification-link-text-view-newsletter',
+                               'destination' => 'newsletter'
                        ),
                        'user-locators' => array(
                                
'EchoNewsletterUserLocator::locateNewsletterSubscribedUsers',
                        ),
                        'formatter-class' => 'EchoNewsletterFormatter',
                        'title-message' => 'newsletter-notification-title',
-                       'title-params' => array( 'newsletter', 'title' ),
+                       'title-params' => array( 'newsletter', 'title', 'agent' 
),
                        'flyout-message' => 'newsletter-notification-flyout',
-                       'flyout-params' => array( 'newsletter', 'title' ),
-
+                       'payload' => array( 'summary' ),
                );
+
                return true;
        }
 
@@ -61,6 +67,7 @@
        }
 
        public static function onUnitTestsList( &$files ) {
+               // @fixme This does NOT work. 
https://gerrit.wikimedia.org/r/248377
                $files = array_merge( $files, glob( __DIR__ . 
'/tests/*Test.php' ) );
 
                return true;
diff --git a/extension.json b/extension.json
index 6a83a20..c7a6e6e 100644
--- a/extension.json
+++ b/extension.json
@@ -57,6 +57,10 @@
                "EchoNewsletterFormatter": 
"includes/Echo/EchoNewsletterFormatter.php",
                "EchoNewsletterUserLocator": 
"includes/Echo/EchoNewsletterUserLocator.php"
        },
+       "DefaultUserOptions": {
+               "echo-subscriptions-web-newsletter": true,
+               "echo-subscriptions-email-newsletter": true
+       },
        "ResourceModules": {
                "ext.newsletter": {
                        "scripts": "ext.newsletter.js",
diff --git a/i18n/en.json b/i18n/en.json
index e18ec3b..474edeb 100755
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -81,9 +81,10 @@
        "newsletter-list-search-none-found": "No newsletters match your query.",
        "echo-category-title-newsletter": "Newsletters",
        "echo-pref-tooltip-newsletter": "Notify me when any of the newsletters 
to which I have subscribed to announces a new issue.",
-       "newsletter-notification-title": "$1 has announced an issue",
-       "newsletter-notification-flyout": "$1 has announced a new issue",
+       "newsletter-notification-title": "[[User:$3|$3]] has announced a 
[[$2|new issue]] of $1.",
+       "newsletter-notification-flyout": "$3 has announced a new issue of $1.",
        "newsletter-notification-link-text-new-issue": "View new issue",
+       "newsletter-notification-link-text-view-newsletter": "View newsletter",
        "newsletter-header-name": "Name of newsletter",
        "newsletter-header-description": "Description",
        "newsletter-header-action": "Subscribed?",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 7074128..693aee1 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -84,9 +84,10 @@
        "newsletter-list-search-none-found": "Error message shown on 
[[Special:Newsletters]] if no newsletters found after user searches the table 
using filters",
        "echo-category-title-newsletter": "Title of the notification category 
used by Newsletter 
extension.\n{{Related|Echo-category-title}}\n{{Identical|Newsletter}}",
        "echo-pref-tooltip-newsletter": "Short description of the newsletter 
notification category.\n{{Related|Echo-pref-tooltip}}",
-       "newsletter-notification-title": "Used as a Echo notification message",
-       "newsletter-notification-flyout": "Used as a Echo notification flyout 
message",
+       "newsletter-notification-title": "Header text for a notification when a 
new issue of a newsletter is announced. Parameters:\n* $1 is the name of the 
newsletter.\n* $2 is title of the issue page.\n* $3 is the username of the user 
who announced the new issue.",
+       "newsletter-notification-flyout": "Used as a Echo notification flyout 
message when a new issue of a newsletter is announced. \n* $1 is the name of 
the newsletter.\n* $2 is title of the issue page.\n* $3 is the username of the 
user who announced the new issue.",
        "newsletter-notification-link-text-new-issue": "Label of the primary 
link of the notification-newsletter-flyout, which on clicking navigates the 
user to the newly announced issue of a newsletter.",
+       "newsletter-notification-link-text-view-newsletter": "Label for button 
that links to the newsletter page.",
        "newsletter-header-name": "Label of the newsletter name column of table 
in [[Special:Newsletters]] which lists the names of newsletters",
        "newsletter-header-description": "Label of the description column of 
table in [[Special:Newsletters]] which displays a description about the 
newsletter\n{{Identical|Description}}",
        "newsletter-header-action": "Label of the subscribe column of table in 
[[Special:Newsletters]] which provides radio buttons to subscribe/unsubscribe 
newsletters\n{{Identical|Subscribed}}",
diff --git a/includes/Echo/EchoNewsletterFormatter.php 
b/includes/Echo/EchoNewsletterFormatter.php
index 5c20dde..20b8389 100644
--- a/includes/Echo/EchoNewsletterFormatter.php
+++ b/includes/Echo/EchoNewsletterFormatter.php
@@ -14,9 +14,7 @@
         */
        protected function processParam( $event, $param, $message, $user ) {
                if ( $param === 'newsletter' ) {
-                       $message->params( $event->getExtraParam( 'newsletter' ) 
);
-               } elseif ( $param === 'title' ) {
-                       $message->params( $event->getExtraParam( 
'issuePageTitle' ) );
+                       $this->processParamEscaped( $message, 
$event->getExtraParam( 'newsletter-name' ) );
                } else {
                        parent::processParam( $event, $param, $message, $user );
                }
@@ -32,17 +30,21 @@
         * @return array including target URL
         */
        protected function getLinkParams( $event, $user, $destination ) {
-               if ( $destination === 'new-issue' ) {
-                       return array(
-                               Title::makeTitle(
-                                       $event->getExtraParam( 
'issuePageNamespace' ),
-                                       $event->getExtraParam( 'issuePageTitle' 
)
-                               ),
-                               array(),
-                       );
-               } else {
-                       return parent::getLinkParams( $event, $user, 
$destination );
+               $target = null;
+               $query = array();
+               switch ( $destination ) {
+                       case 'new-issue':
+                               // Placeholder for T119090 - currently the same 
as 'title'
+                               $target = $event->getTitle();
+                               break;
+                       case 'newsletter':
+                               $target = SpecialPage::getTitleFor( 
'Newsletter', $event->getExtraParam( 'newsletter-id' ) );
+                               break;
+                       default:
+                               return parent::getLinkParams( $event, $user, 
$destination );
                }
+
+               return array( $target, $query );
        }
 
 }
diff --git a/includes/Echo/EchoNewsletterUserLocator.php 
b/includes/Echo/EchoNewsletterUserLocator.php
index 285bd24..2753a41 100644
--- a/includes/Echo/EchoNewsletterUserLocator.php
+++ b/includes/Echo/EchoNewsletterUserLocator.php
@@ -10,7 +10,7 @@
        public static function locateNewsletterSubscribedUsers( EchoEvent 
$event ) {
                $extra = $event->getExtra();
                $ids = NewsletterDb::newFromGlobalState()
-                       ->getSubscribersFromID( $extra['newsletterId'] );
+                       ->getSubscribersFromID( $extra['newsletter-id'] );
 
                return UserArray::newFromIDs( $ids );
 
diff --git a/includes/specials/SpecialNewsletter.php 
b/includes/specials/SpecialNewsletter.php
index 360b724..f9a3b47 100644
--- a/includes/specials/SpecialNewsletter.php
+++ b/includes/specials/SpecialNewsletter.php
@@ -46,7 +46,6 @@
                $out = $this->getOutput();
                $this->newsletter = Newsletter::newFromID( (int)$id );
 
-
                if ( $this->newsletter ) {
                        // Newsletter exists for the given subpage id - let's 
check what they want to do
                        switch ( $action ) {
@@ -69,6 +68,7 @@
                        // Just show an error message if we couldn't find a 
newsletter
                        $out->showErrorPage( 'newsletter-notfound', 
'newsletter-not-found-id' );
                }
+
                $out->setSubtitle( NewsletterLinksGenerator::getSubtitleLinks( 
$this->getContext() ) );
        }
 
@@ -366,7 +366,7 @@
                                'type' => 'text',
                                'name' => 'summary',
                                'label-message' => 
'newsletter-announce-summary',
-                               'maxlength' => '255',
+                               'maxlength' => '160',
                                'autofocus' => true,
                        ),
                );
@@ -443,12 +443,14 @@
                EchoEvent::create(
                        array(
                                'type' => 'newsletter-announce',
+                               'title' => $title,
                                'extra' => array(
-                                       'newsletter' => 
$this->newsletter->getName(),
-                                       'newsletterId' => 
$this->newsletter->getId(),
-                                       'issuePageTitle' => 
$title->getPrefixedText(),
-                                       'issuePageNamespace' => 
$title->getNamespace(), // @todo we can just get this from issuePageTitle
+                                       'newsletter-name' => 
$this->newsletter->getName(),
+                                       'newsletter-id' => 
$this->newsletter->getId(),
+                                       'section-text' => trim( 
$data['summary'] ),
+                                       'notifyAgent' => true,
                                ),
+                               'agent' => $this->getUser()
                        )
                );
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaca3a3d88b08adf74333aeaf6b328fc35fe65b97
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Newsletter
Gerrit-Branch: master
Gerrit-Owner: Glaisher <glaisher.w...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to