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