2 package IkiWiki::Plugin::blogspam;
8 my $defaulturl='http://test.blogspam.net:8888/';
11 hook(type => "getsetup", id => "blogspam", call => \&getsetup);
12 hook(type => "checkconfig", id => "blogspam", call => \&checkconfig);
13 hook(type => "checkcontent", id => "blogspam", call => \&checkcontent);
22 blogspam_pagespec => {
24 example => 'postcomment(*)',
25 description => 'PageSpec of pages to check for spam',
26 link => 'ikiwiki/PageSpec',
32 example => "blacklist=1.2.3.4,blacklist=8.7.6.5,max-links=10",
33 description => "options to send to blogspam server",
34 link => "http://blogspam.net/api/testComment.html#options",
40 default => $defaulturl,
41 description => "blogspam server XML-RPC url",
48 # This is done at checkconfig time because printing an error
49 # if the module is missing when a spam is posted would not
50 # let the admin know about the problem.
58 sub checkcontent (@) {
61 if (exists $config{blogspam_pagespec}) {
63 if ! pagespec_match($params{page}, $config{blogspam_pagespec},
64 location => $params{page});
68 $url = $config{blogspam_server} if exists $config{blogspam_server};
69 my $client = RPC::XML::Client->new($url);
71 my @options = split(",", $config{blogspam_options})
72 if exists $config{blogspam_options};
74 # Allow short comments and whitespace-only edits, unless the user
75 # has overridden min-words themselves.
76 push @options, "min-words=0"
77 unless grep /^min-words=/i, @options;
78 # Wiki pages can have a lot of urls, unless the user specifically
79 # wants to limit them.
80 push @options, "exclude=lotsaurls"
81 unless grep /^max-links/i, @options;
82 # Unless the user specified a size check, disable such checking.
83 push @options, "exclude=size"
84 unless grep /^(?:max|min)-size/i, @options;
85 # This test has absurd false positives on words like "alpha"
87 push @options, "exclude=stopwords";
90 ip => $ENV{REMOTE_ADDR},
91 comment => defined $params{diff} ? $params{diff} : $params{content},
92 subject => defined $params{subject} ? $params{subject} : "",
93 name => defined $params{author} ? $params{author} : "",
94 link => exists $params{url} ? $params{url} : "",
95 options => join(",", @options),
97 version => "ikiwiki ".$IkiWiki::version,
99 my $res = $client->send_request('testComment', \%req);
101 if (! ref $res || ! defined $res->value) {
102 debug("failed to get response from blogspam server ($url)");
105 elsif ($res->value =~ /^SPAM:(.*)/) {
106 eval q{use Data::Dumper};
107 debug("blogspam server reports ".$res->value.": ".Dumper(\%req));
108 return gettext("Sorry, but that looks like spam to <a href=\"http://blogspam.net/\">blogspam</a>: ").$1;
110 elsif ($res->value ne 'OK') {
111 debug("blogspam server failure: ".$res->value);