Index: trunk/phase3/includes/GlobalFunctions.php |
— | — | @@ -646,6 +646,26 @@ |
647 | 647 | } |
648 | 648 | |
649 | 649 | /** |
| 650 | + * Check whether a given URL has a domain that occurs in a given set of domains |
| 651 | + * @param $url string URL |
| 652 | + * @param $domains array Array of domains (strings) |
| 653 | + * @return bool True if the host part of $url ends in one of the strings in $domains |
| 654 | + */ |
| 655 | +function wfMatchesDomainList( $url, $domains ) { |
| 656 | + $bits = wfParseUrl( $url ); |
| 657 | + if ( is_array( $bits ) && isset( $bits['host'] ) ) { |
| 658 | + foreach ( (array)$domains as $domain ) { |
| 659 | + // FIXME: This gives false positives. http://nds-nl.wikipedia.org will match nl.wikipedia.org |
| 660 | + // We should use something that interprets dots instead |
| 661 | + if ( substr( $bits['host'], -strlen( $domain ) ) === $domain ) { |
| 662 | + return true; |
| 663 | + } |
| 664 | + } |
| 665 | + } |
| 666 | + return false; |
| 667 | +} |
| 668 | + |
| 669 | +/** |
650 | 670 | * Sends a line to the debug log if enabled or, optionally, to a comment in output. |
651 | 671 | * In normal operation this is a NOP. |
652 | 672 | * |
Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -1648,23 +1648,12 @@ |
1649 | 1649 | */ |
1650 | 1650 | function getExternalLinkAttribs( $url = false ) { |
1651 | 1651 | $attribs = array(); |
1652 | | - global $wgNoFollowLinks, $wgNoFollowNsExceptions; |
| 1652 | + global $wgNoFollowLinks, $wgNoFollowNsExceptions, $wgNoFollowDomainExceptions; |
1653 | 1653 | $ns = $this->mTitle->getNamespace(); |
1654 | | - if ( $wgNoFollowLinks && !in_array( $ns, $wgNoFollowNsExceptions ) ) { |
| 1654 | + if ( $wgNoFollowLinks && !in_array( $ns, $wgNoFollowNsExceptions ) && |
| 1655 | + !wfMatchesDomainList( $url, $wgNoFollowDomainExceptions ) ) |
| 1656 | + { |
1655 | 1657 | $attribs['rel'] = 'nofollow'; |
1656 | | - |
1657 | | - global $wgNoFollowDomainExceptions; |
1658 | | - if ( $wgNoFollowDomainExceptions ) { |
1659 | | - $bits = wfParseUrl( $url ); |
1660 | | - if ( is_array( $bits ) && isset( $bits['host'] ) ) { |
1661 | | - foreach ( $wgNoFollowDomainExceptions as $domain ) { |
1662 | | - if ( substr( $bits['host'], -strlen( $domain ) ) == $domain ) { |
1663 | | - unset( $attribs['rel'] ); |
1664 | | - break; |
1665 | | - } |
1666 | | - } |
1667 | | - } |
1668 | | - } |
1669 | 1658 | } |
1670 | 1659 | if ( $this->mOptions->getExternalLinkTarget() ) { |
1671 | 1660 | $attribs['target'] = $this->mOptions->getExternalLinkTarget(); |
Index: trunk/phase3/includes/Skin.php |
— | — | @@ -1153,24 +1153,13 @@ |
1154 | 1154 | |
1155 | 1155 | if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) { |
1156 | 1156 | $href = $link; |
1157 | | - //Parser::getExternalLinkAttribs won't work here because of the Namespace things |
1158 | | - global $wgNoFollowLinks; |
1159 | | - if ( $wgNoFollowLinks ) { |
| 1157 | + |
| 1158 | + // Parser::getExternalLinkAttribs won't work here because of the Namespace things |
| 1159 | + global $wgNoFollowLinks, $wgNoFollowDomainExceptions; |
| 1160 | + if ( $wgNoFollowLinks && !wfMatchesDomainList( $url, $wgNoFollowDomainExceptions ) ) { |
1160 | 1161 | $extraAttribs['rel'] = 'nofollow'; |
1161 | | - |
1162 | | - global $wgNoFollowDomainExceptions; |
1163 | | - if ( $wgNoFollowDomainExceptions ) { |
1164 | | - $bits = wfParseUrl( $url ); |
1165 | | - if ( is_array( $bits ) && isset( $bits['host'] ) ) { |
1166 | | - foreach ( $wgNoFollowDomainExceptions as $domain ) { |
1167 | | - if ( substr( $bits['host'], -strlen( $domain ) ) == $domain ) { |
1168 | | - unset( $extraAttribs['rel'] ); |
1169 | | - break; |
1170 | | - } |
1171 | | - } |
1172 | | - } |
1173 | | - } |
1174 | 1162 | } |
| 1163 | + |
1175 | 1164 | global $wgExternalLinkTarget; |
1176 | 1165 | if ( $wgExternalLinkTarget) { |
1177 | 1166 | $extraAttribs['target'] = $wgExternalLinkTarget; |