Let Html::element do the HTML encoding
authorFomafix <fomafix@googlemail.com>
Sun, 12 Nov 2017 19:56:44 +0000 (20:56 +0100)
committerFomafix <fomafix@googlemail.com>
Wed, 7 Aug 2019 21:51:41 +0000 (23:51 +0200)
Also inline variables used once and move the htmlspecialchars to the
self::link call.

Change-Id: I6d9063af3f4ff0a6d70f3ebbce8362122d5bb06a

includes/Linker.php
tests/parser/parserTests.txt

index db3e2f5..f4be326 100644 (file)
@@ -688,35 +688,37 @@ class Linker {
                if ( $label == '' ) {
                        $label = $title->getPrefixedText();
                }
-               $encLabel = htmlspecialchars( $label );
                $currentExists = $time
                        && MediaWikiServices::getInstance()->getRepoGroup()->findFile( $title ) !== false;
 
                if ( ( $wgUploadMissingFileUrl || $wgUploadNavigationUrl || $wgEnableUploads )
                        && !$currentExists
                ) {
-                       $redir = RepoGroup::singleton()->getLocalRepo()->checkRedirect( $title );
-
-                       if ( $redir ) {
-                               // We already know it's a redirect, so mark it
-                               // accordingly
+                       if ( RepoGroup::singleton()->getLocalRepo()->checkRedirect( $title ) ) {
+                               // We already know it's a redirect, so mark it accordingly
                                return self::link(
                                        $title,
-                                       $encLabel,
+                                       htmlspecialchars( $label ),
                                        [ 'class' => 'mw-redirect' ],
                                        wfCgiToArray( $query ),
                                        [ 'known', 'noclasses' ]
                                );
                        }
 
-                       $href = self::getUploadUrl( $title, $query );
-
-                       return '<a href="' . htmlspecialchars( $href ) . '" class="new" title="' .
-                               htmlspecialchars( $title->getPrefixedText(), ENT_QUOTES ) . '">' .
-                               $encLabel . '</a>';
+                       return Html::element( 'a', [
+                                       'href' => self::getUploadUrl( $title, $query ),
+                                       'class' => 'new',
+                                       'title' => $title->getPrefixedText()
+                               ], $label );
                }
 
-               return self::link( $title, $encLabel, [], wfCgiToArray( $query ), [ 'known', 'noclasses' ] );
+               return self::link(
+                       $title,
+                       htmlspecialchars( $label ),
+                       [],
+                       wfCgiToArray( $query ),
+                       [ 'known', 'noclasses' ]
+               );
        }
 
        /**
index 7efa8e3..3728b9a 100644 (file)
@@ -8073,7 +8073,7 @@ File containing double quotes and spaces
 !! wikitext
 [[File:Cool "Gator".png]]
 !! html/php+tidy
-<p><a href="/index.php?title=Special:Upload&amp;wpDestFile=Cool_%22Gator%22.png" class="new" title="File:Cool &quot;Gator&quot;.png">File:Cool &quot;Gator&quot;.png</a>
+<p><a href="/index.php?title=Special:Upload&amp;wpDestFile=Cool_%22Gator%22.png" class="new" title="File:Cool &quot;Gator&quot;.png">File:Cool "Gator".png</a>
 </p>
 !! html/parsoid
 <p><figure-inline class="mw-default-size" typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"apierror-filedoesnotexist","message":"This image does not exist."}]}'><a href="./Special:FilePath/Cool_%22Gator%22.png"><span resource='./File:Cool_"Gator".png' data-parsoid='{"a":{"resource":"./File:Cool_\"Gator\".png"},"sa":{"resource":"File:Cool \"Gator\".png"}}'>File:Cool "Gator".png</span></a></figure-inline></p>
@@ -8150,8 +8150,8 @@ Broken image links with HTML captions (T41700)
 [[File:Nonexistent|&lt;]]
 [[File:Nonexistent|a<i>b</i>c]]
 !! html/php
-<p><a href="/index.php?title=Special:Upload&amp;wpDestFile=Nonexistent" class="new" title="File:Nonexistent">&lt;script&gt;&lt;/script&gt;</a>
-<a href="/index.php?title=Special:Upload&amp;wpDestFile=Nonexistent" class="new" title="File:Nonexistent">&lt;script&gt;&lt;/script&gt;</a>
+<p><a href="/index.php?title=Special:Upload&amp;wpDestFile=Nonexistent" class="new" title="File:Nonexistent">&lt;script>&lt;/script></a>
+<a href="/index.php?title=Special:Upload&amp;wpDestFile=Nonexistent" class="new" title="File:Nonexistent">&lt;script>&lt;/script></a>
 <a href="/index.php?title=Special:Upload&amp;wpDestFile=Nonexistent" class="new" title="File:Nonexistent">&lt;</a>
 <a href="/index.php?title=Special:Upload&amp;wpDestFile=Nonexistent" class="new" title="File:Nonexistent">abc</a>
 </p>