From 1706d353ae33e3bf24ff631213c39914c5fdf621 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Sat, 1 Dec 2018 01:19:33 -0800 Subject: [PATCH] Don't link wikilinks in section heading autocomments Previously, a manually constructed autocomment in the form of /* [[Some link]] */ would create a link to the the section, and then the "Some link" page. After T165189 was implemented, the entire autocomment is now a link to the section, so we're creating links inside of a link...which is problematic. In most contexts (history and watchlist particularly), the section link is more important than the title in the section heading, so that's what we'll favor here. It's worth noting that this situation is a manually created edge case. Even if the section heading is a wikilink, the edit summary will autofill a section autocomment without the double brackets. We'll now render the double brackets ([[...]]) and not link them. This is what the user literally typed, and matches the existing practice of rendering templates in section headings with their literal syntax. And as a bonus, it's still possible for user scripts such as wikEdDiff to turn the rendered double brackets into a real link if users want. Bug: T165189 Change-Id: Ib10679edd76c72a60d7e1c89fc8454166e34c463 --- includes/Linker.php | 6 +++++- tests/parser/parserTests.txt | 20 ++++++++++++++++++++ tests/phpunit/includes/LinkerTest.php | 2 +- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/includes/Linker.php b/includes/Linker.php index e96d8d84af..2028197a49 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -1159,6 +1159,10 @@ class Linker { $section = str_replace( '[[', '', $section ); $section = str_replace( ']]', '', $section ); + // We don't want any links in the auto text to be linked, but we still + // want to show any [[ ]] + $sectionText = str_replace( '[[', '[[', $auto ); + $section = substr( Parser::guessSectionNameFromStrippedText( $section ), 1 ); if ( $local ) { $sectionTitle = Title::makeTitleSafe( NS_MAIN, '', $section ); @@ -1168,7 +1172,7 @@ class Linker { } if ( $sectionTitle ) { $auto = Linker::makeCommentLink( - $sectionTitle, $wgLang->getArrow() . $wgLang->getDirMark() . $auto, + $sectionTitle, $wgLang->getArrow() . $wgLang->getDirMark() . $sectionText, $wikiId, 'noclasses' ); } diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt index bbacfafc64..025ebc0dd7 100644 --- a/tests/parser/parserTests.txt +++ b/tests/parser/parserTests.txt @@ -24525,6 +24525,26 @@ comment local title=[[Main Page]] →‎External links: removed bogus entries !!end +!! test +Edit comment with section link that has a link in it +!! options +comment local title=[[Main Page]] +!! wikitext +/* [[A link]] */ +!! html/php +→‎[[A link]] +!! end + +!! test +Edit comment with section link that has a template in it +!! options +comment local title=[[Main Page]] +!! wikitext +/* {{foobar|param}} */ +!! html/php +→‎{{foobar|param}} +!! end + !! test Edit comment with subpage link (T16080) !! options diff --git a/tests/phpunit/includes/LinkerTest.php b/tests/phpunit/includes/LinkerTest.php index 1f8f4385e9..34e5593cfc 100644 --- a/tests/phpunit/includes/LinkerTest.php +++ b/tests/phpunit/includes/LinkerTest.php @@ -156,7 +156,7 @@ class LinkerTest extends MediaWikiLangTestCase { "/* autocomment */", ], [ - '→‎linkie?', + '→‎[[linkie?]]', "/* [[linkie?]] */", ], [ -- 2.20.1