Don't link wikilinks in section heading autocomments
authorKunal Mehta <legoktm@member.fsf.org>
Sat, 1 Dec 2018 09:19:33 +0000 (01:19 -0800)
committerKunal Mehta <legoktm@member.fsf.org>
Mon, 3 Dec 2018 20:43:03 +0000 (12:43 -0800)
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
tests/parser/parserTests.txt
tests/phpunit/includes/LinkerTest.php

index e96d8d8..2028197 100644 (file)
@@ -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( '[[', '&#91;[', $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'
                                                        );
                                                }
index bbacfaf..025ebc0 100644 (file)
@@ -24525,6 +24525,26 @@ comment local title=[[Main Page]]
 <span dir="auto"><span class="autocomment"><a href="#External_links">→‎External links</a>: </span> removed bogus entries</span>
 !!end
 
+!! test
+Edit comment with section link that has a link in it
+!! options
+comment local title=[[Main Page]]
+!! wikitext
+/* [[A link]] */
+!! html/php
+<span dir="auto"><span class="autocomment"><a href="#A_link">→‎&#91;[A link]]</a></span></span>
+!! end
+
+!! test
+Edit comment with section link that has a template in it
+!! options
+comment local title=[[Main Page]]
+!! wikitext
+/* {{foobar|param}} */
+!! html/php
+<span dir="auto"><span class="autocomment"><a href="#.7B.7Bfoobar.7Cparam.7D.7D">→‎{{foobar|param}}</a></span></span>
+!! end
+
 !! test
 Edit comment with subpage link (T16080)
 !! options
index 1f8f438..34e5593 100644 (file)
@@ -156,7 +156,7 @@ class LinkerTest extends MediaWikiLangTestCase {
                                "/* autocomment */",
                        ],
                        [
-                               '<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#linkie.3F" title="Special:BlankPage">→‎<a href="/wiki/index.php?title=Linkie%3F&amp;action=edit&amp;redlink=1" class="new" title="Linkie? (page does not exist)">linkie?</a></a></span></span>',
+                               '<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#linkie.3F" title="Special:BlankPage">→‎&#91;[linkie?]]</a></span></span>',
                                "/* [[linkie?]] */",
                        ],
                        [