CommentParser: Ignore generated timestamp links

This will be present in parser cache output and can
sometimes be mistaken for user page links.

Bug: T356142
Change-Id: I800b23d8466f72affcadfa336aab07abf7f8d79e
(cherry picked from commit 8069585489)
This commit is contained in:
Ed Sanders 2024-01-30 10:28:36 +00:00 committed by Bartosz Dziewoński
parent 94a5c86ceb
commit 7c8060669d
2 changed files with 31 additions and 24 deletions

View file

@ -666,21 +666,26 @@ class CommentParser {
//
// Handle links nested in formatting elements.
if ( $event === 'leave' && $node instanceof Element && strtolower( $node->tagName ) === 'a' ) {
$user = $this->getUsernameFromLink( $node );
if ( $user ) {
// Accept the first link to the user namespace, then only accept links to that user
if ( $sigUsername === null ) {
$sigUsername = $user['username'];
}
if ( $user['username'] === $sigUsername ) {
$lastLinkNode = $node;
if ( $user['displayName'] ) {
$sigDisplayName = $user['displayName'];
$classList = DOMCompat::getClassList( $node );
// Generated timestamp links sometimes look like username links (e.g. on user talk pages)
// so ignore these.
if ( !$classList->contains( 'ext-discussiontools-init-timestamplink' ) ) {
$user = $this->getUsernameFromLink( $node );
if ( $user ) {
// Accept the first link to the user namespace, then only accept links to that user
if ( $sigUsername === null ) {
$sigUsername = $user['username'];
}
if ( $user['username'] === $sigUsername ) {
$lastLinkNode = $node;
if ( $user['displayName'] ) {
$sigDisplayName = $user['displayName'];
}
}
}
// Keep looking if a node with links wasn't a link to a user page
// "Doc James (talk · contribs · email)"
}
// Keep looking if a node with links wasn't a link to a user page
// "Doc James (talk · contribs · email)"
}
}
);

View file

@ -737,21 +737,23 @@ Parser.prototype.findSignature = function ( timestampNode, until ) {
//
// Handle links nested in formatting elements.
if ( event === 'leave' && node.nodeType === Node.ELEMENT_NODE && node.tagName.toLowerCase() === 'a' ) {
var user = parser.getUsernameFromLink( node );
if ( user ) {
// Accept the first link to the user namespace, then only accept links to that user
if ( sigUsername === null ) {
sigUsername = user.username;
}
if ( user.username === sigUsername ) {
lastLinkNode = node;
if ( user.displayName ) {
sigDisplayName = user.displayName;
if ( !node.classList.contains( 'ext-discussiontools-init-timestamplink' ) ) {
var user = parser.getUsernameFromLink( node );
if ( user ) {
// Accept the first link to the user namespace, then only accept links to that user
if ( sigUsername === null ) {
sigUsername = user.username;
}
if ( user.username === sigUsername ) {
lastLinkNode = node;
if ( user.displayName ) {
sigDisplayName = user.displayName;
}
}
}
// Keep looking if a node with links wasn't a link to a user page
// "Doc James (talk · contribs · email)"
}
// Keep looking if a node with links wasn't a link to a user page
// "Doc James (talk · contribs · email)"
}
}
);