r41409 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41408‎ | r41409 | r41410 >
Date:01:00, 30 September 2008
Author:tstarling
Status:old
Tags:
Comment:
Revert revert r41406 of r41333, and removed one space between attributes.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/Linker.php (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/includes/parser/ParserOptions.php (modified) (history)
  • /trunk/phase3/includes/parser/Parser_OldPP.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/ParserOptions.php
@@ -30,6 +30,7 @@
3131 var $mTemplateCallback; # Callback for template fetching
3232 var $mEnableLimitReport; # Enable limit report in an HTML comment on output
3333 var $mTimestamp; # Timestamp used for {{CURRENTDAY}} etc.
 34+ var $mExternalLinkTarget; # Target attribute for external links
3435
3536 var $mUser; # Stored user object, just used to initialise the skin
3637
@@ -52,6 +53,7 @@
5354 function getTemplateCallback() { return $this->mTemplateCallback; }
5455 function getEnableLimitReport() { return $this->mEnableLimitReport; }
5556 function getCleanSignatures() { return $this->mCleanSignatures; }
 57+ function getExternalLinkTarget() { return $this->mExternalLinkTarget; }
5658
5759 function getSkin() {
5860 if ( !isset( $this->mSkin ) ) {
@@ -96,6 +98,7 @@
9799 function enableLimitReport( $x = true ) { return wfSetVar( $this->mEnableLimitReport, $x ); }
98100 function setTimestamp( $x ) { return wfSetVar( $this->mTimestamp, $x ); }
99101 function setCleanSignatures( $x ) { return wfSetVar( $this->mCleanSignatures, $x ); }
 102+ function setExternalLinkTarget( $x ) { return wfSetVar( $this->mExternalLinkTarget, $x ); }
100103
101104 function __construct( $user = null ) {
102105 $this->initialiseFromUser( $user );
@@ -114,6 +117,7 @@
115118 global $wgUseTeX, $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages;
116119 global $wgAllowExternalImagesFrom, $wgEnableImageWhitelist, $wgAllowSpecialInclusion, $wgMaxArticleSize;
117120 global $wgMaxPPNodeCount, $wgMaxTemplateDepth, $wgMaxPPExpandDepth, $wgCleanSignatures;
 121+ global $wgExternalLinkTarget;
118122 $fname = 'ParserOptions::initialiseFromUser';
119123 wfProfileIn( $fname );
120124 if ( !$userInput ) {
@@ -151,6 +155,7 @@
152156 $this->mTemplateCallback = array( 'Parser', 'statelessFetchTemplate' );
153157 $this->mEnableLimitReport = false;
154158 $this->mCleanSignatures = $wgCleanSignatures;
 159+ $this->mExternalLinkTarget = $wgExternalLinkTarget;
155160 wfProfileOut( $fname );
156161 }
157162 }
Index: trunk/phase3/includes/parser/Parser_OldPP.php
@@ -1353,7 +1353,7 @@
13541354 # This means that users can paste URLs directly into the text
13551355 # Funny characters like ö aren't valid in URLs anyway
13561356 # This was changed in August 2004
1357 - $s .= $sk->makeExternalLink( $url, $text, false, $linktype, $this->mTitle->getNamespace() ) . $dtrail . $trail;
 1357+ $s .= $sk->makeExternalLink( $url, $text, false, $linktype, $this->getExternalLinkAttribs() ) . $dtrail . $trail;
13581358
13591359 # Register link in the output object.
13601360 # Replace unnecessary URL escape codes with the referenced character
@@ -1366,6 +1366,19 @@
13671367 return $s;
13681368 }
13691369
 1370+ function getExternalLinkAttribs() {
 1371+ $attribs = array();
 1372+ global $wgNoFollowLinks, $wgNoFollowNsExceptions;
 1373+ $ns = $this->mTitle->getNamespace();
 1374+ if( $wgNoFollowLinks && !in_array($ns, $wgNoFollowNsExceptions) ) {
 1375+ $attribs['rel'] = 'nofollow';
 1376+ }
 1377+ if ( $this->mOptions->getExternalLinkTarget() ) {
 1378+ $attribs['target'] = $this->mOptions->getExternalLinkTarget();
 1379+ }
 1380+ return $attribs;
 1381+ }
 1382+
13701383 /**
13711384 * Replace anything that looks like a URL with a link
13721385 * @private
@@ -1432,7 +1445,8 @@
14331446 $text = $this->maybeMakeExternalImage( $url );
14341447 if ( $text === false ) {
14351448 # Not an image, make a link
1436 - $text = $sk->makeExternalLink( $url, $wgContLang->markNoConversion($url), true, 'free', $this->mTitle->getNamespace() );
 1449+ $text = $sk->makeExternalLink( $url, $wgContLang->markNoConversion($url), true, 'free',
 1450+ $this->getExternalLinkAttribs() );
14371451 # Register it in the output object...
14381452 # Replace unnecessary URL escape codes with their equivalent characters
14391453 $pasteurized = self::replaceUnusualEscapes( $url );
Index: trunk/phase3/includes/parser/Parser.php
@@ -1118,7 +1118,8 @@
11191119 $text = $this->maybeMakeExternalImage( $url );
11201120 if ( $text === false ) {
11211121 # Not an image, make a link
1122 - $text = $sk->makeExternalLink( $url, $wgContLang->markNoConversion($url), true, 'free', $this->mTitle->getNamespace() );
 1122+ $text = $sk->makeExternalLink( $url, $wgContLang->markNoConversion($url), true, 'free',
 1123+ $this->getExternalLinkAttribs() );
11231124 # Register it in the output object...
11241125 # Replace unnecessary URL escape codes with their equivalent characters
11251126 $pasteurized = self::replaceUnusualEscapes( $url );
@@ -1394,11 +1395,18 @@
13951396
13961397 $url = Sanitizer::cleanUrl( $url );
13971398
 1399+ if ( $this->mOptions->mExternalLinkTarget ) {
 1400+ $attribs = array( 'target' => $this->mOptions->mExternalLinkTarget );
 1401+ } else {
 1402+ $attribs = array();
 1403+ }
 1404+
13981405 # Use the encoded URL
13991406 # This means that users can paste URLs directly into the text
14001407 # Funny characters like ö aren't valid in URLs anyway
14011408 # This was changed in August 2004
1402 - $s .= $sk->makeExternalLink( $url, $text, false, $linktype, $this->mTitle->getNamespace() ) . $dtrail . $trail;
 1409+ $s .= $sk->makeExternalLink( $url, $text, false, $linktype, $this->getExternalLinkAttribs() )
 1410+ . $dtrail . $trail;
14031411
14041412 # Register link in the output object.
14051413 # Replace unnecessary URL escape codes with the referenced character
@@ -1411,6 +1419,20 @@
14121420 return $s;
14131421 }
14141422
 1423+ function getExternalLinkAttribs() {
 1424+ $attribs = array();
 1425+ global $wgNoFollowLinks, $wgNoFollowNsExceptions;
 1426+ $ns = $this->mTitle->getNamespace();
 1427+ if( $wgNoFollowLinks && !in_array($ns, $wgNoFollowNsExceptions) ) {
 1428+ $attribs['rel'] = 'nofollow';
 1429+ }
 1430+ if ( $this->mOptions->getExternalLinkTarget() ) {
 1431+ $attribs['target'] = $this->mOptions->getExternalLinkTarget();
 1432+ }
 1433+ return $attribs;
 1434+ }
 1435+
 1436+
14151437 /**
14161438 * Replace unusual URL escape codes with their equivalent characters
14171439 * @param string
Index: trunk/phase3/includes/DefaultSettings.php
@@ -2891,6 +2891,11 @@
28922892 $wgSearchForwardUrl = null;
28932893
28942894 /**
 2895+ * Set a default target for external links, e.g. _blank to pop up a new window
 2896+ */
 2897+$wgExternalLinkTarget = false;
 2898+
 2899+/**
28952900 * If true, external URL links in wiki text will be given the
28962901 * rel="nofollow" attribute as a hint to search engines that
28972902 * they should not be followed for ranking purposes as they
Index: trunk/phase3/includes/Linker.php
@@ -990,11 +990,10 @@
991991 }
992992
993993 /** @todo document */
994 - function makeExternalLink( $url, $text, $escape = true, $linktype = '', $ns = null ) {
995 - $style = $this->getExternalLinkAttributes( $url, $text, 'external ' . $linktype );
996 - global $wgNoFollowLinks, $wgNoFollowNsExceptions;
997 - if( $wgNoFollowLinks && !(isset($ns) && in_array($ns, $wgNoFollowNsExceptions)) ) {
998 - $style .= ' rel="nofollow"';
 994+ function makeExternalLink( $url, $text, $escape = true, $linktype = '', $attribs = array() ) {
 995+ $attribsText = $this->getExternalLinkAttributes( $url, $text, 'external ' . $linktype );
 996+ if ( $attribs ) {
 997+ $attribsText .= Xml::expandAttributes( $attribs );
999998 }
1000999 $url = htmlspecialchars( $url );
10011000 if( $escape ) {
@@ -1006,7 +1005,7 @@
10071006 wfDebug("Hook LinkerMakeExternalLink changed the output of link with url {$url} and text {$text} to {$link}", true);
10081007 return $link;
10091008 }
1010 - return '<a href="'.$url.'"'.$style.'>'.$text.'</a>';
 1009+ return '<a href="'.$url.'"'.$attribsText.'>'.$text.'</a>';
10111010 }
10121011
10131012 /**
Index: trunk/phase3/RELEASE-NOTES
@@ -140,6 +140,8 @@
141141 restriction types on the protection form.
142142 * (bug 8440) Allow preventing blocked users from editing their talk pages
143143 * Improved upload file type detection for OpenDocument formats
 144+* Added the ability to set the target attribute on external links with
 145+ $wgExternalLinkTarget
144146
145147
146148 === Bug fixes in 1.14 ===

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r41333* Added the ability to set the target attribute on external links with $wgExt...tstarling02:35, 28 September 2008
r41406Back out r41333 -- causes lots of parser test regressions due to funny spacin...brion00:14, 30 September 2008

Status & tagging log