Industry guru Dave Taylor answers free tech support questions about a wide variety of business and technical topics, including blogging, Google AdSense, MySpace, Sony PSP, Apple iPod, Mp3 players, management, Linux, SEO, Mac OS X, Facebook, Twitter, LinkedIn and Microsoft Windows.

How can I delete Movable Type (MT) blog comment spam easily?

A technical wizard pal of mine asks: "I have all sorts of challenge/response barriers to comment spam on my Movable Type weblog, but occasionally someone goes through the work of identifying themselves and still leaves some silly spam comment. I want to delete it, but right now I get the email notification of the new comment, then have to log in to the administrative interface, find the comment, and delete it by hand. Quite a hassle. Isn't there a better solution to this?"

Dave's Answer:

Ah yes, those wonderful people with their blogspam comments on weblogs.

A personal message from Ask Dave Taylor about this type of comment:

Keep it off our site!

I feel better now. Thanks for letting me vent.

To make life easier for me, I hacked into the Comments.pm module within Movable Type (which you can find in lib/MT/App in your installation) and made the following addition:

$body .= "\nDelete:" . 
$app->{cfg}->CGIPath . 
"mt.cgi?__mode=delete_confirm&" .
"_type=comment&id=".$comment->id . 
"&blog_id=" . $blog->id . "\n";
This should be placed immediately after the message construction line:
$body = Text::Wrap::wrap('', '', $body) . "\n$link_url\n\n" .
$app->translate('IP Address:') . ' ' . $comment->ip . "\n" .
$app->translate('Name:') . ' ' . $comment->author . "\n" .
$app->translate('Email Address:') . ' ' . $comment->email . "\n" .
$app->translate('URL:') . ' ' . $comment->url . "\n\n" .
$app->translate('Comments:') . "\n\n" . $comment->text . "\n";
Now, when I get notification of a new comment, I have an instant "Delete" link I can click, which then takes me directly to the confirm dialog box (though in a big browser window, which is kinda weird). I click "delete" a second time, and the comment is wiped out of the database.

However, and this is an important caveat, I still need to rebuild the weblog to finish the removal process. Not a big deal: I usually find myself rebuilding every 2-3 days anyway, but unfortunately I haven't figured out how to do everything with a single mouse click. Yet.

If you know of other ways to build a URL to embed in the email notification that offers a one-click delete comment and rebuild weblog as needed feature, I'd sure love to hear about it!



Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Simpy.

Subscribe!

Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader.

Comments

I use MT-Blacklist. While it lets through a fair bit of spam, it provides a great interface to bulk delete comments, including rebuilding all the relevent pages.

BTW, how did you get that math question in there? Does it work well? I was going to hack it into mt-comments.cgi, but I see a few people have similar schemes so I thought there might be something out there.

Sean

Posted by: Sean at November 18, 2004 4:03 AM

Thanks for your note, Sean. MT-Blacklist is something that only comes along with an upgraded version of Movable Type: I'm still running 2.x so I can't use it. I am, however, starting to think about an upgrade. :-)

In terms of the math formula, I paid someone to write a custom plug-in for me and then added some code both in the comment templates and in the Comments.pm module...

Posted by: Dave Taylor at November 18, 2004 4:46 AM

You can actually use the earlier versions of MT-Blacklist on a 2.X MT blog. It's not as advanced, and the blacklist isn't being updated, but I still find it useful for those situations in which I get 300 identical spam comments, all on different entries. I can click the link in the notification email, delete the comment and rebuild that one entry, then "de-spam" the whole blog and rebuild the relevant entries in one step.

And I agree; the math formula is terrific! Does it actually cut down on the amount of comment spam? If it does, maybe you'll take a contribution towards costs to share it ...?

---- Nick

Posted by: Nick at November 18, 2004 2:52 PM

I get almost zero comment spam, actually. It's a rare occurrence, probably less than six/month at this point (I cringe at even writing this, though). However, I'm a pretty open source sort of guy, but I am not willing to share this particular plug-in for the simple reason that the more sites that use it, the more motivation spammers will have for figuring out how to reverse-engineer it. Sorry. :-|

Posted by: Dave Taylor at November 19, 2004 7:08 AM

Can someone elaborate on what comment spam is all about? I'll come back to see if there's a clarification later this week. Thanks.

Posted by: Mark C. at April 25, 2006 1:12 AM

Here's how to do it in one click. First you have to have Jay Allen's MT-Blacklist installed http://www.jayallen.org/projects/mt-blacklist/

Then instead of the code in the Comments.pm file, add the following in the same place:
$body .= "\nDelete: " . $app->{cfg}->CGIPath."commentremove.cgi?".$comment->id."\n";

Then in your MovableType directory drop this file as commentremove.cgi (you'll probably need to edit the action= path to mt-blacklist.cgi)

#!/bin/sh

echo Content-type: text/html; charset=utf-8
echo

echo \<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"\>
echo \<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\"\>
echo \<head\>
echo \<title\>Delete Comment $QUERY_STRING \</title\>
echo \</head\>
echo \<body onLoad=\"javascript:submitform\(\)\"\>
echo \<script language=\"JavaScript\"\>
echo function submitform\(\)
echo \{
echo setTimeout\(\"document.onlyform.submit\(\)\",45000\)\;
echo \}
echo \</script\>
echo \<div align=\"center\"\>
echo \<form method=\"post\" action=\"/mt/mt-blacklist.cgi\" name=\"onlyform\" enctype=\"application/x-www-form-urlencoded\"\>
echo \<input type=\"hidden\" name=\"__mode\" value=\"despam_multi\" /\>
echo \<input type=\"hidden\" name=\"_type\" value=\"comment\" /\>
echo \<input type=\"hidden\" name=\"deleteObject\" value=\"$QUERY_STRING\" /\>
echo \<input type=\"hidden\" name=\"rebuildEntries\" value=\"1\" /\>
echo \<input type=\"submit\" name=\"\" value=\"Delete Comment $QUERY_STRING\" /\>
echo \</form\>
echo \</div\>
echo \</body\>
echo \</html\>


And that is how you get comment removal and rebuilding in one click.

Posted by: Nicholas Barnard at November 27, 2007 6:01 PM

I have a lot to say, but ...
Starbucks coffee cup I have a lot to say, and questions of my own for that matter, but most of all I'd like to say thank you for all your efforts on this Web site by buying you a chai!

I do have a comment, now that you mention it!









Remember personal info?


Please note that I will never send you any unsolicited commercial email. Ever.

While I'm at it, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site.









Search
Find just the answers you seek from among our 1700+ free tech support articles by using our Lijit search engine.


Help!





Subscribe to
Ask Dave Taylor!

Add to Google Reader
Add to My Yahoo!
Subscribe in NewsGator Online

RDF   XML

Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.


Recent Entries
Join the List!
Join my author info mailing list, where you'll learn about my upcoming books, speaking gigs, and more!


Book Links
© 2002 - 2008 by Dave Taylor. All Rights Reserved.

Note: This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this web site or on any linked site.

[whiteboard marker tray]