Revision: 46078
Author: simetrical
Date: 2009-01-23 18:03:12 +0000 (Fri, 23 Jan 2009)
Log Message:
-----------
Allow exempting domain names from rel="nofollow"
This introduces a new configuration option, $wgNoFollowDomainExceptions.
By default this is an empty array; perhaps it should be null by default
and initialize to something extracted from $wgServer. An appropriate
value for Wikimedia would be something like:
$wgNoFollowDomainExceptions = array( 'wikipedia.org', 'wiktionary.org',
'wikibooks.org', ... );
It's fairly silly that we're nofollowing links to our own sites. :)
Modified Paths:
--------------
trunk/phase3/RELEASE-NOTES
trunk/phase3/includes/DefaultSettings.php
trunk/phase3/includes/parser/Parser.php
Modified: trunk/phase3/RELEASE-NOTES
===================================================================
--- trunk/phase3/RELEASE-NOTES 2009-01-23 18:03:02 UTC (rev 46077)
+++ trunk/phase3/RELEASE-NOTES 2009-01-23 18:03:12 UTC (rev 46078)
@@ -23,6 +23,8 @@
* Added $wgNewPasswordExpiry, to specify an expiry time (in seconds) to
temporary passwords
* Added $wgUseTwoButtonsSearchForm to choose the Search form behavior/look
+* Added $wgNoFollowDomainExceptions to allow exempting particular domain names
+ from rel="nofollow" on external links
=== New features in 1.15 ===
Modified: trunk/phase3/includes/DefaultSettings.php
===================================================================
--- trunk/phase3/includes/DefaultSettings.php 2009-01-23 18:03:02 UTC (rev
46077)
+++ trunk/phase3/includes/DefaultSettings.php 2009-01-23 18:03:12 UTC (rev
46078)
@@ -3085,6 +3085,19 @@
$wgNoFollowNsExceptions = array();
/**
+ * If this is set to an array of domains, external links to these domain names
+ * (or any subdomains) will not be set to rel="nofollow" regardless of the
+ * value of $wgNoFollowLinks. For instance:
+ *
+ * $wgNoFollowDomainExceptions = array( 'en.wikipedia.org', 'wiktionary.org' );
+ *
+ * This would add rel="nofollow" to links to de.wikipedia.org, but not
+ * en.wikipedia.org, wiktionary.org, en.wiktionary.org, us.en.wikipedia.org,
+ * etc.
+ */
+$wgNoFollowDomainExceptions = array();
+
+/**
* Default robot policy. The default policy is to encourage indexing and fol-
* lowing of links. It may be overridden on a per-namespace and/or per-page
* basis.
Modified: trunk/phase3/includes/parser/Parser.php
===================================================================
--- trunk/phase3/includes/parser/Parser.php 2009-01-23 18:03:02 UTC (rev
46077)
+++ trunk/phase3/includes/parser/Parser.php 2009-01-23 18:03:12 UTC (rev
46078)
@@ -1130,7 +1130,7 @@
if ( $text === false ) {
# Not an image, make a link
$text = $sk->makeExternalLink( $url,
$wgContLang->markNoConversion($url), true, 'free',
- $this->getExternalLinkAttribs() );
+ $this->getExternalLinkAttribs( $url ) );
# Register it in the output object...
# Replace unnecessary URL escape codes with their
equivalent characters
$pasteurized = self::replaceUnusualEscapes( $url );
@@ -1410,8 +1410,8 @@
# This means that users can paste URLs directly into
the text
# Funny characters like ö aren't valid in URLs
anyway
# This was changed in August 2004
- $s .= $sk->makeExternalLink( $url, $text, false,
$linktype, $this->getExternalLinkAttribs() )
- . $dtrail . $trail;
+ $s .= $sk->makeExternalLink( $url, $text, false,
$linktype,
+ $this->getExternalLinkAttribs( $url ) ) .
$dtrail . $trail;
# Register link in the output object.
# Replace unnecessary URL escape codes with the
referenced character
@@ -1424,12 +1424,36 @@
return $s;
}
- function getExternalLinkAttribs() {
+ /**
+ * Get an associative array of additional HTML attributes appropriate
for a
+ * particular external link. This currently may include rel => nofollow
+ * (depending on configuration, namespace, and the URL's domain) and/or
a
+ * target attribute (depending on configuration).
+ *
+ * @param string $url Optional URL, to extract the domain from for rel
=>
+ * nofollow if appropriate
+ * @return array Associative array of HTML attributes
+ */
+ function getExternalLinkAttribs( $url = false ) {
$attribs = array();
global $wgNoFollowLinks, $wgNoFollowNsExceptions;
$ns = $this->mTitle->getNamespace();
if( $wgNoFollowLinks && !in_array($ns, $wgNoFollowNsExceptions)
) {
$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();
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs