Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -1130,7 +1130,7 @@ |
1131 | 1131 | if ( $text === false ) { |
1132 | 1132 | # Not an image, make a link |
1133 | 1133 | $text = $sk->makeExternalLink( $url, $wgContLang->markNoConversion($url), true, 'free', |
1134 | | - $this->getExternalLinkAttribs() ); |
| 1134 | + $this->getExternalLinkAttribs( $url ) ); |
1135 | 1135 | # Register it in the output object... |
1136 | 1136 | # Replace unnecessary URL escape codes with their equivalent characters |
1137 | 1137 | $pasteurized = self::replaceUnusualEscapes( $url ); |
— | — | @@ -1410,8 +1410,8 @@ |
1411 | 1411 | # This means that users can paste URLs directly into the text |
1412 | 1412 | # Funny characters like ö aren't valid in URLs anyway |
1413 | 1413 | # This was changed in August 2004 |
1414 | | - $s .= $sk->makeExternalLink( $url, $text, false, $linktype, $this->getExternalLinkAttribs() ) |
1415 | | - . $dtrail . $trail; |
| 1414 | + $s .= $sk->makeExternalLink( $url, $text, false, $linktype, |
| 1415 | + $this->getExternalLinkAttribs( $url ) ) . $dtrail . $trail; |
1416 | 1416 | |
1417 | 1417 | # Register link in the output object. |
1418 | 1418 | # Replace unnecessary URL escape codes with the referenced character |
— | — | @@ -1424,12 +1424,36 @@ |
1425 | 1425 | return $s; |
1426 | 1426 | } |
1427 | 1427 | |
1428 | | - function getExternalLinkAttribs() { |
| 1428 | + /** |
| 1429 | + * Get an associative array of additional HTML attributes appropriate for a |
| 1430 | + * particular external link. This currently may include rel => nofollow |
| 1431 | + * (depending on configuration, namespace, and the URL's domain) and/or a |
| 1432 | + * target attribute (depending on configuration). |
| 1433 | + * |
| 1434 | + * @param string $url Optional URL, to extract the domain from for rel => |
| 1435 | + * nofollow if appropriate |
| 1436 | + * @return array Associative array of HTML attributes |
| 1437 | + */ |
| 1438 | + function getExternalLinkAttribs( $url = false ) { |
1429 | 1439 | $attribs = array(); |
1430 | 1440 | global $wgNoFollowLinks, $wgNoFollowNsExceptions; |
1431 | 1441 | $ns = $this->mTitle->getNamespace(); |
1432 | 1442 | if( $wgNoFollowLinks && !in_array($ns, $wgNoFollowNsExceptions) ) { |
1433 | 1443 | $attribs['rel'] = 'nofollow'; |
| 1444 | + |
| 1445 | + global $wgNoFollowDomainExceptions; |
| 1446 | + if ( $wgNoFollowDomainExceptions ) { |
| 1447 | + $bits = wfParseUrl( $url ); |
| 1448 | + if ( is_array( $bits ) && isset( $bits['host'] ) ) { |
| 1449 | + foreach ( $wgNoFollowDomainExceptions as $domain ) { |
| 1450 | + if( substr( $bits['host'], -strlen( $domain ) ) |
| 1451 | + == $domain ) { |
| 1452 | + unset( $attribs['rel'] ); |
| 1453 | + break; |
| 1454 | + } |
| 1455 | + } |
| 1456 | + } |
| 1457 | + } |
1434 | 1458 | } |
1435 | 1459 | if ( $this->mOptions->getExternalLinkTarget() ) { |
1436 | 1460 | $attribs['target'] = $this->mOptions->getExternalLinkTarget(); |
Index: trunk/phase3/includes/DefaultSettings.php |
— | — | @@ -3085,6 +3085,19 @@ |
3086 | 3086 | $wgNoFollowNsExceptions = array(); |
3087 | 3087 | |
3088 | 3088 | /** |
| 3089 | + * If this is set to an array of domains, external links to these domain names |
| 3090 | + * (or any subdomains) will not be set to rel="nofollow" regardless of the |
| 3091 | + * value of $wgNoFollowLinks. For instance: |
| 3092 | + * |
| 3093 | + * $wgNoFollowDomainExceptions = array( 'en.wikipedia.org', 'wiktionary.org' ); |
| 3094 | + * |
| 3095 | + * This would add rel="nofollow" to links to de.wikipedia.org, but not |
| 3096 | + * en.wikipedia.org, wiktionary.org, en.wiktionary.org, us.en.wikipedia.org, |
| 3097 | + * etc. |
| 3098 | + */ |
| 3099 | +$wgNoFollowDomainExceptions = array(); |
| 3100 | + |
| 3101 | +/** |
3089 | 3102 | * Default robot policy. The default policy is to encourage indexing and fol- |
3090 | 3103 | * lowing of links. It may be overridden on a per-namespace and/or per-page |
3091 | 3104 | * basis. |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -23,6 +23,8 @@ |
24 | 24 | * Added $wgNewPasswordExpiry, to specify an expiry time (in seconds) to |
25 | 25 | temporary passwords |
26 | 26 | * Added $wgUseTwoButtonsSearchForm to choose the Search form behavior/look |
| 27 | +* Added $wgNoFollowDomainExceptions to allow exempting particular domain names |
| 28 | + from rel="nofollow" on external links |
27 | 29 | |
28 | 30 | === New features in 1.15 === |
29 | 31 | |