From c2df4ae2d94ea390754e878b6963fc5f10b7579e Mon Sep 17 00:00:00 2001 From: "Mark A. Hershberger" Date: Sun, 26 Jun 2011 19:52:11 +0000 Subject: [PATCH] Apply rgcjones' patch for Bug#29533: Whe placing an external link in the sidebar, $wgExternalLinkTarget is ignored. Also enables applying of $wgNoFollowLinks in the sidebar. --- CREDITS | 1 + includes/Skin.php | 27 +++++++++++++++++++++++++-- includes/SkinTemplate.php | 4 ++-- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/CREDITS b/CREDITS index 8a6e199704..8bc7a26424 100644 --- a/CREDITS +++ b/CREDITS @@ -136,6 +136,7 @@ following names for their contribution to the product. * PieRRoMaN * quietust * René Kijewski +* rgcjonas * Robert Treat * RockMFR * Salvatore Ingala diff --git a/includes/Skin.php b/includes/Skin.php index 64bfa95600..fda64b6df3 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -1253,6 +1253,7 @@ abstract class Skin { if ( strpos( $line, '|' ) !== false ) { // sanity check $line = MessageCache::singleton()->transform( $line, false, null, $this->getTitle() ); $line = array_map( 'trim', explode( '|', $line, 2 ) ); + $extraAttribs = array(); $msgLink = wfMessage( $line[0] )->inContentLanguage(); if ( $msgLink->exists() ) { @@ -1273,6 +1274,28 @@ abstract class Skin { if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) { $href = $link; + //Parser::getExternalLinkAttribs won't work here because of the Namespace things + global $wgNoFollowLinks; + if ( $wgNoFollowLinks ) { + $extraAttribs['rel'] = 'nofollow'; + + global $wgNoFollowDomainExceptions; + if ( $wgNoFollowDomainExceptions ) { + $bits = wfParseUrl( $url ); + if ( is_array( $bits ) && isset( $bits['host'] ) ) { + foreach ( $wgNoFollowDomainExceptions as $domain ) { + if ( substr( $bits['host'], -strlen( $domain ) ) == $domain ) { + unset( $extraAttribs['rel'] ); + break; + } + } + } + } + } + global $wgExternalLinkTarget; + if ( $wgExternalLinkTarget) { + $extraAttribs['target'] = $wgExternalLinkTarget; + } } else { $title = Title::newFromText( $link ); @@ -1284,12 +1307,12 @@ abstract class Skin { } } - $bar[$heading][] = array( + $bar[$heading][] = array_merge( array( 'text' => $text, 'href' => $href, 'id' => 'n-' . strtr( $line[1], ' ', '-' ), 'active' => false - ); + ), $extraAttribs ); } elseif ( ( substr( $line, 0, 2 ) == '{{' ) && ( substr( $line, -2 ) == '}}' ) ) { global $wgParser; diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index 213d7008cb..598dc1354c 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -1576,7 +1576,7 @@ abstract class BaseTemplate extends QuickTemplate { } $attrs = array(); - foreach ( array( 'href', 'id', 'class', 'rel', 'type' ) as $attr ) { + foreach ( array( 'href', 'id', 'class', 'rel', 'type', 'target') as $attr ) { if ( isset( $item[$attr] ) ) { $attrs[$attr] = $item[$attr]; } @@ -1629,7 +1629,7 @@ abstract class BaseTemplate extends QuickTemplate { } } else { $link = array(); - foreach ( array( 'text', 'msg', 'href', 'rel', 'type', 'tooltiponly' ) as $k ) { + foreach ( array( 'text', 'msg', 'href', 'rel', 'type', 'tooltiponly', 'target' ) as $k ) { if ( isset( $item[$k] ) ) { $link[$k] = $item[$k]; } -- 2.20.1