The first step was to find out what interfaces (if any) already exist to allow us to hook into Defensio - thankfully, I found two that already existed.
Rick Olsen of Mephisto fame released the code a while back for a plugin he uses to provide Akismet and Defensio support within Lighthouse. This set of code makes up Viking and thanks to Rick's release saved me having to rewrite any Defensio interface code. I also considered using the Defensio on Rails plugin but in the end plumped with Viking as it was already pretty similar to the Akismet code used in Mephisto.
Next step was to hook the code into Mephisto - there were a few options on how to do this but in the end I plumped for overriding some of the methods within the Comment model and extracted the Defensio code from Viking (in hindsight, I could just have used Viking as it was). My motivation behind this was that I just wanted to get it working - so there is a caveat that this approach isn't necessarily the most future facing but it gets the job done.
After figuring out where I needed to hook the code in then I went ahead and got cracking. The behaviour of the plugin means that it allows Akismet to continue functioning as before, or it will use Defensio if it is configured.
An additional table field was required to allow the storage of the signature returned by the Defensio service - this is used to subsequently mark a comment as spam or ham (i.e. to notify the service of false positives and negatives).
The main flow of the plugin is as follows - when a comment is posted it checks to see if Defensio is configured (which is done through plugin options in the Mephisto administration screens) - if it is configured, it will use Defensio. If Defensio is not configured it will then see if Akismet is - if it is, it will use Akismet. Otherwise, no spam filtering will be done.
Similar to the built in Akismet code then it will mark a comment as ham if you approve it, and as spam if you unapprove it - in my head this isn't always the case (on the spam side) but is how Mephisto currently does it, so i've kept it consistent.
While testing the approve/unapprove function I also found that the Approve link on comments on the Overview screen didn't actually work - a patch for this is available on Pastie along with the description of the problem on the Mephisto Newsgroup.
I already have some ideas for the next version - one is to show the statisitcs provided by the Defensio service, another is to hook in Viking for both Akismet and Defensio (rather than just hacking the Defensio bit out for use), another is to allow for a chain of spam filters for fallback - for example, if one service fails then to fallback to another. So watch this space!
I've posted about the project on our projects page which should tell you where you need to go to find the plugin and how to install it.


1 comment
Comment on Mephisto Comment Defensio Plugin by Rob
February 13th, 2008 @ 08:12 – permalink
Leave a reply
You can use Markdown in your comment as well as plain HTML. You can use
<filter:jscode lang="ruby">and</filter:jscode>tags to surround code blocks (supported languages are css, html, javascript and ruby). Your email address will not be published.If your comment doesn’t appear immediately after posting it could have been marked as spam. Don’t worry: we regularly check for and approve incorrectly filtered comments so you shouldn’t have to wait too long for it to be shown.