Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -142,6 +142,8 @@ |
143 | 143 | * Improved upload file type detection for OpenDocument formats |
144 | 144 | * (bug 15739) Add $wgArticlePathForCurid to make links with only curid=# as the |
145 | 145 | query string use the article path, rather than the script path |
| 146 | +* Added the ability to set the target attribute on external links with |
| 147 | + $wgExternalLinkTarget |
146 | 148 | |
147 | 149 | |
148 | 150 | === Bug fixes in 1.14 === |
Index: trunk/phase3/includes/DefaultSettings.php |
— | — | @@ -2883,6 +2883,11 @@ |
2884 | 2884 | $wgSearchForwardUrl = null; |
2885 | 2885 | |
2886 | 2886 | /** |
| 2887 | + * Set a default target for external links, e.g. _blank to pop up a new window |
| 2888 | + */ |
| 2889 | +$wgExternalLinkTarget = false; |
| 2890 | + |
| 2891 | +/** |
2887 | 2892 | * If true, external URL links in wiki text will be given the |
2888 | 2893 | * rel="nofollow" attribute as a hint to search engines that |
2889 | 2894 | * they should not be followed for ranking purposes as they |
Index: trunk/phase3/includes/parser/ParserOptions.php |
— | — | @@ -30,6 +30,7 @@ |
31 | 31 | var $mTemplateCallback; # Callback for template fetching |
32 | 32 | var $mEnableLimitReport; # Enable limit report in an HTML comment on output |
33 | 33 | var $mTimestamp; # Timestamp used for {{CURRENTDAY}} etc. |
| 34 | + var $mExternalLinkTarget; # Target attribute for external links |
34 | 35 | |
35 | 36 | var $mUser; # Stored user object, just used to initialise the skin |
36 | 37 | |
— | — | @@ -52,6 +53,7 @@ |
53 | 54 | function getTemplateCallback() { return $this->mTemplateCallback; } |
54 | 55 | function getEnableLimitReport() { return $this->mEnableLimitReport; } |
55 | 56 | function getCleanSignatures() { return $this->mCleanSignatures; } |
| 57 | + function getExternalLinkTarget() { return $this->mExternalLinkTarget; } |
56 | 58 | |
57 | 59 | function getSkin() { |
58 | 60 | if ( !isset( $this->mSkin ) ) { |
— | — | @@ -96,6 +98,7 @@ |
97 | 99 | function enableLimitReport( $x = true ) { return wfSetVar( $this->mEnableLimitReport, $x ); } |
98 | 100 | function setTimestamp( $x ) { return wfSetVar( $this->mTimestamp, $x ); } |
99 | 101 | function setCleanSignatures( $x ) { return wfSetVar( $this->mCleanSignatures, $x ); } |
| 102 | + function setExternalLinkTarget( $x ) { return wfSetVar( $this->mExternalLinkTarget, $x ); } |
100 | 103 | |
101 | 104 | function __construct( $user = null ) { |
102 | 105 | $this->initialiseFromUser( $user ); |
— | — | @@ -114,6 +117,7 @@ |
115 | 118 | global $wgUseTeX, $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages; |
116 | 119 | global $wgAllowExternalImagesFrom, $wgEnableImageWhitelist, $wgAllowSpecialInclusion, $wgMaxArticleSize; |
117 | 120 | global $wgMaxPPNodeCount, $wgMaxTemplateDepth, $wgMaxPPExpandDepth, $wgCleanSignatures; |
| 121 | + global $wgExternalLinkTarget; |
118 | 122 | $fname = 'ParserOptions::initialiseFromUser'; |
119 | 123 | wfProfileIn( $fname ); |
120 | 124 | if ( !$userInput ) { |
— | — | @@ -151,6 +155,7 @@ |
152 | 156 | $this->mTemplateCallback = array( 'Parser', 'statelessFetchTemplate' ); |
153 | 157 | $this->mEnableLimitReport = false; |
154 | 158 | $this->mCleanSignatures = $wgCleanSignatures; |
| 159 | + $this->mExternalLinkTarget = $wgExternalLinkTarget; |
155 | 160 | wfProfileOut( $fname ); |
156 | 161 | } |
157 | 162 | } |
Index: trunk/phase3/includes/parser/Parser_OldPP.php |
— | — | @@ -1353,7 +1353,7 @@ |
1354 | 1354 | # This means that users can paste URLs directly into the text |
1355 | 1355 | # Funny characters like ö aren't valid in URLs anyway |
1356 | 1356 | # 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; |
1358 | 1358 | |
1359 | 1359 | # Register link in the output object. |
1360 | 1360 | # Replace unnecessary URL escape codes with the referenced character |
— | — | @@ -1366,6 +1366,19 @@ |
1367 | 1367 | return $s; |
1368 | 1368 | } |
1369 | 1369 | |
| 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 | + |
1370 | 1383 | /** |
1371 | 1384 | * Replace anything that looks like a URL with a link |
1372 | 1385 | * @private |
— | — | @@ -1432,7 +1445,8 @@ |
1433 | 1446 | $text = $this->maybeMakeExternalImage( $url ); |
1434 | 1447 | if ( $text === false ) { |
1435 | 1448 | # 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() ); |
1437 | 1451 | # Register it in the output object... |
1438 | 1452 | # Replace unnecessary URL escape codes with their equivalent characters |
1439 | 1453 | $pasteurized = self::replaceUnusualEscapes( $url ); |
Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -1118,7 +1118,8 @@ |
1119 | 1119 | $text = $this->maybeMakeExternalImage( $url ); |
1120 | 1120 | if ( $text === false ) { |
1121 | 1121 | # 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() ); |
1123 | 1124 | # Register it in the output object... |
1124 | 1125 | # Replace unnecessary URL escape codes with their equivalent characters |
1125 | 1126 | $pasteurized = self::replaceUnusualEscapes( $url ); |
— | — | @@ -1393,11 +1394,18 @@ |
1394 | 1395 | |
1395 | 1396 | $url = Sanitizer::cleanUrl( $url ); |
1396 | 1397 | |
| 1398 | + if ( $this->mOptions->mExternalLinkTarget ) { |
| 1399 | + $attribs = array( 'target' => $this->mOptions->mExternalLinkTarget ); |
| 1400 | + } else { |
| 1401 | + $attribs = array(); |
| 1402 | + } |
| 1403 | + |
1397 | 1404 | # Use the encoded URL |
1398 | 1405 | # This means that users can paste URLs directly into the text |
1399 | 1406 | # Funny characters like ö aren't valid in URLs anyway |
1400 | 1407 | # This was changed in August 2004 |
1401 | | - $s .= $sk->makeExternalLink( $url, $text, false, $linktype, $this->mTitle->getNamespace() ) . $dtrail . $trail; |
| 1408 | + $s .= $sk->makeExternalLink( $url, $text, false, $linktype, $this->getExternalLinkAttribs() ) |
| 1409 | + . $dtrail . $trail; |
1402 | 1410 | |
1403 | 1411 | # Register link in the output object. |
1404 | 1412 | # Replace unnecessary URL escape codes with the referenced character |
— | — | @@ -1410,6 +1418,20 @@ |
1411 | 1419 | return $s; |
1412 | 1420 | } |
1413 | 1421 | |
| 1422 | + function getExternalLinkAttribs() { |
| 1423 | + $attribs = array(); |
| 1424 | + global $wgNoFollowLinks, $wgNoFollowNsExceptions; |
| 1425 | + $ns = $this->mTitle->getNamespace(); |
| 1426 | + if( $wgNoFollowLinks && !in_array($ns, $wgNoFollowNsExceptions) ) { |
| 1427 | + $attribs['rel'] = 'nofollow'; |
| 1428 | + } |
| 1429 | + if ( $this->mOptions->getExternalLinkTarget() ) { |
| 1430 | + $attribs['target'] = $this->mOptions->getExternalLinkTarget(); |
| 1431 | + } |
| 1432 | + return $attribs; |
| 1433 | + } |
| 1434 | + |
| 1435 | + |
1414 | 1436 | /** |
1415 | 1437 | * Replace unusual URL escape codes with their equivalent characters |
1416 | 1438 | * @param string |
Index: trunk/phase3/includes/Linker.php |
— | — | @@ -990,11 +990,10 @@ |
991 | 991 | } |
992 | 992 | |
993 | 993 | /** @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 ); |
999 | 998 | } |
1000 | 999 | $url = htmlspecialchars( $url ); |
1001 | 1000 | if( $escape ) { |
— | — | @@ -1006,7 +1005,7 @@ |
1007 | 1006 | wfDebug("Hook LinkerMakeExternalLink changed the output of link with url {$url} and text {$text} to {$link}", true); |
1008 | 1007 | return $link; |
1009 | 1008 | } |
1010 | | - return '<a href="'.$url.'"'.$style.'>'.$text.'</a>'; |
| 1009 | + return '<a href="'.$url.'"'.$attribsText.'>'.$text.'</a>'; |
1011 | 1010 | } |
1012 | 1011 | |
1013 | 1012 | /** |