From ad99faef19ab5e96f24338dd648d8536f9b1fc4f Mon Sep 17 00:00:00 2001 From: Ammarpad Date: Sat, 2 Nov 2024 21:45:14 +0100 Subject: [PATCH] Handle hidden revision in more places Instead of checking section->exists() everywhere we have to call getTruncatedSectionTitle(), override the method inside PlaintextEchoPresentationModelSection class to make it always return string for our case. Call to getTruncatedSectionTitle() in the following classes now use the method override: * RemovedTopicPresentationModel * SubscribedNewCommentPresentationModel * AddedTopicPresentationModel The call to getTruncatedSectionTitle() in CommentThanksPresentationModel does not need nor use the override. Bug: T378261 Change-Id: Ibe985da5c1a79c5a1853d9c4896f8769cce6ddfd --- .../PlaintextEchoPresentationModelSection.php | 14 ++++++++++++++ .../SubscribedNewCommentPresentationModel.php | 6 +----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/includes/Notifications/PlaintextEchoPresentationModelSection.php b/includes/Notifications/PlaintextEchoPresentationModelSection.php index 12126a8c1..49c5bf5d8 100644 --- a/includes/Notifications/PlaintextEchoPresentationModelSection.php +++ b/includes/Notifications/PlaintextEchoPresentationModelSection.php @@ -48,4 +48,18 @@ class PlaintextEchoPresentationModelSection extends EchoPresentationModelSection } return $title; } + + /** + * Get truncated section title, according to user's language + * or a placeholder text if the section title is not available. + * + * @return string + */ + public function getTruncatedSectionTitle() { + if ( $this->exists() ) { + return parent::getTruncatedSectionTitle(); + } + + return wfMessage( 'discussiontools-notification-topic-hidden' )->inLanguage( $this->language )->text(); + } } diff --git a/includes/Notifications/SubscribedNewCommentPresentationModel.php b/includes/Notifications/SubscribedNewCommentPresentationModel.php index cdc8fbecd..23b5a07a6 100644 --- a/includes/Notifications/SubscribedNewCommentPresentationModel.php +++ b/includes/Notifications/SubscribedNewCommentPresentationModel.php @@ -90,15 +90,11 @@ class SubscribedNewCommentPresentationModel extends EchoEventPresentationModel { $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() ); } else { $msg = parent::getHeaderMessage(); $msg->params( $this->getTruncatedTitleText( $this->event->getTitle(), true ) ); - } - - if ( $this->section->exists() ) { $msg->plaintextParams( $this->section->getTruncatedSectionTitle() ); - } else { - $msg->plaintextParams( $this->msg( 'discussiontools-notification-topic-hidden' )->text() ); } return $msg;