summaryrefslogtreecommitdiff
path: root/IkiWiki
diff options
context:
space:
mode:
authorJoey Hess <joey@gnu.kitenet.net>2009-01-16 20:46:55 -0500
committerJoey Hess <joey@gnu.kitenet.net>2009-01-16 20:46:55 -0500
commitf7b2cfcf50f12ad6ce7358f74e8db9d6083aa284 (patch)
treedd2ab8747231a8de6c3e08a143247175611cdf8a /IkiWiki
parent362a3295563a11ae93370d365d9b0369d0726199 (diff)
checkcontent: New hook, can be used to implement arbitrary content filters, including spam filters.
Diffstat (limited to 'IkiWiki')
-rw-r--r--IkiWiki/Plugin/comments.pm13
-rw-r--r--IkiWiki/Plugin/editpage.pm53
2 files changed, 57 insertions, 9 deletions
diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm
index 16f9a873f..14e785c8f 100644
--- a/IkiWiki/Plugin/comments.pm
+++ b/IkiWiki/Plugin/comments.pm
@@ -467,9 +467,18 @@ sub sessioncgi ($$) {
}
if ($form->submitted eq POST_COMMENT && $form->validate) {
- my $file = "$location._comment";
-
IkiWiki::checksessionexpiry($cgi, $session);
+
+ IkiWiki::check_content(content => $form->field('editcontent'),
+ subject => $form->field('subject'),
+ $config{comments_allowauthor} ? (
+ author => $form->field('author'),
+ url => $form->field('url'),
+ ) : (),
+ page => $location,
+ cgi => $cgi, session => $session);
+
+ my $file = "$location._comment";
# FIXME: could probably do some sort of graceful retry
# on error? Would require significant unwinding though
diff --git a/IkiWiki/Plugin/editpage.pm b/IkiWiki/Plugin/editpage.pm
index ed994306f..bba52e4fd 100644
--- a/IkiWiki/Plugin/editpage.pm
+++ b/IkiWiki/Plugin/editpage.pm
@@ -78,7 +78,43 @@ sub check_canedit ($$$;$) {
}
}
});
- return $canedit;
+ return defined $canedit ? $canedit : 1;
+}
+
+sub check_content (@) {
+ my %params=@_;
+
+ return 1 if ! exists $hooks{checkcontent}; # optimisation
+
+ if (exists $pagesources{$params{page}}) {
+ my @diff;
+ my %old=map { $_ => 1 }
+ split("\n", readfile(srcfile($pagesources{$params{page}})));
+ foreach my $line (split("\n", $params{content})) {
+ push @diff, $line if ! exists $old{$_};
+ }
+ $params{content}=join("\n", @diff);
+ }
+
+ my $ok;
+ run_hooks(checkcontent => sub {
+ return if defined $ok;
+ my $ret=shift->(%params);
+ if (defined $ret) {
+ if ($ret eq "") {
+ $ok=1;
+ }
+ elsif (ref $ret eq 'CODE') {
+ $ret->();
+ $ok=0;
+ }
+ elsif (defined $ret) {
+ error($ret);
+ }
+ }
+
+ });
+ return defined $ok ? $ok : 1;
}
sub cgi_editpage ($$) {
@@ -368,8 +404,17 @@ sub cgi_editpage ($$) {
showform($form, \@buttons, $session, $q, forcebaseurl => $baseurl);
exit;
}
+
+ my $message="";
+ if (defined $form->field('comments') &&
+ length $form->field('comments')) {
+ $message=$form->field('comments');
+ }
my $content=$form->field('editcontent');
+ check_content(content => $content, page => $page,
+ cgi => $q, session => $session,
+ subject => $message);
run_hooks(editcontent => sub {
$content=shift->(
content => $content,
@@ -403,12 +448,6 @@ sub cgi_editpage ($$) {
my $conflict;
if ($config{rcs}) {
- my $message="";
- if (defined $form->field('comments') &&
- length $form->field('comments')) {
- $message=$form->field('comments');
- }
-
if (! $exists) {
rcs_add($file);
}