return $index;
}
+/**
+ * Check whether a given URL has a domain that occurs in a given set of domains
+ * @param $url string URL
+ * @param $domains array Array of domains (strings)
+ * @return bool True if the host part of $url ends in one of the strings in $domains
+ */
+function wfMatchesDomainList( $url, $domains ) {
+ $bits = wfParseUrl( $url );
+ if ( is_array( $bits ) && isset( $bits['host'] ) ) {
+ foreach ( (array)$domains as $domain ) {
+ // FIXME: This gives false positives. http://nds-nl.wikipedia.org will match nl.wikipedia.org
+ // We should use something that interprets dots instead
+ if ( substr( $bits['host'], -strlen( $domain ) ) === $domain ) {
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
/**
* Sends a line to the debug log if enabled or, optionally, to a comment in output.
* In normal operation this is a NOP.
if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
$href = $link;
- //Parser::getExternalLinkAttribs won't work here because of the Namespace things
- global $wgNoFollowLinks;
- if ( $wgNoFollowLinks ) {
+
+ // Parser::getExternalLinkAttribs won't work here because of the Namespace things
+ global $wgNoFollowLinks, $wgNoFollowDomainExceptions;
+ if ( $wgNoFollowLinks && !wfMatchesDomainList( $url, $wgNoFollowDomainExceptions ) ) {
$extraAttribs['rel'] = 'nofollow';
-
- global $wgNoFollowDomainExceptions;
- if ( $wgNoFollowDomainExceptions ) {
- $bits = wfParseUrl( $url );
- if ( is_array( $bits ) && isset( $bits['host'] ) ) {
- foreach ( $wgNoFollowDomainExceptions as $domain ) {
- if ( substr( $bits['host'], -strlen( $domain ) ) == $domain ) {
- unset( $extraAttribs['rel'] );
- break;
- }
- }
- }
- }
}
+
global $wgExternalLinkTarget;
if ( $wgExternalLinkTarget) {
$extraAttribs['target'] = $wgExternalLinkTarget;
*/
function getExternalLinkAttribs( $url = false ) {
$attribs = array();
- global $wgNoFollowLinks, $wgNoFollowNsExceptions;
+ global $wgNoFollowLinks, $wgNoFollowNsExceptions, $wgNoFollowDomainExceptions;
$ns = $this->mTitle->getNamespace();
- if ( $wgNoFollowLinks && !in_array( $ns, $wgNoFollowNsExceptions ) ) {
+ if ( $wgNoFollowLinks && !in_array( $ns, $wgNoFollowNsExceptions ) &&
+ !wfMatchesDomainList( $url, $wgNoFollowDomainExceptions ) )
+ {
$attribs['rel'] = 'nofollow';
-
- global $wgNoFollowDomainExceptions;
- if ( $wgNoFollowDomainExceptions ) {
- $bits = wfParseUrl( $url );
- if ( is_array( $bits ) && isset( $bits['host'] ) ) {
- foreach ( $wgNoFollowDomainExceptions as $domain ) {
- if ( substr( $bits['host'], -strlen( $domain ) ) == $domain ) {
- unset( $attribs['rel'] );
- break;
- }
- }
- }
- }
}
if ( $this->mOptions->getExternalLinkTarget() ) {
$attribs['target'] = $this->mOptions->getExternalLinkTarget();