Stephen
Stephen

Reputation: 543

Adding "nofollow" tag to a single link in MediaWiki

I'm an administrator for a wiki (using MediaWiki), and one of our sponsored links has requested that we add the rel="nofollow" attribute to their links, since they are trying to comply with a new google policy. I purposefully disabled the global rel="nofollow" for the entire wiki a while ago, and I want to keep it this way, so I just want to change this one link.

Now obviously it shouldn't be possible for a regular user to disable a rel="nofollow" attribute on a single link, since then spammers would do this and defeat the purpose of nofollow.

But I want to enable a rel="nofollow" attribute (and I'm also an administrator). Is there any way to do this?

For example, I can modify $wgNoFollowDomainExceptions if I want to remove a rel="nofollow" tag to all links to a certain domain. What I want is the opposite: to add a rel="nofollow" tag to all links to a certain domain.

thanks in advance!

PS. As far as I can tell, CSS and javascript hacks are no good, since this needs to be something that a search engine spider will see.

Upvotes: 1

Views: 449

Answers (1)

Anomie
Anomie

Reputation: 94864

There is no configuration setting to do this. But you can easily enough do this using the LinkerMakeExternalLink hook. Add this to your LocalSettings.php:

function localAddNoFollow( &$url, &$text, &$link, &$attribs ) {
    $bits = wfParseUrl( $url );
    if ( is_array( $bits ) && isset( $bits['host'] ) ) {
        if ( $bits['host'] == 'www.example.com' ) {
            $attribs['rel']='nofollow';
        }
    }
    return true;
}
$wgHooks['LinkerMakeExternalLink'][] = 'localAddNoFollow';

Upvotes: 3

Related Questions