From 7da70855feb89404577e93d23d0da0da3f24d3b0 Mon Sep 17 00:00:00 2001 From: Fomafix Date: Sun, 12 Nov 2017 20:56:44 +0100 Subject: [PATCH] Let Html::element do the HTML encoding Also inline variables used once and move the htmlspecialchars to the self::link call. Change-Id: I6d9063af3f4ff0a6d70f3ebbce8362122d5bb06a --- includes/Linker.php | 28 +++++++++++++++------------- tests/parser/parserTests.txt | 6 +++--- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/includes/Linker.php b/includes/Linker.php index db3e2f5f03..f4be32642a 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -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 '' . - $encLabel . ''; + 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' ] + ); } /** diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt index 7efa8e332e..3728b9a507 100644 --- a/tests/parser/parserTests.txt +++ b/tests/parser/parserTests.txt @@ -8073,7 +8073,7 @@ File containing double quotes and spaces !! wikitext [[File:Cool "Gator".png]] !! html/php+tidy -

File:Cool "Gator".png +

File:Cool "Gator".png

!! html/parsoid

File:Cool "Gator".png

@@ -8150,8 +8150,8 @@ Broken image links with HTML captions (T41700) [[File:Nonexistent|<]] [[File:Nonexistent|abc]] !! html/php -

<script></script> -<script></script> +

<script></script> +<script></script> < abc

-- 2.20.1