r90849 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90848‎ | r90849 | r90850 >
Date:19:52, 26 June 2011
Author:mah
Status:resolved (Comments)
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/CREDITS (modified) (history)
  • /trunk/phase3/includes/Skin.php (modified) (history)
  • /trunk/phase3/includes/SkinTemplate.php (modified) (history)

Diff [purge]

Index: trunk/phase3/CREDITS
@@ -136,6 +136,7 @@
137137 * PieRRoMaN
138138 * quietust
139139 * René Kijewski
 140+* rgcjonas
140141 * Robert Treat
141142 * RockMFR
142143 * Salvatore Ingala
Index: trunk/phase3/includes/SkinTemplate.php
@@ -1576,7 +1576,7 @@
15771577 }
15781578
15791579 $attrs = array();
1580 - foreach ( array( 'href', 'id', 'class', 'rel', 'type' ) as $attr ) {
 1580+ foreach ( array( 'href', 'id', 'class', 'rel', 'type', 'target') as $attr ) {
15811581 if ( isset( $item[$attr] ) ) {
15821582 $attrs[$attr] = $item[$attr];
15831583 }
@@ -1629,7 +1629,7 @@
16301630 }
16311631 } else {
16321632 $link = array();
1633 - foreach ( array( 'text', 'msg', 'href', 'rel', 'type', 'tooltiponly' ) as $k ) {
 1633+ foreach ( array( 'text', 'msg', 'href', 'rel', 'type', 'tooltiponly', 'target' ) as $k ) {
16341634 if ( isset( $item[$k] ) ) {
16351635 $link[$k] = $item[$k];
16361636 }
Index: trunk/phase3/includes/Skin.php
@@ -1253,6 +1253,7 @@
12541254 if ( strpos( $line, '|' ) !== false ) { // sanity check
12551255 $line = MessageCache::singleton()->transform( $line, false, null, $this->getTitle() );
12561256 $line = array_map( 'trim', explode( '|', $line, 2 ) );
 1257+ $extraAttribs = array();
12571258
12581259 $msgLink = wfMessage( $line[0] )->inContentLanguage();
12591260 if ( $msgLink->exists() ) {
@@ -1273,6 +1274,28 @@
12741275
12751276 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
12761277 $href = $link;
 1278+ //Parser::getExternalLinkAttribs won't work here because of the Namespace things
 1279+ global $wgNoFollowLinks;
 1280+ if ( $wgNoFollowLinks ) {
 1281+ $extraAttribs['rel'] = 'nofollow';
 1282+
 1283+ global $wgNoFollowDomainExceptions;
 1284+ if ( $wgNoFollowDomainExceptions ) {
 1285+ $bits = wfParseUrl( $url );
 1286+ if ( is_array( $bits ) && isset( $bits['host'] ) ) {
 1287+ foreach ( $wgNoFollowDomainExceptions as $domain ) {
 1288+ if ( substr( $bits['host'], -strlen( $domain ) ) == $domain ) {
 1289+ unset( $extraAttribs['rel'] );
 1290+ break;
 1291+ }
 1292+ }
 1293+ }
 1294+ }
 1295+ }
 1296+ global $wgExternalLinkTarget;
 1297+ if ( $wgExternalLinkTarget) {
 1298+ $extraAttribs['target'] = $wgExternalLinkTarget;
 1299+ }
12771300 } else {
12781301 $title = Title::newFromText( $link );
12791302
@@ -1284,12 +1307,12 @@
12851308 }
12861309 }
12871310
1288 - $bar[$heading][] = array(
 1311+ $bar[$heading][] = array_merge( array(
12891312 'text' => $text,
12901313 'href' => $href,
12911314 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
12921315 'active' => false
1293 - );
 1316+ ), $extraAttribs );
12941317 } elseif ( ( substr( $line, 0, 2 ) == '{{' ) && ( substr( $line, -2 ) == '}}' ) ) {
12951318 global $wgParser;
12961319

Follow-up revisions

RevisionCommit summaryAuthorDate
r95072Per r90849, factor out most of the code that's duplicated between Parser::get...catrope10:18, 20 August 2011
r95073Fix serious bug in r90849 that didn't show up in the tests until I restructur...catrope10:25, 20 August 2011
r95632MFT to REL1_18...hashar17:57, 28 August 2011

Comments

#Comment by Hashar (talk | contribs)   09:32, 13 August 2011

That patch introduces code duplication :(

The part that check for $wgNoFollowLinks is copy/pasted from Parser::getExternalLinkAttribs(). Although altered to not look at the Title namespace, probably because we do not have a valid Title object in the context of the sidebar.

#Comment by Catrope (talk | contribs)   10:18, 20 August 2011

Code duplication fixed in r95072.

Status & tagging log