Matthias Mullie has uploaded a new change for review.

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

Change subject: Notify when a topic is marked as resolved or reopened
......................................................................

Notify when a topic is marked as resolved or reopened

Bug: T125654
Change-Id: Ibf07083108777c02bd16f691140314da8c734df6
---
M autoload.php
M i18n/en.json
M i18n/qqq.json
M includes/Data/Listener/NotificationListener.php
M includes/Notifications/Controller.php
M includes/Notifications/Notifications.php
A includes/Notifications/TopicResolvedPresentationModel.php
A modules/notification/icon/flow-topic-reopened.svg
A modules/notification/icon/flow-topic-resolved.svg
9 files changed, 185 insertions(+), 2 deletions(-)


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

diff --git a/autoload.php b/autoload.php
index 29188d1..5458568 100644
--- a/autoload.php
+++ b/autoload.php
@@ -390,6 +390,7 @@
        'Flow\\Tests\\UrlGeneratorTest' => __DIR__ . 
'/tests/phpunit/UrlGeneratorTest.php',
        'Flow\\Tests\\WatchedTopicItemTest' => __DIR__ . 
'/tests/phpunit/WatchedTopicItemsTest.php',
        'Flow\\TopicRenamedPresentationModel' => __DIR__ . 
'/includes/Notifications/TopicRenamedPresentationModel.php',
+       'Flow\\TopicResolvedPresentationModel' => __DIR__ . 
'/includes/Notifications/TopicResolvedPresentationModel.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 bc22a12..87feb23 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -315,6 +315,12 @@
        "notification-email-subject-flow-description-edited": "$1 
{{GENDER:$1|edited}} the description on $2.",
        "notification-email-batch-body-flow-description-edited": "$1 
{{GENDER:$1|edited}} the description on $2.",
        "notification-email-batch-bundle-body-flow-description-edited": "$1 and 
$3 {{PLURAL:$4|other|others}} {{GENDER:$1|edited}} the description on $2",
+       "notification-header-flow-topic-resolved": "The topic \"'''$1'''\" was 
resolved.",
+       "notification-header-flow-topic-reopened": "The topic \"'''$1'''\" was 
reopened.",
+       "notification-header-flow-topic-resolved-user-talk": "The topic 
\"'''$1'''\" was resolved on '''your talk page'''.",
+       "notification-header-flow-topic-reopened-user-talk": "The topic 
\"'''$1'''\" was reopened on '''your talk page'''.",
+       "notification-email-subject-flow-topic-resolved": "The topic 
\"'''$2'''\" was resolved.",
+       "notification-email-batch-body-flow-topic-resolved": "The topic 
\"'''$2'''\" was resolved.",
        "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 31a41d6..6c36925 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -325,6 +325,12 @@
        "notification-email-subject-flow-description-edited": "Subject line of 
notification email for the description being edited. Parameters:\n* $1 - name 
of the user that edited the description\n* $2 - title of the page",
        "notification-email-batch-body-flow-description-edited": "Email 
notification for the description being edited. Parameters:\n* $1 - name of the 
user that edited the description\n* $2 - title of the page",
        "notification-email-batch-bundle-body-flow-description-edited": "Email 
notification body when a board description is edited multiple times, this 
message is used in both single email and email digest.\n\nParameters:\n* $1 - 
username of the person who edited the description\n* $2 - title for the page\n* 
$3 - the count of other action performers, could be number or 
{{msg-mw|Echo-notification-count}}. e.g. 7 others or 99+ others\n* $4 - a 
number used for plural support",
+       "notification-header-flow-topic-resolved": "Notification header text 
for when a topic summary is resolved. Parameters:\n* $1 - title of the 
topic.\n* $2 - name of the user viewing the notification, can be used for 
GENDER.\n{{Related|Notification-header-flow}}.",
+       "notification-header-flow-topic-reopened": "Notification header text 
for when a topic summary is reopened. Parameters:\n* $1 - title of the 
topic.\n* $2 - name of the user viewing the notification, can be used for 
GENDER.\n{{Related|Notification-header-flow}}.",
+       "notification-header-flow-topic-resolved-user-talk": "Notification 
header text for when a topic summary is resolved on a user's talk page. 
Parameters:\n* $1 - title of the topic.\n* $2 - name of the user viewing the 
notification, can be used for GENDER.\n{{Related|Notification-header-flow}}.",
+       "notification-header-flow-topic-reopened-user-talk": "Notification 
header text for when a topic summary is reopened on a user's talk page. 
Parameters:\n* $1 - title of the topic.\n* $2 - name of the user viewing the 
notification, can be used for GENDER.\n{{Related|Notification-header-flow}}.",
+       "notification-email-subject-flow-topic-resolved": "Subject line of 
notification email for the topic being resolved. Parameters:\n* $1 - name of 
the user that edited the summary\n* $2 - title of the topic",
+       "notification-email-batch-body-flow-topic-resolved": "Subject line of 
notification email for the topic being reopened. Parameters:\n* $1 - name of 
the user that edited the summary\n* $2 - title of the topic",
        "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/Data/Listener/NotificationListener.php 
b/includes/Data/Listener/NotificationListener.php
index 427124c..f747223 100644
--- a/includes/Data/Listener/NotificationListener.php
+++ b/includes/Data/Listener/NotificationListener.php
@@ -33,8 +33,7 @@
                }
 
                switch( $row['rev_change_type'] ) {
-               // Actually new-topic @todo rename
-               case 'new-post':
+               case 'new-topic':
                        if ( !isset(
                                $metadata['board-workflow'],
                                $metadata['workflow'],
@@ -64,6 +63,30 @@
                        $this->notifyPostChange( 'flow-post-edited', $object, 
$metadata );
                        break;
 
+               case 'lock-topic':
+                       $this->notificationController->notifyTopicLocked( 
'flow-topic-resolved', array(
+                               'revision' => $object,
+                               'topic-workflow' => $metadata['workflow'],
+                               'topic-title' => $metadata['topic-title'],
+                       ) );
+                       break;
+
+               // "restore" can be a lot of different things
+               // - undo moderation (suppress/delete/hide) things
+               // - undo lock status
+               // we'll need to inspect the previous revision to figure out 
what is was
+               case 'restore-topic':
+                       $post = $object->getCollection();
+                       $previousRevision = $post->getPrevRevision( $object );
+                       if ( $previousRevision->isLocked() ) {
+                               
$this->notificationController->notifyTopicLocked( 'flow-topic-reopened', array(
+                                       'revision' => $object,
+                                       'topic-workflow' => 
$metadata['workflow'],
+                                       'topic-title' => 
$metadata['topic-title'],
+                               ) );
+                       }
+                       break;
+
                case 'edit-header':
                        $this->notificationController->notifyHeaderChange( 
'flow-description-edited', array(
                                'revision' => $object,
diff --git a/includes/Notifications/Controller.php 
b/includes/Notifications/Controller.php
index 0c8cbd0..9cbc60e 100644
--- a/includes/Notifications/Controller.php
+++ b/includes/Notifications/Controller.php
@@ -47,6 +47,12 @@
                $icons['flowusertalk-new-topic'] = array(
                        'path' => 
'Flow/modules/notification/icon/flowusertalk-new-topic.svg',
                );
+               $icons['flow-topic-resolved'] = array(
+                       'path' => 
'Flow/modules/notification/icon/flow-topic-resolved.svg',
+               );
+               $icons['flow-topic-reopened'] = array(
+                       'path' => 
'Flow/modules/notification/icon/flow-topic-reopened.svg',
+               );
        }
 
        /**
@@ -353,6 +359,52 @@
                return $events;
        }
 
+       /**
+        * Triggers notifications when a topic is resolved or reopened.
+        *
+        * @param string $type
+        * @param array $data
+        * @return array
+        * @throws Exception\InvalidDataException
+        * @throws FlowException
+        * @throws \MWException
+        */
+       public function notifyTopicLocked( $type, $data = array() ) {
+               if ( !class_exists( 'EchoEvent' ) ) {
+                       return array();
+               }
+
+               $revision = $data['revision'];
+               if ( !$revision instanceof PostRevision ) {
+                       throw new FlowException( 'Expected PostSummary but 
received ' . get_class( $revision ) );
+               }
+               $topicWorkflow = $data['topic-workflow'];
+               if ( !$topicWorkflow instanceof Workflow ) {
+                       throw new FlowException( 'Expected Workflow but 
received ' . get_class( $topicWorkflow ) );
+               }
+
+               $extraData['topic-workflow'] = $topicWorkflow->getId();
+               $extraData['topic-title'] = Utils::htmlToPlaintext( 
$revision->getContent( 'topic-title-html' ), 200, $this->language );
+               $extraData['target-page'] = 
$topicWorkflow->getArticleTitle()->getArticleID();
+               // I'll treat resolve & reopen as the same notification type, 
but pass the
+               // different type so presentation models can differentiate
+               $extraData['type'] = $type;
+
+               $info = array(
+                       'type' => 'flow-topic-resolved',
+                       'agent' => $revision->getUser(),
+                       'title' => $topicWorkflow->getOwnerTitle(),
+                       'extra' => $extraData,
+               );
+
+               // Allow a specific timestamp to be set - useful when importing 
existing data
+               if ( isset( $data['timestamp'] ) ){
+                       $info['timestamp'] = $data['timestamp'];
+               }
+
+               return array( EchoEvent::create( $info ) );
+       }
+
        public function notifyFlowEnabledOnTalkpage( User $user ) {
                if ( !class_exists( 'EchoEvent' ) ) {
                        // Nothing to do here.
diff --git a/includes/Notifications/Notifications.php 
b/includes/Notifications/Notifications.php
index d04f91c..d0530e0 100644
--- a/includes/Notifications/Notifications.php
+++ b/includes/Notifications/Notifications.php
@@ -208,6 +208,24 @@
                'email-body-batch-params' => array( 'agent', 'title' ),
                'icon' => 'chat',
        ) + $notificationTemplate,
+       'flow-topic-resolved' => array(
+               'presentation-model' => 'Flow\\TopicResolvedPresentationModel',
+               'user-locators' => array(
+                       'EchoUserLocator::locateUsersWatchingTitle',
+                       'EchoUserLocator::locateTalkPageOwner'
+               ),
+               'primary-link' => array(
+                       'message' => 'flow-notification-link-text-view-topic',
+                       'destination' => 'flow-post'
+               ),
+               'title-message' => 'notification-header-flow-topic-resolved',
+               'title-params' => array( 'subject', 'agent' ),
+               'email-subject-message' => 
'notification-email-subject-flow-topic-resolved',
+               'email-subject-params' => array( 'agent', 'subject' ),
+               'email-body-batch-message' => 
'notification-email-batch-body-flow-topic-resolved',
+               'email-body-batch-params' => array( 'agent', 'subject' ),
+               'icon' => 'flow-topic-resolved',
+       ) + $notificationTemplate,
 );
 
 return $notifications;
diff --git a/includes/Notifications/TopicResolvedPresentationModel.php 
b/includes/Notifications/TopicResolvedPresentationModel.php
new file mode 100644
index 0000000..88292bb
--- /dev/null
+++ b/includes/Notifications/TopicResolvedPresentationModel.php
@@ -0,0 +1,53 @@
+<?php
+
+namespace Flow;
+
+class TopicResolvedPresentationModel extends FlowPresentationModel {
+    public function getIconType() {
+        // flow-topic-resolved or flow-topic-reopened
+        return $this->event->getExtraParam( 'type' );
+    }
+
+    public function canRender() {
+        $type = $this->event->getExtraParam( 'type' );
+
+        return $this->hasTitle()
+            && $this->hasValidTopicWorkflowId()
+            && in_array( $type, array( 'flow-topic-resolved', 
'flow-topic-reopened' ) );
+    }
+
+    public function getPrimaryLink() {
+        return $this->getViewTopicLink();
+    }
+
+    public function getSecondaryLinks() {
+        return array(
+            $this->getAgentLink(),
+            $this->getBoardLink(),
+        );
+    }
+
+    protected function getHeaderMessageKey() {
+        // notification-header-flow-topic-resolved,
+        // notification-header-flow-topic-reopened,
+        // notification-header-flow-topic-reopened-user-talk or
+        // notification-header-flow-topic-reopened-user-talk
+        $key = "notification-header-" . $this->event->getExtraParam( 'type' );
+        if ( $this->isUserTalkPage() ) {
+            $key .= '-user-talk';
+        }
+
+        return $key;
+    }
+
+    public function getHeaderMessage() {
+        $msg = $this->msg( $this->getHeaderMessageKey() );
+        $msg->params( $this->getTruncatedTitleText( $this->event->getTitle(), 
true ) );
+        $msg->params( $this->getViewingUserForGender() );
+        return $msg;
+    }
+
+    public function getBodyMessage() {
+        return false;
+    }
+}
diff --git a/modules/notification/icon/flow-topic-reopened.svg 
b/modules/notification/icon/flow-topic-reopened.svg
new file mode 100644
index 0000000..eeac333
--- /dev/null
+++ b/modules/notification/icon/flow-topic-reopened.svg
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg width="30px" height="30px" viewBox="0 0 30 30" version="1.1" 
xmlns="http://www.w3.org/2000/svg"; xmlns:xlink="http://www.w3.org/1999/xlink"; 
xmlns:sketch="http://www.bohemiancoding.com/sketch/ns";>
+    <!-- Generator: Sketch 3.5.1 (25234) - 
http://www.bohemiancoding.com/sketch -->
+    <title>flow-new-reopened</title>
+    <desc>Created with Sketch.</desc>
+    <defs></defs>
+    <g id="Page-1" stroke="none" stroke-width="1" fill="none" 
fill-rule="evenodd" sketch:type="MSPage">
+        <g id="flow-new-reopened" sketch:type="MSArtboardGroup" fill="#165CA0">
+            <path d="M25.5,26 L0,26 L4.5,21.5 L4.5,5 L30,5 L30,21.5 C30,24.05 
28.05,26 25.5,26 Z M13.5,15 C13.5,15.6 13.3,16 12.9,16.4 C12.5,16.8 12,17 
11.5,17 C10.9,17 10.5,16.8 10.1,16.4 C9.7,16 9.5,15.5 9.5,15 C9.5,14.5 9.7,14 
10.1,13.6 C10.5,13.2 11,13 11.5,13 C12,13 12.5,13.2 12.9,13.6 C13.3,14 
13.5,14.5 13.5,15 Z M19.5,15 C19.5,15.6 19.3,16 18.9,16.4 C18.5,16.8 18,17 
17.5,17 C16.9,17 16.5,16.8 16.1,16.4 C15.7,16 15.5,15.5 15.5,15 C15.5,14.5 
15.7,14 16.1,13.6 C16.5,13.2 17,13 17.5,13 C18,13 18.5,13.2 18.9,13.6 C19.3,14 
19.5,14.5 19.5,15 Z M25.5,15 C25.5,15.6 25.3,16 24.9,16.4 C24.5,16.8 24,17 
23.5,17 C22.9,17 22.5,16.8 22.1,16.4 C21.7,16 21.5,15.5 21.5,15 C21.5,14.5 
21.7,14 22.1,13.6 C22.5,13.2 23,13 23.5,13 C24,13 24.5,13.2 24.9,13.6 C25.3,14 
25.5,14.5 25.5,15 Z" id="new-topic" sketch:type="MSShapeGroup"></path>
+        </g>
+    </g>
+</svg>
\ No newline at end of file
diff --git a/modules/notification/icon/flow-topic-resolved.svg 
b/modules/notification/icon/flow-topic-resolved.svg
new file mode 100644
index 0000000..131cc9e
--- /dev/null
+++ b/modules/notification/icon/flow-topic-resolved.svg
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg width="30px" height="30px" viewBox="0 0 30 30" version="1.1" 
xmlns="http://www.w3.org/2000/svg"; xmlns:xlink="http://www.w3.org/1999/xlink"; 
xmlns:sketch="http://www.bohemiancoding.com/sketch/ns";>
+    <!-- Generator: Sketch 3.5.1 (25234) - 
http://www.bohemiancoding.com/sketch -->
+    <title>flow-new-resolved</title>
+    <desc>Created with Sketch.</desc>
+    <defs></defs>
+    <g id="Page-1" stroke="none" stroke-width="1" fill="none" 
fill-rule="evenodd" sketch:type="MSPage">
+        <g id="flow-new-resolved" sketch:type="MSArtboardGroup" fill="#165CA0">
+            <path d="M25.5,26 L0,26 L4.5,21.5 L4.5,5 L30,5 L30,21.5 C30,24.05 
28.05,26 25.5,26 Z M24.3846154,10.5230769 L15.6666667,19.2410256 
L11.3076923,14.8820513 L10,16.1897436 L15.6666667,21.8564103 L27,10.5230769 
C26.3025641,9.82564103 25.0820513,9.82564103 24.3846154,10.5230769 Z" 
id="resolved" sketch:type="MSShapeGroup"></path>
+        </g>
+    </g>
+</svg>
\ No newline at end of file

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

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

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

Reply via email to