}
}
});
- return $canedit;
+ return defined $canedit ? $canedit : 1;
}
-sub check_cansave ($$$$) {
- my $page=shift;
- my $content=shift;
- my $q=shift;
- my $session=shift;
+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{diff}=join("\n", @diff);
+ }
- my $cansave;
- run_hooks(cansave => sub {
- return if defined $cansave;
- my $ret=shift->($page, $content, $q, $session);
+ my $ok;
+ run_hooks(checkcontent => sub {
+ return if defined $ok;
+ my $ret=shift->(%params);
if (defined $ret) {
if ($ret eq "") {
- $cansave=1;
+ $ok=1;
}
elsif (ref $ret eq 'CODE') {
- $ret->();
- $cansave=0;
+ $ret->() unless $params{nonfatal};
+ $ok=0;
}
- else {
- error($ret);
- $cansave=0;
+ elsif (defined $ret) {
+ error($ret) unless $params{nonfatal};
+ $ok=0;
}
}
+
});
- return $cansave;
+ return defined $ok ? $ok : 1;
}
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_cansave($page, $content, $q, $session);
+ check_content(content => $content, page => $page,
+ cgi => $q, session => $session,
+ subject => $message);
run_hooks(editcontent => sub {
$content=shift->(
content => $content,
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);
}