From 7dff37e354ed04757a5e2f014aab6a4b7afe5e9b Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Mon, 28 Aug 2023 19:53:28 +0100 Subject: [PATCH] Show new topics subscription button on history pages Bug: T345096 Change-Id: I5da6ac0bca900f9fe3482d247d20aaf24feb61f2 --- includes/Hooks/HookUtils.php | 10 ++++++++-- includes/Hooks/PageHooks.php | 2 ++ modules/dt.init.js | 9 ++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/includes/Hooks/HookUtils.php b/includes/Hooks/HookUtils.php index 7b13dbbd5..3d12d70ea 100644 --- a/includes/Hooks/HookUtils.php +++ b/includes/Hooks/HookUtils.php @@ -406,8 +406,14 @@ class HookUtils { // Don't try to call $output->getActionName if testing for NEWTOPICTOOL as we use // the hook onGetActionName to override the action for the tool on empty pages. // If we tried to call it here it would set up infinite recursion (T312689) - $feature !== static::NEWTOPICTOOL && - !in_array( $output->getActionName(), [ 'view', 'edit', 'submit' ], true ) + $feature !== static::NEWTOPICTOOL && !( + in_array( $output->getActionName(), [ 'view', 'edit', 'submit' ], true ) || + // Subscriptions (specifically page-level subscriptions) are available on history pages (T345096) + ( + $output->getActionName() === 'history' && + $feature === static::TOPICSUBSCRIPTION + ) + ) ) { return false; } diff --git a/includes/Hooks/PageHooks.php b/includes/Hooks/PageHooks.php index db81d8cfb..e88b50221 100644 --- a/includes/Hooks/PageHooks.php +++ b/includes/Hooks/PageHooks.php @@ -584,6 +584,8 @@ class PageHooks implements 'data-mw-subscribed' => $button['isSubscribed'] ? '1' : '0', 'href' => $button['href'], ]; + + $output->addModules( [ 'ext.discussionTools.init' ] ); } } diff --git a/modules/dt.init.js b/modules/dt.init.js index 3a41b4451..92f71d1ba 100644 --- a/modules/dt.init.js +++ b/modules/dt.init.js @@ -77,11 +77,18 @@ if ( url.searchParams.get( 'dtdebug' ) ) { mw.hook( 'wikipage.content' ).add( mw.dt.init ); } +var topicSubscriptions; + if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'TopicSubscriptions' ) { - var topicSubscriptions = require( './topicsubscriptions.js' ); + topicSubscriptions = require( './topicsubscriptions.js' ); topicSubscriptions.initSpecialTopicSubscriptions(); } +if ( mw.config.get( 'wgAction' ) === 'history' ) { + topicSubscriptions = require( './topicsubscriptions.js' ); + topicSubscriptions.initNewTopicsSubscription(); +} + // Clean up old localStorage entries that were erroneously set with no expiration (T339042). // We are no longer using these keys since T329299. // TODO: Remove this code after a few weeks.