chipplechipple

Blog - Let's "nofollow"! (+ time-sensitive patch)

Technology Let's "nofollow"! (+ time-sensitive patch)

A great idea to attempt to get rid of comment spam once for all has been suggested by the people at Google to MovableType. It sums up to adding an automatic rel="nofollow" to links posted by visitors (comments and trackbacks). Cooperating search engines (so far Google, Yahoo! and MSN... not bad for starters) will from now on ignore those links, making useless the comment spammers' malicious tactics such as increasing their PageRank.

MovableType has already issued a plugin that does the above. (By the way, the plugin is said to be for MT 3.x and MT 2.661, but I have installed it on my MT 2.64 and can confirm that all seems to work as supposed to.)

However one thing bothers me about this, as was pointed out by many, not only links in spam comments are being ignored, but also the good links posted by legit readers.

In an attempt to compromise, I changed a bit the Perl version plugin (nofollow.pl) to make it time-sensitive. This means that it will only add rel="nofollow" to comments/trackbacks that are less than X hours old. X hours corresponds to the maximum time I may be without despamming.
This sure isn't perfect, since some rel="nofollow"'s may remain in my static archives until I rebuild someday, but in my opinion it's better than leaving the plugin as is. Needless to say, if you don't despam regularly, don't use this.

So here's my patch.

nofollow.pl

Near the top of the file, let's say before the first eval (line 12), add the variable that contains the minimum number of hours. Change the 24 to whatever you like.

my $nofollowfy_hours_limit = 24;  # Number of hours to nofollowfy
                                  # set this to the maximum time you may not despam

Then, in the nofollowfy_hdlr sub, just below the line that reads
    my $out = $fn->($ctx, $args, $cond);
add:

    my $created_on;
    if ($tag eq 'CommentBody' || $tag eq 'CommentAuthorLink') {
        # Comment, use "created_on" from comment
        $created_on = $ctx->stash('comment')->created_on;
    }
    else {
        # Pings, get "created_on" from latest ping for current set
        # (code from Context.pm sub _hdlr_pings)
        require MT::Trackback;
        require MT::TBPing;
        my($tb, $cat);
        if (my $e = $ctx->stash('entry')) {
            $tb = MT::Trackback->load({ entry_id => $e->id });
            return '' unless $tb;
        } elsif ($cat = $ctx->stash('archive_category')) {
            $tb = MT::Trackback->load({ category_id => $cat->id });
            return '' unless $tb;
        } elsif (my $cat_name = $args->{category}) {
            require MT::Category;
            $cat = MT::Category->load({ label => $cat_name,
                                        blog_id => $ctx->stash('blog_id') })
                or return $ctx->error("No such category '$cat_name'");
            $tb = MT::Trackback->load({ category_id => $cat->id });
            return '' unless $tb;
        }
        my $tokens = $ctx->stash('tokens');
        my %terms;
        $terms{tb_id} = $tb->id if $tb;
        $terms{blog_id} = $ctx->stash('blog_id');
        my %arg = ('sort' => 'created_on', direction => 'descend', limit => 1);
        my $iter = MT::TBPing->load_iter(\%terms, \%arg);
        if (my $ping = $iter->()) {
            $ctx->stash('ping' => $ping);
            $created_on = $ping->created_on;
        }
    }
    # If date found and older than $nofollowfy_hours_limit,
    # return without nofollowfying
    if ($created_on) {
        my @ts = gmtime (MT::Util::offset_time(time, $ctx->stash('blog_id'))-$nofollowfy_hours_limit*3600);
        my $ts = sprintf "%04d%02d%02d%02d%02d%02d",
            $ts[5]+1900, $ts[4]+1, @ts[3,2,1,0];
        return $out unless $ts < $created_on;
    }

That's all. Seems to be working fine for me.
Comments/suggestions/improvements are welcome.

Disclaimer: This has only been tested with my good old MT 2.64 and is provided with no guarantee, so backup your files and use at your own risk.

Posted on January 19, 2005 at 22:39 | Tweet |


Trackback


Comments RSS

very nice! I was actually wondering if it would work on 2.64... that's what i'm on too.

one day i'll throw down the money and upgrade... but I don't think I need it just yet.

Posted by Brent on January 24, 2005 at 11:28


I don't think there's much difference between 2.64 and 2.661 except the link redirection thing and some minor fixes, so most plugins should work anyway.

Personally, I'm not considering upgrading to 3.0 as I do this for fun and don't have $70 for them. I'd go for the free version but I use two accounts (one for my moblog) so their limits don't do it for me.
I was a bit upset when it came out though cause I missed 2.661 while it was still under the original license. Oh well.

Posted by Patrick on January 24, 2005 at 11:58


Patrick, why do you need a separate account for you moblog? I'm using MT 3.1.12 and I have 1 account and 5 blogs and I'm using the free version. It says that I can only have 3 blogs but I created 5!

Posted by Roy on January 26, 2005 at 11:01


Sure I could use my main user account for the moblog, but I prefer creating a separate account which only has access to posting in the moblog, for security reasons (it may be unlikely but mfop's server could be hacked into someday, just like any other).

I think the MT software isn't crippled, e.g. whatever your license the software you download is the same and you can create as many users and blogs as you want. However it goes against their license to make more than you've paid for.
Regarding blogs though, they clarified that you can make as many blogs in MT as you want as long as they all appear as "one same blog/web site", so you're not breaking their license. :) They didn't say the same regarding authors though.

Posted by Patrick on January 26, 2005 at 11:10


Hmmm, you've got a good point there. Maybe I should rethink how I'm doing my moblogging.

By the way, mfop doesn't support image resizing so I'm guessing you wrote some custom script to create thumbnails and links to the original sized photos.

I'm still looking for a better plugin or service for moblogging.

Posted by Roy on January 26, 2005 at 11:55


Yeah I have my custom script to make thumbnails. Maybe I should share it but I don't want to do support. :)

I like Mfop, it's simple and flexible enough!

Posted by Patrick on January 26, 2005 at 13:37



« Scope browser for i-mode | Back to main page | Tea Room Alice »