mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-24 00:13:36 +00:00
Merge "CommentUtils: Fix isSingleCommentSignedBy() with empty heading"
This commit is contained in:
commit
d91fe7aad0
|
@ -724,13 +724,19 @@ class CommentUtils {
|
|||
$items = $itemSet->getThreadItems();
|
||||
|
||||
if ( $items ) {
|
||||
$lastItem = end( $items );
|
||||
// Check that we've detected a comment first, not just headings (T304377)
|
||||
if ( !( $lastItem instanceof CommentItem && $lastItem->getAuthor() === $author ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Range covering all of the detected items (to account for a heading, and for multiple
|
||||
// signatures resulting in multiple comments)
|
||||
$commentsRange = new ImmutableRange(
|
||||
$items[0]->getRange()->startContainer,
|
||||
$items[0]->getRange()->startOffset,
|
||||
end( $items )->getRange()->endContainer,
|
||||
end( $items )->getRange()->endOffset
|
||||
$lastItem->getRange()->endContainer,
|
||||
$lastItem->getRange()->endOffset
|
||||
);
|
||||
$bodyRange = new ImmutableRange(
|
||||
$rootNode, 0, $rootNode, count( $rootNode->childNodes )
|
||||
|
@ -738,12 +744,9 @@ class CommentUtils {
|
|||
|
||||
if ( self::compareRanges( $commentsRange, $bodyRange ) === 'equal' ) {
|
||||
// New comment includes a signature in the proper place
|
||||
$lastComment = end( $items );
|
||||
if ( $lastComment instanceof CommentItem && $lastComment->getAuthor() === $author ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,13 @@
|
|||
"html": "<h2><span class=\"mw-headline\" id=\"Foo\">Foo</span></h2>\n<p>bar\n</p>",
|
||||
"expected": false
|
||||
},
|
||||
{
|
||||
"msg": "Simple message [with empty heading]",
|
||||
"title": "Talk:A",
|
||||
"user": "X",
|
||||
"html": "<h2><span class=\"mw-headline\" id=\"\"></span></h2>\n<p>bar\n</p>",
|
||||
"expected": false
|
||||
},
|
||||
{
|
||||
"msg": "Simple message [indented]",
|
||||
"title": "Talk:A",
|
||||
|
|
Loading…
Reference in a new issue