Apply rgcjones' patch for Bug#29533:
authorMark A. Hershberger <mah@users.mediawiki.org>
Sun, 26 Jun 2011 19:52:11 +0000 (19:52 +0000)
committerMark A. Hershberger <mah@users.mediawiki.org>
Sun, 26 Jun 2011 19:52:11 +0000 (19:52 +0000)
    Whe placing an external link in the sidebar, $wgExternalLinkTarget is ignored.
    Also enables applying of $wgNoFollowLinks in the sidebar.

CREDITS
includes/Skin.php
includes/SkinTemplate.php

diff --git a/CREDITS b/CREDITS
index 8a6e199..8bc7a26 100644 (file)
--- 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
index 64bfa95..fda64b6 100644 (file)
@@ -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;
 
index 213d700..598dc13 100644 (file)
@@ -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];
                                }