Use `class="free external"` only on unbracketed URLs
authorC. Scott Ananian <cscott@cscott.net>
Wed, 28 Feb 2018 21:11:09 +0000 (16:11 -0500)
committerC. Scott Ananian <cscott@cscott.net>
Wed, 7 Mar 2018 05:20:09 +0000 (00:20 -0500)
The ability for URLs to be marked free even if they use bracketed syntax
but "sorta look free" (aka unbracketed) was added 13 years ago in
2d71cb30802e5cb78a423a1699ad87e23bfe9f4e (r7074).

It seemed like a reasonable idea at the time: make printed output a little
prettier by marking "sorta free" URLs as free.  But this complicates the
semantics of wikitext, and introduces all sorts of strange corner cases,
for example:

  [http://example.com/&amp; http://example.com/&]

isn't marked as free, even though the parser output is:

  <a rel="nofollow" class="external text" href="http://example.com/&amp;">http://example.com/&amp;</a>

This functionality isn't actually needed: if you want the pretty printed
output of an unbracketed URL, then actually use an unbracketed URL.

In recent years we're more concerned with simplifying the semantics of
wikitext and eliminating corner cases, such that the content of our wikis
can be effectively archived.  The "effectively free" URLs are low-hanging
fruit in this quest.

Change-Id: I339e8698786c60c96a37a73443cb9a04362662c4

RELEASE-NOTES-1.31
includes/parser/Parser.php
tests/parser/parserTests.txt

index 83669e6..718ada9 100644 (file)
@@ -285,6 +285,8 @@ changes to languages because of Phabricator reports.
   * Parser::isValidHalfParsedText()
   * StripState::getSubState()
   * StripState::merge()
+* The "free" class is now only applied to unbracketed URLs in wikitext. Links
+  written using square brackets will get the class "text" not "free".
 
 == Compatibility ==
 MediaWiki 1.31 requires PHP 5.5.9 or later. Although HHVM 3.18.5 or later is supported,
index 8e5dcbd..9458728 100644 (file)
@@ -1868,8 +1868,8 @@ class Parser {
 
                        $dtrail = '';
 
-                       # Set linktype for CSS - if URL==text, link is essentially free
-                       $linktype = ( $text === $url ) ? 'free' : 'text';
+                       # Set linktype for CSS
+                       $linktype = 'text';
 
                        # No link text, e.g. [http://domain.tld/some.link]
                        if ( $text == '' ) {
index 6da23e1..f98044b 100644 (file)
@@ -4937,7 +4937,7 @@ parsoid=wt2html
 !! wikitext
 URL in text: [http://example.com http://example.com]
 !! html/php
-<p>URL in text: <a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>
+<p>URL in text: <a rel="nofollow" class="external text" href="http://example.com">http://example.com</a>
 </p>
 !! html/parsoid
 <p>URL in text: <a rel="mw:ExtLink" class="external free" href="http://example.com">http://example.com</a></p>
@@ -22532,8 +22532,8 @@ gopher://www.google.com
 !! html/php
 <p><a rel="nofollow" class="external free" href="http://www.google.com">http://www.google.com</a>
 <a rel="nofollow" class="external free" href="gopher://www.google.com">gopher://www.google.com</a>
-<a rel="nofollow" class="external free" href="http://www.google.com">http://www.google.com</a>
-<a rel="nofollow" class="external free" href="gopher://www.google.com">gopher://www.google.com</a>
+<a rel="nofollow" class="external text" href="http://www.google.com">http://www.google.com</a>
+<a rel="nofollow" class="external text" href="gopher://www.google.com">gopher://www.google.com</a>
 <a rel="nofollow" class="external text" href="https://www.google.com">irc://www.google.com</a>
 <a rel="nofollow" class="external text" href="ftp://www.google.com">www.гоогле.цом/фтп://дир</a>
 <a rel="nofollow" class="external text" href="//www.google.com">www.гоогле.цом</a>