From 1b2517faf722cedce716e225b7a485bac933868a Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Thu, 7 Oct 2021 17:34:24 +0100 Subject: [PATCH] Show created/notified dates on Special:TopicSubscriptions Extracted from patchset 29...28 of If96a0df1ef. Also adds sorting functionality to sub_created using the existing index on sub_id. Bug: T294162 Change-Id: Ic4702c8c5a8119d9cdb4c3c99cf110626694777f --- i18n/en.json | 3 +++ i18n/qqq.json | 3 +++ includes/TopicSubscriptionsPager.php | 19 +++++++++++++++++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/i18n/en.json b/i18n/en.json index 23bda19b9..626a68f24 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -124,6 +124,9 @@ "discussiontools-topicsubscription-notify-unsubscribed-body": "You will no longer receive notifications about new comments in this topic.", "discussiontools-topicsubscription-notify-unsubscribed-title": "You have unsubscribed.", "discussiontools-topicsubscription-pager-actions": "Actions", + "discussiontools-topicsubscription-pager-created": "First subscribed", + "discussiontools-topicsubscription-pager-notified": "Latest notification", + "discussiontools-topicsubscription-pager-notified-never": "never", "discussiontools-topicsubscription-pager-page": "Page", "discussiontools-topicsubscription-pager-topic": "Topic", "discussiontools-topicsubscription-pager-unsubscribe-button": "Unsubscribe", diff --git a/i18n/qqq.json b/i18n/qqq.json index 6623ec762..7d69c8f72 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -135,6 +135,9 @@ "discussiontools-topicsubscription-notify-unsubscribed-body": "Body of notification shown when a user unsubscribes from a topic.", "discussiontools-topicsubscription-notify-unsubscribed-title": "Title of notification shown when a user unsubscribes from a topic.", "discussiontools-topicsubscription-pager-actions": "Used on [[mw:Special:TopicSubscriptions|Special:TopicSubscriptions]] as a table heading.\n{{identical|Action}}", + "discussiontools-topicsubscription-pager-created": "Used on [[mw:Special:TopicSubscriptions|Special:TopicSubscriptions]] as a table heading.", + "discussiontools-topicsubscription-pager-notified": "Used on [[mw:Special:TopicSubscriptions|Special:TopicSubscriptions]] as a table heading.", + "discussiontools-topicsubscription-pager-notified-never": "Used on [[mw:Special:TopicSubscriptions|Special:TopicSubscriptions]] in the table.", "discussiontools-topicsubscription-pager-page": "Used on [[mw:Special:TopicSubscriptions|Special:TopicSubscriptions]] as a table heading.", "discussiontools-topicsubscription-pager-topic": "Used on [[mw:Special:TopicSubscriptions|Special:TopicSubscriptions]] as a table heading.", "discussiontools-topicsubscription-pager-unsubscribe-button": "Used on [[mw:Special:TopicSubscriptions|Special:TopicSubscriptions]] in the table, as a button label.", diff --git a/includes/TopicSubscriptionsPager.php b/includes/TopicSubscriptionsPager.php index 0e90acc13..4bf1c5c12 100644 --- a/includes/TopicSubscriptionsPager.php +++ b/includes/TopicSubscriptionsPager.php @@ -18,7 +18,10 @@ class TopicSubscriptionsPager extends TablePager { * won't get "stuck" when e.g. 50 subscriptions are all created within a second. */ private const INDEX_FIELDS = [ + // The auto-increment ID will almost always have the same order as sub_created + // and the field already has an index. '_topic' => [ 'sub_id' ], + 'sub_created' => [ 'sub_id' ], // TODO Add indexes that cover these fields to enable sorting by them // 'sub_state' => [ 'sub_state', 'sub_item' ], // 'sub_created' => [ 'sub_created', 'sub_item' ], @@ -60,6 +63,8 @@ class TopicSubscriptionsPager extends TablePager { return [ '_topic' => $this->msg( 'discussiontools-topicsubscription-pager-topic' )->text(), '_page' => $this->msg( 'discussiontools-topicsubscription-pager-page' )->text(), + 'sub_created' => $this->msg( 'discussiontools-topicsubscription-pager-created' )->text(), + 'sub_notified' => $this->msg( 'discussiontools-topicsubscription-pager-notified' )->text(), '_unsubscribe' => $this->msg( 'discussiontools-topicsubscription-pager-actions' )->text(), ]; } @@ -81,6 +86,14 @@ class TopicSubscriptionsPager extends TablePager { $title = Title::makeTitleSafe( $row->sub_namespace, $row->sub_title ); return $linkRenderer->makeLink( $title, $title->getPrefixedText() ); + case 'sub_created': + return htmlspecialchars( $this->getLanguage()->userTimeAndDate( $value, $this->getUser() ) ); + + case 'sub_notified': + return $value ? + htmlspecialchars( $this->getLanguage()->userTimeAndDate( $value, $this->getUser() ) ) : + $this->msg( 'discussiontools-topicsubscription-pager-notified-never' )->escaped(); + case '_unsubscribe': $title = Title::makeTitleSafe( $row->sub_namespace, $row->sub_title ); return (string)new OOUI\ButtonWidget( [ @@ -123,6 +136,8 @@ class TopicSubscriptionsPager extends TablePager { 'sub_namespace', 'sub_title', 'sub_section', + 'sub_created', + 'sub_notified', ], 'conds' => [ 'sub_user' => $this->getUser()->getId(), @@ -135,7 +150,7 @@ class TopicSubscriptionsPager extends TablePager { * @inheritDoc */ public function getDefaultSort() { - return '_topic'; + return 'sub_created'; } /** @@ -149,7 +164,7 @@ class TopicSubscriptionsPager extends TablePager { * @inheritDoc */ protected function isFieldSortable( $field ) { - // Topic is set to the auto-ID field (sub_id), so sorting by it is not very useful + // Hide the sort button for "Topic" as it is more accurately shown as "Created" return isset( static::INDEX_FIELDS[$field] ) && $field !== '_topic'; } }