mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-23 16:06:53 +00:00
Enable transformations in preview mode
We remove the [reply] and [subscribe] links when they should not be visible (controlled by 'enableSectionEditLinks' option, which is disabled when previewing). Bug: T309423 Change-Id: Ie0d3fba2c4d166daac3ea2e117a246c9584284ca
This commit is contained in:
parent
caefb1ae39
commit
2bc76dabd7
|
@ -475,6 +475,7 @@
|
|||
"MinervaNeueTalkPageOverlay": "\\MediaWiki\\Extension\\DiscussionTools\\Hooks\\MobileHooks::onMinervaNeueTalkPageOverlay",
|
||||
"LoadExtensionSchemaUpdates": "installer",
|
||||
"ParserAfterTidy": "parser",
|
||||
"ParserOutputPostCacheTransform": "parser",
|
||||
"ArticleViewHeader": "page",
|
||||
"BeforeDisplayNoArticleText": "page",
|
||||
"BeforePageDisplay": "page",
|
||||
|
|
|
@ -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, [
|
||||
'<!--__DTREPLY__-->' => '',
|
||||
'<!--__DTREPLYBRACKETOPEN__-->' => '',
|
||||
'<!--__DTREPLYBRACKETCLOSE__-->' => '',
|
||||
'<!--__DTELLIPSISBUTTON__-->' => '',
|
||||
'<!--__DTEMPTYTALKPAGE__-->' => '',
|
||||
] );
|
||||
|
||||
$text = preg_replace( '/<!--__DTSUBSCRIBE__(.*?)-->/', '', $text );
|
||||
$text = preg_replace( '/<!--__DTSUBSCRIBELINK__(.*?)-->/', '', $text );
|
||||
$text = preg_replace( '/<!--__DTSUBSCRIBEBUTTON__(.*?)-->/', '', $text );
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace placeholders for topic subscription buttons with the real thing.
|
||||
*
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue