From fb0cc01ff82108224c355b50536e6ce46a0a7d52 Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Wed, 9 Dec 2020 11:58:58 +0000 Subject: [PATCH] Skip over empty inline templates (e.g. tracking templates) Bug: T269036 Change-Id: I15e56041c1f1ecb85e9e368a9fbb07882438bf8d --- includes/CommentUtils.php | 9 ++++++++- modules/utils.js | 9 ++++++++- .../signatures-comments-modified.html | 4 ++++ tests/cases/signatures-comments/signatures-comments.html | 4 ++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/includes/CommentUtils.php b/includes/CommentUtils.php index a0fecbe9a..e6ed4bb89 100644 --- a/includes/CommentUtils.php +++ b/includes/CommentUtils.php @@ -8,6 +8,7 @@ use DOMNode; use DOMXPath; use MediaWiki\MediaWikiServices; use Title; +use Wikimedia\Parsoid\Utils\DOMCompat; class CommentUtils { private function __construct() { @@ -47,7 +48,13 @@ class CommentUtils { $node instanceof DOMComment || $node instanceof DOMElement && ( strtolower( $node->tagName ) === 'meta' || - strtolower( $node->tagName ) === 'link' + strtolower( $node->tagName ) === 'link' || + // Empty inline templates, e.g. tracking templates + ( + strtolower( $node->tagName ) === 'span' && + in_array( 'mw:Transclusion', explode( ' ', $node->getAttribute( 'typeof' ) ) ) && + !self::htmlTrim( DOMCompat::getInnerHTML( $node ) ) + ) ) ); } diff --git a/modules/utils.js b/modules/utils.js index 926cafe7c..0a01b306f 100644 --- a/modules/utils.js +++ b/modules/utils.js @@ -22,7 +22,14 @@ function isRenderingTransparentNode( node ) { node.nodeType === Node.COMMENT_NODE || node.nodeType === Node.ELEMENT_NODE && ( node.tagName.toLowerCase() === 'meta' || - node.tagName.toLowerCase() === 'link' + node.tagName.toLowerCase() === 'link' || + // Empty inline templates, e.g. tracking templates + ( + node.tagName.toLowerCase() === 'span' && + node.getAttribute( 'typeof' ).split( ' ' ).indexOf( 'mw:Transclusion' ) !== -1 && + // eslint-disable-next-line no-use-before-define + !htmlTrim( node.innerHTML ) + ) ) ); } diff --git a/tests/cases/signatures-comments/signatures-comments-modified.html b/tests/cases/signatures-comments/signatures-comments-modified.html index 52c8d8f6c..492a8afd5 100644 --- a/tests/cases/signatures-comments/signatures-comments-modified.html +++ b/tests/cases/signatures-comments/signatures-comments-modified.html @@ -10,6 +10,10 @@

hello Matma Rex (talk) 18:44, 22 July 2020 (UTC)

Reply to c|Matma Rex|2020-07-22T18:44:00.000Z|comments_T257651
+
Blocked! + +Admin (talk) 21:33, 8 December 2020 (UTC)
Reply to c|Admin|2020-12-08T21:33:00.000Z|comments_T257651
+

hello Matma Rex (talk) 18:45, 22 July 2020 (UTC)

Reply to c|Matma Rex|2020-07-22T18:45:00.000Z|comments_T257651

hello Matma Rex (talk) 18:46, 22 July 2020 (UTC)

Reply to c|Matma Rex|2020-07-22T18:46:00.000Z|comments_T257651
diff --git a/tests/cases/signatures-comments/signatures-comments.html b/tests/cases/signatures-comments/signatures-comments.html index 6b74e24f5..bc32ece84 100644 --- a/tests/cases/signatures-comments/signatures-comments.html +++ b/tests/cases/signatures-comments/signatures-comments.html @@ -10,6 +10,10 @@

hello Matma Rex (talk) 18:44, 22 July 2020 (UTC)

+
Blocked! + +Admin (talk) 21:33, 8 December 2020 (UTC)
+

hello Matma Rex (talk) 18:45, 22 July 2020 (UTC)

hello Matma Rex (talk) 18:46, 22 July 2020 (UTC)