X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/54f600af14bf6dc067ffc30ec6f22d517001fe99..0116509c81314c80bedc88185faa816d046c6ce5:/IkiWiki/Plugin/blogspam.pm?ds=sidebyside diff --git a/IkiWiki/Plugin/blogspam.pm b/IkiWiki/Plugin/blogspam.pm index c4e5cf390..e48ed729f 100644 --- a/IkiWiki/Plugin/blogspam.pm +++ b/IkiWiki/Plugin/blogspam.pm @@ -4,6 +4,7 @@ package IkiWiki::Plugin::blogspam; use warnings; use strict; use IkiWiki 3.00; +use Encode; my $defaulturl='http://test.blogspam.net:8888/'; @@ -52,21 +53,30 @@ sub checkconfig () { eval q{ use RPC::XML; use RPC::XML::Client; + $RPC::XML::ENCODING = 'utf-8'; }; error $@ if $@; } sub checkcontent (@) { my %params=@_; + my $session=$params{session}; - if (exists $config{blogspam_pagespec}) { - return undef - if ! pagespec_match($params{page}, $config{blogspam_pagespec}, - location => $params{page}); + my $spec='!admin()'; + if (exists $config{blogspam_pagespec} && + length $config{blogspam_pagespec}) { + $spec.=" and (".$config{blogspam_pagespec}.")"; } + my $user=$session->param("name"); + return undef unless pagespec_match($params{page}, $spec, + (defined $user ? (user => $user) : ()), + (defined $session->remote_addr() ? (ip => $session->remote_addr()) : ()), + location => $params{page}); + my $url=$defaulturl; $url = $config{blogspam_server} if exists $config{blogspam_server}; + my $client = RPC::XML::Client->new($url); my @options = split(",", $config{blogspam_options}) @@ -88,13 +98,13 @@ sub checkcontent (@) { push @options, "exclude=stopwords"; my %req=( - ip => $ENV{REMOTE_ADDR}, - comment => defined $params{diff} ? $params{diff} : $params{content}, - subject => defined $params{subject} ? $params{subject} : "", - name => defined $params{author} ? $params{author} : "", - link => exists $params{url} ? $params{url} : "", + ip => $session->remote_addr(), + comment => encode_utf8(defined $params{diff} ? $params{diff} : $params{content}), + subject => encode_utf8(defined $params{subject} ? $params{subject} : ""), + name => encode_utf8(defined $params{author} ? $params{author} : ""), + link => encode_utf8(exists $params{url} ? $params{url} : ""), options => join(",", @options), - site => $config{url}, + site => encode_utf8($config{url}), version => "ikiwiki ".$IkiWiki::version, ); my $res = $client->send_request('testComment', \%req);