2 package IkiWiki::Plugin::blogspam;
8 require RPC::XML::Client;
10 my $defaulturl='http://test.blogspam.net:8888/';
13 hook(type => "getsetup", id => "blogspam", call => \&getsetup);
14 hook(type => "checkcontent", id => "blogspam", call => \&checkcontent);
23 blogspam_pagespec => {
25 example => 'postcomment(*)',
26 description => 'PageSpec of pages to check for spam',
27 link => 'ikiwiki/PageSpec',
33 example => "blacklist=1.2.3.4,blacklist=8.7.6.5,max-links=10",
34 description => "options to send to blogspam server",
35 link => "http://blogspam.net/api/testComment.html#options",
41 default => $defaulturl,
42 description => "blogspam server XML-RPC url",
48 sub checkcontent (@) {
51 if (exists $config{blogspam_pagespec}) {
53 if ! pagespec_match($params{page}, $config{blogspam_pagespec},
54 location => $params{page});
58 $url = $params{blogspam_server} if exists $params{blogspam_server};
59 my $client = RPC::XML::Client->new($url);
61 my @options = split(",", $params{blogspam_options})
62 if exists $params{blogspam_options};
64 # Allow short comments and whitespace-only edits, unless the user
65 # has overridden min-words themselves.
66 push @options, "min-words=0"
67 unless grep /^min-words=/i, @options;
68 # Wiki pages can have a lot of urls, unless the user specifically
69 # wants to limit them.
70 push @options, "exclude=lotsaurls"
71 unless grep /^max-links/i, @options;
72 # Unless the user specified a size check, disable such checking.
73 push @options, "exclude=size"
74 unless grep /^(?:max|min)-size/i, @options;
75 # This test has absurd false positives on words like "alpha"
77 push @options, "exclude=stopwords";
79 # blogspam API does not have a field for author url, so put it in
80 # the content to be checked.
81 if (exists $params{url}) {
82 $params{content}.="\n".$params{url};
85 my $res = $client->send_request('testComment', {
86 ip => $ENV{REMOTE_ADDR},
87 comment => $params{content},
88 subject => defined $params{subject} ? $params{subject} : "",
89 name => defined $params{author} ? $params{author} : "",
90 options => join(",", @options),
92 version => "ikiwiki ".$IkiWiki::version,
95 if (! ref $res || ! defined $res->value) {
96 debug("failed to get response from blogspam server ($url)");
99 elsif ($res->value =~ /^SPAM:(.*)/) {
100 return gettext("Sorry, but that looks like spam to <a href=\"http://blogspam.net/\">blogspam</a>: ").$1;
102 elsif ($res->value ne 'OK') {
103 debug(gettext("blogspam server failure: ").$res->value);