Support suppressing comment detection in pages or sections

This can be done within sections using CSS:
* mw-notalk

Or at a page level using a magic word:
* __NOTALK__

"notalk" suppresses all comment detection, treating the content as
not containing any comments even if there are signatures present.

Bug: T295553
Bug: T249293
Change-Id: Ic1d7294bafcf7071e16838e70684ecadd7bc6fd3
This commit is contained in:
Ed Sanders 2023-03-27 13:50:45 +01:00 committed by Bartosz Dziewoński
parent 856b90fa3e
commit 92f5cfd821
9 changed files with 119 additions and 57 deletions

View file

@ -4,4 +4,5 @@ $magicWords = [];
/** English (English) */
$magicWords['en'] = [
'archivedtalk' => [ 0, '__ARCHIVEDTALK__' ],
'notalk' => [ 0, '__NOTALK__' ],
];

View file

@ -691,6 +691,19 @@ class CommentParser {
if ( $node->getAttribute( 'id' ) === 'toc' ) {
return NodeFilter::FILTER_REJECT;
}
// Don't detect comments within quotes (T275881)
if (
$tagName === 'blockquote' ||
$tagName === 'cite' ||
$tagName === 'q'
) {
return NodeFilter::FILTER_REJECT;
}
$classList = DOMCompat::getClassList( $node );
// Don't attempt to parse blocks marked 'mw-notalk'
if ( $classList->contains( 'mw-notalk' ) ) {
return NodeFilter::FILTER_REJECT;
}
// Don't detect comments within references. We can't add replies to them without bungling up
// the structure in some cases (T301213), and you're not supposed to do that anyway…
if (
@ -700,14 +713,6 @@ class CommentParser {
) {
return NodeFilter::FILTER_REJECT;
}
// Don't detect comments within quotes (T275881)
if (
$tagName === 'blockquote' ||
$tagName === 'cite' ||
$tagName === 'q'
) {
return NodeFilter::FILTER_REJECT;
}
}
$parentNode = $node->parentNode;
// Don't detect comments within headings (but don't reject the headings themselves)

View file

@ -349,7 +349,10 @@ class HookUtils {
return false;
}
// ARCHIVEDTALK magic word
// ARCHIVEDTALK/NOTALK magic words
if ( self::hasPagePropCached( $title, 'notalk' ) ) {
return false;
}
if (
$feature === static::REPLYTOOL &&
self::hasPagePropCached( $title, 'archivedtalk' )

View file

@ -85,5 +85,6 @@ class ParserHooks implements
*/
public function onGetDoubleUnderscoreIDs( &$doubleUnderscoreIDs ) {
$doubleUnderscoreIDs[] = 'archivedtalk';
$doubleUnderscoreIDs[] = 'notalk';
}
}

View file

@ -454,6 +454,18 @@ function acceptOnlyNodesAllowingComments( node ) {
if ( node.id === 'toc' ) {
return NodeFilter.FILTER_REJECT;
}
// Don't detect comments within quotes (T275881)
if (
tagName === 'blockquote' ||
tagName === 'cite' ||
tagName === 'q'
) {
return NodeFilter.FILTER_REJECT;
}
// Don't attempt to parse blocks marked 'mw-notalk'
if ( node.classList.contains( 'mw-notalk' ) ) {
return NodeFilter.FILTER_REJECT;
}
// Don't detect comments within references. We can't add replies to them without bungling up
// the structure in some cases (T301213), and you're not supposed to do that anyway…
if (
@ -463,14 +475,6 @@ function acceptOnlyNodesAllowingComments( node ) {
) {
return NodeFilter.FILTER_REJECT;
}
// Don't detect comments within quotes (T275881)
if (
tagName === 'blockquote' ||
tagName === 'cite' ||
tagName === 'q'
) {
return NodeFilter.FILTER_REJECT;
}
}
var parentNode = node.parentNode;
// Don't detect comments within headings (but don't reject the headings themselves)

View file

@ -1,4 +1,10 @@
<div class="mw-parser-output">
<div class="mw-heading mw-heading2 ext-discussiontools-init-section"><h2><span class="mw-headline" id="No_talk_section" data-mw-thread-id="h-No_talk_section"><span data-mw-comment-start="" id="h-No_talk_section"></span>No talk section<span data-mw-comment-end="h-No_talk_section"></span></span></h2></div>
<div class="mw-notalk">
<ul><li>Vote 1. <a href="/wiki/User:DTDummyUserAlice" title="User:DTDummyUserAlice">DTDummyUserAlice</a> (<a href="/wiki/User_talk:DTDummyUserAlice" title="User talk:DTDummyUserAlice">talk</a>) 13:30, 10 March 2022 (UTC)</li>
<li>Vote 2. <a href="/wiki/User:DTDummyUserBob" title="User:DTDummyUserBob">DTDummyUserBob</a> (<a href="/wiki/User_talk:DTDummyUserBob" title="User talk:DTDummyUserBob">talk</a>) 13:40, 10 March 2022 (UTC)</li>
<li>Vote 3. <a href="/wiki/User:DTDummyUserEve" title="User:DTDummyUserEve">DTDummyUserEve</a> (<a href="/wiki/User_talk:DTDummyUserEve" title="User talk:DTDummyUserEve">talk</a>) 13:50, 10 March 2022 (UTC)</li></ul>
</div>
<div class="mw-archivedtalk" style="background: lightblue; padding: 20px; border: 1px solid blue;">
<div class="mw-heading mw-heading2 ext-discussiontools-init-section"><span class='ext-discussiontools-init-section-subscribeButton oo-ui-widget oo-ui-widget-enabled oo-ui-buttonElement oo-ui-buttonElement-frameless oo-ui-iconElement oo-ui-labelElement oo-ui-flaggedElement-progressive oo-ui-buttonWidget' data-ooui='{"_":"OO.ui.ButtonWidget","rel":["nofollow"],"framed":false,"icon":"bellOutline","label":"(discussiontools-topicsubscription-button-subscribe-label)","title":"(discussiontools-topicsubscription-button-subscribe-tooltip)","flags":["progressive"],"classes":["ext-discussiontools-init-section-subscribeButton"]}'><a role='button' title='(discussiontools-topicsubscription-button-subscribe-tooltip)' tabindex='0' rel='nofollow' class='oo-ui-buttonElement-button'><span class='oo-ui-iconElement-icon oo-ui-icon-bellOutline oo-ui-image-progressive'></span><span class='oo-ui-labelElement-label'>(discussiontools-topicsubscription-button-subscribe-label)</span><span class='oo-ui-indicatorElement-indicator oo-ui-indicatorElement-noIndicator oo-ui-image-progressive'></span></a></span><h2><span class="ext-discussiontools-init-section-subscribe mw-editsection-like"><span class="ext-discussiontools-init-section-subscribe-bracket">[</span><a href="" class="ext-discussiontools-init-section-subscribe-link" role="button" tabindex="0" title="(discussiontools-topicsubscription-button-subscribe-tooltip)">(discussiontools-topicsubscription-button-subscribe)</a><span class="ext-discussiontools-init-section-subscribe-bracket">]</span></span><span class="mw-headline" id="Archived_section" data-mw-thread-id="h-Archived_section-2022-03-10T14:30:00.000Z"><span data-mw-comment-start="" id="h-Archived_section-2022-03-10T14:30:00.000Z"></span>Archived section<span data-mw-comment-end="h-Archived_section-2022-03-10T14:30:00.000Z"></span></span></h2><div class="ext-discussiontools-init-section-bar"><div class="ext-discussiontools-init-section-metadata"><span class='ext-discussiontools-init-section-metaitem ext-discussiontools-init-section-timestampLabel'>(discussiontools-topicheader-latestcomment: <a href="#c-DTDummyUserEve-2022-03-10T14:50:00.000Z-DTDummyUserBob-2022-03-10T14:40:00.000Z">1646923800</a>)</span><span class='ext-discussiontools-init-section-metaitem ext-discussiontools-init-section-commentCountLabel'>(discussiontools-topicheader-commentcount: 3)</span><span class='ext-discussiontools-init-section-metaitem ext-discussiontools-init-section-authorCountLabel'>(discussiontools-topicheader-authorcount: 3)</span></div><div class="ext-discussiontools-init-section-actions"></div></div></div>
<p><span data-mw-comment-start="" id="c-DTDummyUserAlice-2022-03-10T14:30:00.000Z-Archived_section"></span>Comment 1. <a href="/wiki/User:DTDummyUserAlice" title="User:DTDummyUserAlice">DTDummyUserAlice</a> (<a href="/wiki/User_talk:DTDummyUserAlice" title="User talk:DTDummyUserAlice">talk</a>) 14:30, 10 March 2022 (UTC)<span class="ext-discussiontools-init-replylink-buttons" data-mw-thread-id="c-DTDummyUserAlice-2022-03-10T14:30:00.000Z-Archived_section"><span class="ext-discussiontools-init-replybutton oo-ui-widget oo-ui-widget-enabled oo-ui-buttonElement oo-ui-buttonElement-frameless oo-ui-labelElement oo-ui-flaggedElement-progressive oo-ui-buttonWidget" data-ooui='{"_":"OO.ui.ButtonWidget","rel":["nofollow"],"framed":false,"label":"(discussiontools-replybutton)","flags":["progressive"],"classes":["ext-discussiontools-init-replybutton"]}'><a role="button" tabindex="0" rel="nofollow" class="oo-ui-buttonElement-button"><span class="oo-ui-iconElement-icon oo-ui-iconElement-noIcon oo-ui-image-progressive"></span><span class="oo-ui-labelElement-label">(discussiontools-replybutton)</span><span class="oo-ui-indicatorElement-indicator oo-ui-indicatorElement-noIndicator oo-ui-image-progressive"></span></a></span><span class="ext-discussiontools-init-replylink-bracket">[</span><a class="ext-discussiontools-init-replylink-reply" role="button" tabindex="0" href="">(discussiontools-replylink)</a><span class="ext-discussiontools-init-replylink-bracket">]</span></span><span data-mw-comment-end="c-DTDummyUserAlice-2022-03-10T14:30:00.000Z-Archived_section"></span>
@ -34,6 +40,14 @@ newestComment: {
hasLedeContent
{
"wgDiscussionToolsPageThreads": [
{
"headingLevel": 2,
"name": "h-",
"type": "heading",
"level": 0,
"id": "h-No_talk_section",
"replies": []
},
{
"headingLevel": 2,
"name": "h-DTDummyUserAlice-2022-03-10T14:30:00.000Z",

View file

@ -1,4 +1,10 @@
<div class="mw-parser-output">
<div class="mw-heading mw-heading2 ext-discussiontools-init-section"><h2><span class="mw-headline" id="No_talk_section" data-mw-thread-id="h-No_talk_section"><span data-mw-comment-start="" id="h-No_talk_section"></span>No talk section<span data-mw-comment-end="h-No_talk_section"></span></span></h2><span class='ext-discussiontools-init-section-ellipsisButton oo-ui-widget oo-ui-widget-enabled oo-ui-buttonElement oo-ui-buttonElement-frameless oo-ui-iconElement oo-ui-buttonWidget' data-ooui='{"_":"OO.ui.ButtonMenuSelectWidget","rel":["nofollow"],"framed":false,"icon":"ellipsis","classes":["ext-discussiontools-init-section-ellipsisButton"]}'><a role='button' tabindex='0' rel='nofollow' class='oo-ui-buttonElement-button'><span class='oo-ui-iconElement-icon oo-ui-icon-ellipsis'></span><span class='oo-ui-labelElement-label'></span><span class='oo-ui-indicatorElement-indicator oo-ui-indicatorElement-noIndicator'></span></a></span></div>
<div class="mw-notalk">
<ul><li>Vote 1. <a href="/wiki/User:DTDummyUserAlice" title="User:DTDummyUserAlice">DTDummyUserAlice</a> (<a href="/wiki/User_talk:DTDummyUserAlice" title="User talk:DTDummyUserAlice">talk</a>) 13:30, 10 March 2022 (UTC)</li>
<li>Vote 2. <a href="/wiki/User:DTDummyUserBob" title="User:DTDummyUserBob">DTDummyUserBob</a> (<a href="/wiki/User_talk:DTDummyUserBob" title="User talk:DTDummyUserBob">talk</a>) 13:40, 10 March 2022 (UTC)</li>
<li>Vote 3. <a href="/wiki/User:DTDummyUserEve" title="User:DTDummyUserEve">DTDummyUserEve</a> (<a href="/wiki/User_talk:DTDummyUserEve" title="User talk:DTDummyUserEve">talk</a>) 13:50, 10 March 2022 (UTC)</li></ul>
</div>
<div class="mw-archivedtalk" style="background: lightblue; padding: 20px; border: 1px solid blue;">
<div class="mw-heading mw-heading2 ext-discussiontools-init-section"><h2><span class="ext-discussiontools-init-section-subscribe mw-editsection-like"><span class="ext-discussiontools-init-section-subscribe-bracket">[</span><a href="" class="ext-discussiontools-init-section-subscribe-link" role="button" tabindex="0" title="(discussiontools-topicsubscription-button-subscribe-tooltip)">(discussiontools-topicsubscription-button-subscribe)</a><span class="ext-discussiontools-init-section-subscribe-bracket">]</span></span><span class="mw-headline" id="Archived_section" data-mw-thread-id="h-Archived_section-2022-03-10T14:30:00.000Z"><span data-mw-comment-start="" id="h-Archived_section-2022-03-10T14:30:00.000Z"></span>Archived section<span data-mw-comment-end="h-Archived_section-2022-03-10T14:30:00.000Z"></span></span></h2><span class='ext-discussiontools-init-section-ellipsisButton oo-ui-widget oo-ui-widget-enabled oo-ui-buttonElement oo-ui-buttonElement-frameless oo-ui-iconElement oo-ui-buttonWidget' data-ooui='{"_":"OO.ui.ButtonMenuSelectWidget","rel":["nofollow"],"framed":false,"icon":"ellipsis","classes":["ext-discussiontools-init-section-ellipsisButton"]}'><a role='button' tabindex='0' rel='nofollow' class='oo-ui-buttonElement-button'><span class='oo-ui-iconElement-icon oo-ui-icon-ellipsis'></span><span class='oo-ui-labelElement-label'></span><span class='oo-ui-indicatorElement-indicator oo-ui-indicatorElement-noIndicator'></span></a></span><div class="ext-discussiontools-init-section-bar"><div class="ext-discussiontools-init-section-metadata"><span class='ext-discussiontools-init-section-metaitem ext-discussiontools-init-section-timestampLabel'>(discussiontools-topicheader-latestcomment: <a href="#c-DTDummyUserEve-2022-03-10T14:50:00.000Z-DTDummyUserBob-2022-03-10T14:40:00.000Z">1646923800</a>)</span><span class='ext-discussiontools-init-section-metaitem ext-discussiontools-init-section-commentCountLabel'>(discussiontools-topicheader-commentcount: 3)</span><span class='ext-discussiontools-init-section-metaitem ext-discussiontools-init-section-authorCountLabel'>(discussiontools-topicheader-authorcount: 3)</span></div><div class="ext-discussiontools-init-section-actions"><span class='ext-discussiontools-init-section-subscribeButton oo-ui-widget oo-ui-widget-enabled oo-ui-buttonElement oo-ui-buttonElement-frameless oo-ui-iconElement oo-ui-labelElement oo-ui-flaggedElement-progressive oo-ui-buttonWidget' data-ooui='{"_":"OO.ui.ButtonWidget","rel":["nofollow"],"framed":false,"icon":"bellOutline","label":"(discussiontools-topicsubscription-button-subscribe-label)","title":"(discussiontools-topicsubscription-button-subscribe-tooltip)","flags":["progressive"],"classes":["ext-discussiontools-init-section-subscribeButton"]}'><a role='button' title='(discussiontools-topicsubscription-button-subscribe-tooltip)' tabindex='0' rel='nofollow' class='oo-ui-buttonElement-button'><span class='oo-ui-iconElement-icon oo-ui-icon-bellOutline oo-ui-image-progressive'></span><span class='oo-ui-labelElement-label'>(discussiontools-topicsubscription-button-subscribe-label)</span><span class='oo-ui-indicatorElement-indicator oo-ui-indicatorElement-noIndicator oo-ui-image-progressive'></span></a></span></div></div></div>
<p><span data-mw-comment-start="" id="c-DTDummyUserAlice-2022-03-10T14:30:00.000Z-Archived_section"></span>Comment 1. <a href="/wiki/User:DTDummyUserAlice" title="User:DTDummyUserAlice">DTDummyUserAlice</a> (<a href="/wiki/User_talk:DTDummyUserAlice" title="User talk:DTDummyUserAlice">talk</a>) 14:30, 10 March 2022 (UTC)<span class="ext-discussiontools-init-replylink-buttons" data-mw-thread-id="c-DTDummyUserAlice-2022-03-10T14:30:00.000Z-Archived_section"><span class="ext-discussiontools-init-replybutton oo-ui-widget oo-ui-widget-enabled oo-ui-buttonElement oo-ui-buttonElement-frameless oo-ui-iconElement oo-ui-labelElement oo-ui-flaggedElement-progressive oo-ui-buttonWidget" data-ooui='{"_":"OO.ui.ButtonWidget","rel":["nofollow"],"framed":false,"icon":"share","label":"(discussiontools-replybutton)","flags":["progressive"],"classes":["ext-discussiontools-init-replybutton"]}'><a role="button" tabindex="0" rel="nofollow" class="oo-ui-buttonElement-button"><span class="oo-ui-iconElement-icon oo-ui-icon-share oo-ui-image-progressive"></span><span class="oo-ui-labelElement-label">(discussiontools-replybutton)</span><span class="oo-ui-indicatorElement-indicator oo-ui-indicatorElement-noIndicator oo-ui-image-progressive"></span></a></span><span class="ext-discussiontools-init-replylink-bracket">[</span><a class="ext-discussiontools-init-replylink-reply" role="button" tabindex="0" href="">(discussiontools-replylink)</a><span class="ext-discussiontools-init-replylink-bracket">]</span></span><span data-mw-comment-end="c-DTDummyUserAlice-2022-03-10T14:30:00.000Z-Archived_section"></span>
@ -34,6 +40,14 @@ newestComment: {
hasLedeContent
{
"wgDiscussionToolsPageThreads": [
{
"headingLevel": 2,
"name": "h-",
"type": "heading",
"level": 0,
"id": "h-No_talk_section",
"replies": []
},
{
"headingLevel": 2,
"name": "h-DTDummyUserAlice-2022-03-10T14:30:00.000Z",

View file

@ -1,4 +1,10 @@
<div class="mw-parser-output">
<h2><span class="mw-headline" id="No_talk_section">No talk section</span></h2>
<div class="mw-notalk">
<ul><li>Vote 1. <a href="/wiki/User:DTDummyUserAlice" title="User:DTDummyUserAlice">DTDummyUserAlice</a> (<a href="/wiki/User_talk:DTDummyUserAlice" title="User talk:DTDummyUserAlice">talk</a>) 13:30, 10 March 2022 (UTC)</li>
<li>Vote 2. <a href="/wiki/User:DTDummyUserBob" title="User:DTDummyUserBob">DTDummyUserBob</a> (<a href="/wiki/User_talk:DTDummyUserBob" title="User talk:DTDummyUserBob">talk</a>) 13:40, 10 March 2022 (UTC)</li>
<li>Vote 3. <a href="/wiki/User:DTDummyUserEve" title="User:DTDummyUserEve">DTDummyUserEve</a> (<a href="/wiki/User_talk:DTDummyUserEve" title="User talk:DTDummyUserEve">talk</a>) 13:50, 10 March 2022 (UTC)</li></ul>
</div>
<div class="mw-archivedtalk" style="background: lightblue; padding: 20px; border: 1px solid blue;">
<h2><span class="mw-headline" id="Archived_section">Archived section</span></h2>
<p>Comment 1. <a href="/wiki/User:DTDummyUserAlice" title="User:DTDummyUserAlice">DTDummyUserAlice</a> (<a href="/wiki/User_talk:DTDummyUserAlice" title="User talk:DTDummyUserAlice">talk</a>) 14:30, 10 March 2022 (UTC)

View file

@ -3,8 +3,22 @@
"placeholderHeading": false,
"type": "heading",
"range": [
"1/1/0/0",
"1/1/0/1"
"1/0/0",
"1/0/1"
],
"headingLevel": 2,
"level": 0,
"name": "h-",
"id": "h-No_talk_section",
"warnings": [],
"replies": []
},
{
"placeholderHeading": false,
"type": "heading",
"range": [
"5/1/0/0",
"5/1/0/1"
],
"headingLevel": 2,
"level": 0,
@ -17,19 +31,19 @@
"timestamp": "2022-03-10T14:30:00.000Z",
"author": "DTDummyUserAlice",
"range": [
"1/3/0",
"1/3/4/28"
"5/3/0",
"5/3/4/28"
],
"signatureRanges": [
[
"1/3/1",
"1/3/4/28"
"5/3/1",
"5/3/4/28"
]
],
"timestampRanges": [
[
"1/3/4/2",
"1/3/4/28"
"5/3/4/2",
"5/3/4/28"
]
],
"level": 1,
@ -42,19 +56,19 @@
"timestamp": "2022-03-10T14:40:00.000Z",
"author": "DTDummyUserBob",
"range": [
"1/5/0/0",
"1/5/0/4/28"
"5/5/0/0",
"5/5/0/4/28"
],
"signatureRanges": [
[
"1/5/0/1",
"1/5/0/4/28"
"5/5/0/1",
"5/5/0/4/28"
]
],
"timestampRanges": [
[
"1/5/0/4/2",
"1/5/0/4/28"
"5/5/0/4/2",
"5/5/0/4/28"
]
],
"level": 2,
@ -67,19 +81,19 @@
"timestamp": "2022-03-10T14:50:00.000Z",
"author": "DTDummyUserEve",
"range": [
"1/5/0/5/0/0",
"1/5/0/5/0/4/28"
"5/5/0/5/0/0",
"5/5/0/5/0/4/28"
],
"signatureRanges": [
[
"1/5/0/5/0/1",
"1/5/0/5/0/4/28"
"5/5/0/5/0/1",
"5/5/0/5/0/4/28"
]
],
"timestampRanges": [
[
"1/5/0/5/0/4/2",
"1/5/0/5/0/4/28"
"5/5/0/5/0/4/2",
"5/5/0/5/0/4/28"
]
],
"level": 3,
@ -98,8 +112,8 @@
"placeholderHeading": false,
"type": "heading",
"range": [
"3/0/0",
"3/0/1"
"7/0/0",
"7/0/1"
],
"headingLevel": 2,
"level": 0,
@ -112,19 +126,19 @@
"timestamp": "2022-03-10T15:30:00.000Z",
"author": "DTDummyUserAlice",
"range": [
"5/0",
"5/4/28"
"9/0",
"9/4/28"
],
"signatureRanges": [
[
"5/1",
"5/4/28"
"9/1",
"9/4/28"
]
],
"timestampRanges": [
[
"5/4/2",
"5/4/28"
"9/4/2",
"9/4/28"
]
],
"level": 1,
@ -137,19 +151,19 @@
"timestamp": "2022-03-10T15:40:00.000Z",
"author": "DTDummyUserBob",
"range": [
"7/0/0",
"7/0/4/28"
"11/0/0",
"11/0/4/28"
],
"signatureRanges": [
[
"7/0/1",
"7/0/4/28"
"11/0/1",
"11/0/4/28"
]
],
"timestampRanges": [
[
"7/0/4/2",
"7/0/4/28"
"11/0/4/2",
"11/0/4/28"
]
],
"level": 2,
@ -162,19 +176,19 @@
"timestamp": "2022-03-10T15:50:00.000Z",
"author": "DTDummyUserEve",
"range": [
"7/0/5/0/0",
"7/0/5/0/4/28"
"11/0/5/0/0",
"11/0/5/0/4/28"
],
"signatureRanges": [
[
"7/0/5/0/1",
"7/0/5/0/4/28"
"11/0/5/0/1",
"11/0/5/0/4/28"
]
],
"timestampRanges": [
[
"7/0/5/0/4/2",
"7/0/5/0/4/28"
"11/0/5/0/4/2",
"11/0/5/0/4/28"
]
],
"level": 3,