Revision [15009]

This is an old revision of SpamBlacklist made by MreimeR on 2006-08-01 16:28:51.

 

SpamBlacklist Plugin


This is a spam blacklisting plugin, I've written. The blacklist is stored on a wiki page. You may optionally enable a log file to log successfully blocked spam.

At first, place the following code as a new file, with the filename spamblacklist.php, under 3rdparty/plugins, into your wikka installation:

  1. <?php
  2. // Spam Blacklisting Plugin for Wikka Wiki
  3. // Copyright (C) Manuel Reimer (Manuel _dot_ Reimer _at_ gmx _dot_ de)
  4. // This program is free software; you can redistribute it and/or
  5. // modify it under the terms of the GNU General Public License
  6. // version 2 as published by the Free Software Foundation
  7.  
  8. // Configuration area
  9. define('SB_PAGE', "SpamBlacklist"); // Name of Wiki-Page with blacklist on it
  10. define('SB_ONLY_ANON', true); // Only append blacklist to anonymous users?
  11. define('SB_LOGFILE', "spam.log"); // Optional logfile (relative to wikka.php)
  12.  
  13. // Don't change below this line
  14. function sb_isspam($wikkaref, $body) {
  15.     $sb_blacklist = $wikkaref->LoadPage(SB_PAGE);
  16.     if (!$wikkaref->GetUser() || !SB_ONLY_ANON) {
  17.         if ($sb_blacklist && isset($sb_blacklist["body"])) {
  18.             $sb_blacklist = $sb_blacklist["body"];
  19.             $sb_blacklist = explode("\n", $sb_blacklist);
  20.             foreach ($sb_blacklist as $sb_expression) {
  21.                 if (preg_match('/(^\s*$|^\s*#)/', $sb_expression))
  22.                     continue;
  23.                 if (preg_match($sb_expression, $body)) {
  24.                     if (SB_LOGFILE) {
  25.                         $sb_fp = fopen(SB_LOGFILE, "a");
  26.                         if ($sb_fp) {
  27.                             $sb_logline = date("M d Y H:i:s") . "\t";
  28.                             $sb_logline .= $sb_expression . "\t";
  29.                             $sb_logline .= $wikkaref->GetUserName() . "\n";
  30.                             fwrite($sb_fp, $sb_logline);
  31.                         }
  32.                     }
  33.                     return true;
  34.                 }
  35.             }
  36.         }
  37.     }
  38.     return false;
  39. }
  40. ?>


You may configure the plugin for your needs, in the "configure area", in that file.

Now open the file handlers/page/addcomment.php and add the following lines on top of this file:

  1. <?php
  2. include("3rdparty/plugins/spamblacklist.php");
  3. if (sb_isspam($this, $_POST["body"])) {
  4.     print("<div class=\"page\"><em>Go spam somewhere else!</em></div>\n");
  5.     return;
  6. }
  7.  
  8. if ($this->HasAccess ...... And so on. Now the code, alredy in the file, follows


If you like, you may also do the same for handlers/page/edit.php

The next step is to create a new page called "SpamBlacklist" and maybe set the ACLs to block users from reading, or even writing, this page. On this page you may now add several lines of regular expressions. As soon as one of your expressions match against the body of the comment/page, someone tries to publish, the user will get a message, your logfile gets updated and the comment/page does not get published.

Comments on your blacklist are possible if you prefix them with "#".

An example for an expression could be:

/viagra/i
There are 4 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki