From 4a25a985ffbc86b51fd04f4907774b6d162e2aa3 Mon Sep 17 00:00:00 2001 From: Ammarpad Date: Sat, 26 Oct 2024 13:46:38 +0100 Subject: [PATCH] Notifications: Handle suppressed topic titles in notification EchoPresentationModelSection::getTruncatedSectionTitle() has a note that it should not be called if ::exists() returned false. Among the reason the section may not exist includes suppressing the revision where the topic title was added or edited. Add placeholder message text "(topic removed)", to be used in place of the unavailable topic title. This is analogous to "(user removed)" which would be shown along if the username is also suppressed. Bug: T378261 Change-Id: I6db0872b8724323a5e15eb6a262c2c3d0bdd630d --- i18n/en.json | 1 + i18n/qqq.json | 1 + .../SubscribedNewCommentPresentationModel.php | 13 ++++++++----- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/i18n/en.json b/i18n/en.json index 8c382b5d3..8d0fd94d9 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -83,6 +83,7 @@ "discussiontools-notification-removed-topic-disable": "Stop receiving notifications like this", "discussiontools-notification-removed-topic-disabled-title": "{{GENDER:|You}} will no longer receive notifications when a topic is archived or removed.", "discussiontools-notification-removed-topic-disabled-body": "You can change this in [[Special:Preferences#mw-prefsection-echo-echosubscriptions|your preferences]].", + "discussiontools-notification-topic-hidden": "(topic removed)", "discussiontools-notification-subscribed-new-comment-header": "$1 {{GENDER:$2|replied}} in \"$4\".", "discussiontools-notification-subscribed-new-comment-header-bundled": "{{PLURAL:$1|One new reply|$1 new replies|100=99+ new replies}} in \"$3\".", "discussiontools-notification-subscribed-new-comment-header-compact": "$1: $3.", diff --git a/i18n/qqq.json b/i18n/qqq.json index 27539b54f..83b011231 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -97,6 +97,7 @@ "discussiontools-notification-removed-topic-disable": "Button to disable notifications of the given type, shown below an Echo notification.", "discussiontools-notification-removed-topic-disabled-title": "Title of notification popup shown when a user disables this type of Echo notifications.", "discussiontools-notification-removed-topic-disabled-body": "Body of notification popup shown when a user disables this type of Echo notifications.", + "discussiontools-notification-topic-hidden": "Text shown instead of topic title when the topic title has been hidden and context user does not have permission to see it", "discussiontools-notification-subscribed-new-comment-header": "Notification header text for when there is a reply on a topic. Parameters:\n* $1 - the formatted username of the user who replied to the topic\n* $2 - the username for gender purposes\n* $3 - title of the page\n* $4 - title of the topic.", "discussiontools-notification-subscribed-new-comment-header-bundled": "Notification header text for when there is a multiple replies on a topic. Parameters:\n* $1 - the number of replies for display\n* $2 - the raw number of replies, for PLURAL\n* $3 - title of the topic.\n{{Related|discussiontools-notification-bundle}}", "discussiontools-notification-subscribed-new-comment-header-compact": "{{optional}}\nNotification compact header text for when there is a reply on a topic. Parameters:\n* $1 - the formatted username of the user who replied to the topic\n* $2 - the username for gender purposes\n* $3 - excerpt of the reply.\n{{Related|discussiontools-notification-header-flow}}", diff --git a/includes/Notifications/SubscribedNewCommentPresentationModel.php b/includes/Notifications/SubscribedNewCommentPresentationModel.php index 96339dabd..cdc8fbecd 100644 --- a/includes/Notifications/SubscribedNewCommentPresentationModel.php +++ b/includes/Notifications/SubscribedNewCommentPresentationModel.php @@ -88,17 +88,20 @@ class SubscribedNewCommentPresentationModel extends EchoEventPresentationModel { if ( $this->isBundled() ) { $count = $this->getNotificationCountForOutput(); $msg = $this->msg( $this->getHeaderMessageKey() ); - // Repeat is B/C until unused parameter is removed from translations $msg->numParams( $count, $count ); - $msg->plaintextParams( $this->section->getTruncatedSectionTitle() ); - return $msg; } else { $msg = parent::getHeaderMessage(); $msg->params( $this->getTruncatedTitleText( $this->event->getTitle(), true ) ); - $msg->plaintextParams( $this->section->getTruncatedSectionTitle() ); - return $msg; } + + if ( $this->section->exists() ) { + $msg->plaintextParams( $this->section->getTruncatedSectionTitle() ); + } else { + $msg->plaintextParams( $this->msg( 'discussiontools-notification-topic-hidden' )->text() ); + } + + return $msg; } /**