Matthias Mullie has uploaded a new change for review. https://gerrit.wikimedia.org/r/269105
Change subject: Pick up on mentions in topic summaries ...................................................................... Pick up on mentions in topic summaries Bug: T125120 Change-Id: I035686e3d87e8a47ab8a6c95423a1bba63339d0b --- M container.php M i18n/en.json M i18n/qqq.json M includes/Block/TopicSummary.php M includes/Data/Listener/NotificationListener.php M includes/Notifications/Controller.php M includes/Notifications/MentionPresentationModel.php 7 files changed, 67 insertions(+), 27 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow refs/changes/05/269105/1 diff --git a/container.php b/container.php index 36a3ecd..fa5303c 100644 --- a/container.php +++ b/container.php @@ -451,6 +451,7 @@ return array( 'listener.recentchanges' => $c['listener.recentchanges'], 'storage.post_summary.listeners.username' => $c['storage.post_summary.listeners.username'], + 'listeners.notification' => $c['listeners.notification'], 'storage.post_summary_board_history.indexes.primary' => $c['storage.post_summary_board_history.indexes.primary'], 'listener.editcount' => $c['listener.editcount'], 'reference.recorder' => $c['reference.recorder'], diff --git a/i18n/en.json b/i18n/en.json index de37d0b..2060d05 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -292,6 +292,7 @@ "notification-header-flow-topic-renamed-user-talk": "The topic \"$1\" was renamed to \"$2\" on your talk page.", "notification-header-flow-mention-post": "$1 {{GENDER:$2|mentioned}} {{GENDER:$4|you}} in \"$5\".", "notification-header-flow-mention-header": "$1 {{GENDER:$2|mentioned}} {{GENDER:$4|you}} in the description of '''$3'''.", + "notification-header-flow-mention-post-summary": "$1 {{GENDER:$2|mentioned}} {{GENDER:$4|you}} in \"$5\".", "notification-body-flow-mention": "$1", "notification-header-flow-enabled-on-talkpage": "New discussion system enabled for {{GENDER:$2|your}} user talk page.", "notification-header-flow-description-edited": "The description of '''$1''' was edited.", diff --git a/i18n/qqq.json b/i18n/qqq.json index 5ba39e8..fa040a4 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -301,7 +301,8 @@ "notification-header-flow-topic-renamed-v2": "Notification header text for when a topic is renamed. Parameters:\n$1 - old title of the topic\n* $2 - new title of the topic\n* $3 - username of the person who receives the notification, can be used for GENDER\n{{Related|Flow-notification}}", "notification-header-flow-topic-renamed-user-talk": "Notification header text for when a topic is renamed on a user's talk page. Parameters:\n$1 - old title of the topic\n* $2 - new title of the topic\n* $3 - username of the person who receives the notification, can be used for GENDER\n{{Related|Flow-notification}}", "notification-header-flow-mention-post": "{{doc-singularthey}}\nNotification header text for when a user is mentioned in a post or topic title. Parameters:\n* $1 - the formatted username of the person who made the post\n* $2 - the username of the user who mentioned the viewing user, can be used for GENDER\n* $3 - title of the Flow board\n* $4 - username of the person who receives the notification, can be used for GENDER\n* $5 - title of the topic\n{{Related|Flow-notification}}", - "notification-header-flow-mention-header": "{{doc-singularthey}}\nNotification header text for when a user is mentioned in the board description. Parameters:\n* $1 - the formatted username of the person who made the post\n* $2 - the username for gender purposes\n* $3 - title of the Flow board\n* $4 - username of the person who receives the notification, can be used for GENDER\n{{Related|Flow-notification}}", + "notification-header-flow-mention-header": "{{doc-singularthey}}\nNotification header text for when a user is mentioned in the board description. Parameters:\n* $1 - the formatted username of the person who made the post\n* $2 - the username of the user who mentioned the viewing user, can be used for GENDER\n* $3 - title of the Flow board\n* $4 - username of the person who receives the notification, can be used for GENDER\n{{Related|Flow-notification}}", + "notification-header-flow-mention-post-summary": "{{doc-singularthey}}\nNotification header text for when a user is mentioned in a post summary. Parameters:\n* $1 - the formatted username of the person who made the post\n* $2 - the username of the user who mentioned the viewing user, can be used for GENDER\n* $3 - title of the Flow board\n* $4 - username of the person who receives the notification, can be used for GENDER\n* $5 - title of the topic\n{{Related|Flow-notification}}", "notification-body-flow-mention": "Notification body text for when a user is mentioned in a post. Parameters:\n* $1 - text snippet of the message containing the mention\n{{Related|Flow-notification}}", "notification-header-flow-enabled-on-talkpage": "Notification header text when Flow is enabled on a user talk page. Parameters:\n* $1 - the formatted username of the user who enabled Flow on his user talk page\n* $2 - the username for gender purposes\n* $3 - Title where Flow was enabled.", "notification-header-flow-description-edited": "Notification header text for when a board description is edited. Parameters:\n* $1 - title of the board.\n* $2 - name of the user viewing the notification, can be used for GENDER.\n{{Related|Flow-notification}}", diff --git a/includes/Block/TopicSummary.php b/includes/Block/TopicSummary.php index 5ee346f..21f92a9 100644 --- a/includes/Block/TopicSummary.php +++ b/includes/Block/TopicSummary.php @@ -203,6 +203,7 @@ $this->storage->put( $this->nextRevision, array( 'workflow' => $this->workflow, + 'topic-title' => $this->findTopicTitle(), ) ); // Reload the $this->formatterRow for renderApi() after save $this->formatterRow = new FormatterRow(); diff --git a/includes/Data/Listener/NotificationListener.php b/includes/Data/Listener/NotificationListener.php index 637e25f..0cf8f2a 100644 --- a/includes/Data/Listener/NotificationListener.php +++ b/includes/Data/Listener/NotificationListener.php @@ -3,9 +3,11 @@ namespace Flow\Data\Listener; use Flow\Exception\InvalidDataException; +use Flow\Exception\InvalidInputException; use Flow\Model\AbstractRevision; use Flow\Model\Header; use Flow\Model\PostRevision; +use Flow\Model\PostSummary; use Flow\Model\Workflow; use Flow\NotificationController; @@ -63,7 +65,18 @@ break; case 'edit-header': - $this->notifyHeaderChange( 'flow-description-edited', $object, $metadata ); + $this->notificationController->notifyHeaderChange( 'flow-description-edited', array( + 'revision' => $object, + 'board-workflow' => $metadata['workflow'], + ) ); + break; + + case 'edit-topic-summary': + $this->notificationController->notifySummaryChange( 'flow-summary-edited', array( + 'revision' => $object, + 'topic-workflow' => $metadata['workflow'], + 'topic-title' => $metadata['topic-title'], + ) ); break; } } @@ -92,29 +105,6 @@ 'revision' => $object, 'topic-workflow' => $workflow, 'topic-title' => $metadata['topic-title'], - ) ); - } - - /** - * @param string $type - * @param Header $object - * @param array $metadata - * @param array $params - * @throws InvalidDataException - */ - protected function notifyHeaderChange( $type, Header $object, $metadata, array $params = array() ) { - if ( !isset( $metadata['workflow'] ) ) { - throw new InvalidDataException( 'Invalid metadata for header revision ' . $object->getRevisionId()->getAlphadecimal(), 'missing-metadata' ); - } - - $workflow = $metadata['workflow']; - if ( !$workflow instanceof Workflow ) { - throw new InvalidDataException( 'Workflow metadata is not a Workflow', 'missing-metadata' ); - } - - $this->notificationController->notifyHeaderChange( $type, $params + array( - 'revision' => $object, - 'board-workflow' => $workflow, ) ); } } diff --git a/includes/Notifications/Controller.php b/includes/Notifications/Controller.php index 9ebd1f6..799c25d 100644 --- a/includes/Notifications/Controller.php +++ b/includes/Notifications/Controller.php @@ -7,6 +7,7 @@ use Flow\Model\AbstractRevision; use Flow\Model\Header; use Flow\Model\PostRevision; +use Flow\Model\PostSummary; use Flow\Model\UUID; use Flow\Model\Workflow; use Flow\Conversion\Utils; @@ -214,6 +215,48 @@ } /** + * Causes notifications to be fired for a Header-related event. + * @param String $eventName The event that occurred. + * @param array $data Associative array of parameters. + * * revision: The PostRevision created by the action. Always required. + * * topic-title: The PostRevision object for the topic title. Always required. + * * topic-workflow: The Workflow object for the board. Always required. + * * extra-data: Additional data to pass along to Event extra. + * @return array Array of created EchoEvent objects. + * @throws FlowException When $data contains unexpected types/values + */ + public function notifySummaryChange( $eventName, $data = array() ) { + if ( !class_exists( 'EchoEvent' ) ) { + return array(); + } + + $revision = $data['revision']; + if ( !$revision instanceof PostSummary ) { + throw new FlowException( 'Expected PostSummary but received ' . get_class( $revision ) ); + } + $topicRevision = $data['topic-title']; + if ( !$topicRevision instanceof PostRevision ) { + throw new FlowException( 'Expected PostRevision but received ' . get_class( $topicRevision ) ); + } + $topicWorkflow = $data['topic-workflow']; + if ( !$topicWorkflow instanceof Workflow ) { + throw new FlowException( 'Expected Workflow but received ' . get_class( $topicWorkflow ) ); + } + + $user = $revision->getUser(); + $events = array(); + + $mentionEvent = $this->generateMentionEvent( $revision, $topicRevision, $topicWorkflow, $user ); + if ( $mentionEvent ) { + $events[] = $mentionEvent; + } + + // @todo we may also want other topic summary edit notifications, some day + + return $events; + } + + /** * Triggers notifications for a new topic. * @param array $params Associative array of parameters, all required: * * board-workflow: Workflow object for the Flow board. @@ -323,10 +366,13 @@ // lets us differentiate between different revision types $extraData['revision-type'] = $content->getRevisionType(); - // additional data needed to render topic/post data + // additional data needed to render link to post if ( $extraData['revision-type'] === 'post' ) { $extraData['post-id'] = $content->getCollection()->getId(); $extraData['topic-workflow'] = $workflow->getId(); + } + // needed to render topic title text + if ( $topic !== null ) { $extraData['topic-title'] = Utils::htmlToPlaintext( $topic->getContent( 'topic-title-html' ), 200, $this->language ); } diff --git a/includes/Notifications/MentionPresentationModel.php b/includes/Notifications/MentionPresentationModel.php index 9ffe6ad..51d1d6e 100644 --- a/includes/Notifications/MentionPresentationModel.php +++ b/includes/Notifications/MentionPresentationModel.php @@ -42,7 +42,7 @@ $msg->params( $this->getTruncatedTitleText( $this->event->getTitle(), true) ); $msg->params( $this->getViewingUserForGender() ); - if ( $this->getType() === 'post' ) { + if ( in_array( $this->getType(), array( 'post', 'post-summary' ) ) ) { $msg->params( $this->getTopicTitle() ); } -- To view, visit https://gerrit.wikimedia.org/r/269105 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I035686e3d87e8a47ab8a6c95423a1bba63339d0b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Flow Gerrit-Branch: master Gerrit-Owner: Matthias Mullie <mmul...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits