From a92e7fb58bee5e8c0fc05692a94255b7566aaf37 Mon Sep 17 00:00:00 2001 From: Marius Hoch Date: Wed, 5 Dec 2012 21:09:14 +0100 Subject: [PATCH] Links created by Linker::makeExternalLink didn't include rel=nofollow The links created by Linker::makeExternalLink didn't obey $wgNoFollowLinks (and $wgNoFollowNsExceptions, $wgNoFollowDomainExceptions). To fix this I made the function call Parser::getExternalLinkRel which I implemented earlier. Fixes bug 41983. Change-Id: I2ff35f89502db2e1f8266f3a943e38c0ea67aced --- includes/Linker.php | 9 ++++++++- tests/parser/parserTests.txt | 10 +++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/includes/Linker.php b/includes/Linker.php index 408538b7d2..76f6b81610 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -1038,9 +1038,11 @@ class Linker { * @param $escape Boolean: do we escape the link text? * @param $linktype String: type of external link. Gets added to the classes * @param $attribs Array of extra attributes to + * @param $title Title|null Title object used for title specific link attributes * @return string */ - public static function makeExternalLink( $url, $text, $escape = true, $linktype = '', $attribs = array() ) { + public static function makeExternalLink( $url, $text, $escape = true, $linktype = '', $attribs = array(), $title = null ) { + global $wgTitle; $class = "external"; if ( $linktype ) { $class .= " $linktype"; @@ -1053,6 +1055,11 @@ class Linker { if ( $escape ) { $text = htmlspecialchars( $text ); } + + if ( !$title ) { + $title = $wgTitle; + } + $attribs['rel'] = Parser::getExternalLinkRel( $url, $title ); $link = ''; $success = wfRunHooks( 'LinkerMakeExternalLink', array( &$url, &$text, &$link, &$attribs, $linktype ) ); diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt index 652fa43e39..0e6e83e3f9 100644 --- a/tests/parser/parserTests.txt +++ b/tests/parser/parserTests.txt @@ -4530,7 +4530,7 @@ Magic links: RFC (bug 479) !! input RFC 822 !! result -

RFC 822 +

RFC 822

!! end @@ -4548,7 +4548,7 @@ Magic links: PMID incorrectly converts space to underscore !! input PMID 1234 !! result -

PMID 1234 +

PMID 1234

!! end @@ -6665,7 +6665,7 @@ BUG 1887: A RFC with a thumbnail !! input [[Image:foobar.jpg|thumb|This is RFC 12354]] !! result -
This is RFC 12354
+
This is RFC 12354
!! end @@ -10250,7 +10250,7 @@ Double RFC !! input RFC RFC 1234 !! result -

RFC RFC 1234 +

RFC RFC 1234

!! end @@ -10268,7 +10268,7 @@ RFC code coverage !! input RFC 983 987 !! result -

RFC 983 987 +

RFC 983 987

!! end -- 2.20.1