diff --git a/extension.json b/extension.json index 76475cf60..008985c7c 100644 --- a/extension.json +++ b/extension.json @@ -475,6 +475,7 @@ "MinervaNeueTalkPageOverlay": "\\MediaWiki\\Extension\\DiscussionTools\\Hooks\\MobileHooks::onMinervaNeueTalkPageOverlay", "LoadExtensionSchemaUpdates": "installer", "ParserAfterTidy": "parser", + "ParserOutputPostCacheTransform": "parser", "ArticleViewHeader": "page", "BeforeDisplayNoArticleText": "page", "BeforePageDisplay": "page", diff --git a/includes/CommentFormatter.php b/includes/CommentFormatter.php index ec72d9a45..f5ba28ff4 100644 --- a/includes/CommentFormatter.php +++ b/includes/CommentFormatter.php @@ -278,6 +278,29 @@ class CommentFormatter { return XMLSerializer::serialize( $container, [ 'innerXML' => true, 'smartQuote' => false ] )['html']; } + /** + * Replace placeholders for all interactive tools with nothing. This is intended for cases where + * interaction is unexpected, e.g. reply links while previewing an edit. + * + * @param string $text + * @return string + */ + public static function removeInteractiveTools( string $text ) { + $text = strtr( $text, [ + '' => '', + '' => '', + '' => '', + '' => '', + '' => '', + ] ); + + $text = preg_replace( '//', '', $text ); + $text = preg_replace( '//', '', $text ); + $text = preg_replace( '//', '', $text ); + + return $text; + } + /** * Replace placeholders for topic subscription buttons with the real thing. * diff --git a/includes/Hooks/HookUtils.php b/includes/Hooks/HookUtils.php index 0e4a51e46..7cc2d9c1b 100644 --- a/includes/Hooks/HookUtils.php +++ b/includes/Hooks/HookUtils.php @@ -229,8 +229,8 @@ class HookUtils { * @return bool */ public static function isFeatureEnabledForOutput( OutputPage $output, ?string $feature = null ): bool { - // Don't show on edit pages, history, etc. - if ( $feature !== static::NEWTOPICTOOL && $output->getActionName() !== 'view' ) { + // Only show on normal page views (not history etc.), and in edit mode for previews + if ( !in_array( $output->getActionName(), [ 'view', 'edit', 'submit' ] ) ) { return false; } diff --git a/includes/Hooks/ParserHooks.php b/includes/Hooks/ParserHooks.php index e66763e83..d7bd92aac 100644 --- a/includes/Hooks/ParserHooks.php +++ b/includes/Hooks/ParserHooks.php @@ -12,9 +12,14 @@ namespace MediaWiki\Extension\DiscussionTools\Hooks; use ConfigFactory; use MediaWiki\Extension\DiscussionTools\CommentFormatter; use MediaWiki\Hook\ParserAfterTidyHook; +use MediaWiki\Hook\ParserOutputPostCacheTransformHook; use Parser; +use ParserOutput; -class ParserHooks implements ParserAfterTidyHook { +class ParserHooks implements + ParserAfterTidyHook, + ParserOutputPostCacheTransformHook +{ /** @var ConfigFactory */ private $configFactory; @@ -34,7 +39,7 @@ class ParserHooks implements ParserAfterTidyHook { * @param string &$text */ public function onParserAfterTidy( $parser, &$text ) { - if ( $parser->getOptions()->getInterfaceMessage() || $parser->getOptions()->getIsPreview() ) { + if ( $parser->getOptions()->getInterfaceMessage() ) { return; } @@ -70,4 +75,17 @@ class ParserHooks implements ParserAfterTidyHook { ] ); } } + + /** + * @see https://www.mediawiki.org/wiki/Manual:Hooks/ParserOutputPostCacheTransform + * + * @param ParserOutput $parserOutput + * @param string &$text + * @param array &$options + */ + public function onParserOutputPostCacheTransform( $parserOutput, &$text, &$options ): void { + if ( !$options['enableSectionEditLinks'] ) { + $text = CommentFormatter::removeInteractiveTools( $text ); + } + } } diff --git a/modules/ReplyLinksController.js b/modules/ReplyLinksController.js index 98c24317f..159134990 100644 --- a/modules/ReplyLinksController.js +++ b/modules/ReplyLinksController.js @@ -133,6 +133,10 @@ ReplyLinksController.prototype.onAnyLinkClick = function ( e ) { }; ReplyLinksController.prototype.isActivationEvent = function ( e ) { + if ( mw.config.get( 'wgAction' ) !== 'view' ) { + // Don't do anything when we're editing/previewing + return false; + } if ( e.type === 'keypress' && e.which !== OO.ui.Keys.ENTER && e.which !== OO.ui.Keys.SPACE ) { // Only handle keypresses on the "Enter" or "Space" keys return false; diff --git a/modules/dt.ui.ReplyWidget.less b/modules/dt.ui.ReplyWidget.less index 434888a29..026bfb51f 100644 --- a/modules/dt.ui.ReplyWidget.less +++ b/modules/dt.ui.ReplyWidget.less @@ -240,6 +240,11 @@ padding-top: 0; margin-top: 0.25em; } + + .ext-discussiontools-init-section-bar { + // Looks just a little weird to display this in preview of your own new topic (T309423) + display: none; + } } &-bodyWrapper {