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 = $config{blogspam_server} if exists $config{blogspam_server};
66 my $client = RPC::XML::Client->new($url);
68 my @options = split(",", $config{blogspam_options})
69 if exists $config{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";
87 ip => $ENV{REMOTE_ADDR},
88 comment => defined $params{diff} ? $params{diff} : $params{content},
89 subject => defined $params{subject} ? $params{subject} : "",
90 name => defined $params{author} ? $params{author} : "",
91 link => exists $params{url} ? $params{url} : "",
92 options => join(",", @options),
94 version => "ikiwiki ".$IkiWiki::version,
96 my $res = $client->send_request('testComment', \%req);
98 if (! ref $res || ! defined $res->value) {
99 debug("failed to get response from blogspam server ($url)");
102 elsif ($res->value =~ /^SPAM:(.*)/) {
103 eval q{use Data::Dumper};
104 debug("blogspam server reports ".$res->value.": ".Dumper(\%req));
105 return gettext("Sorry, but that looks like spam to <a href=\"http://blogspam.net/\">blogspam</a>: ").$1;
107 elsif ($res->value ne 'OK') {
108 debug("blogspam server failure: ".$res->value);