X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/d69fdf64455eb343160bca73443e62e550b3c052..68869d664b978b063c9181d024edb34a63306c33:/IkiWiki/Plugin/editpage.pm diff --git a/IkiWiki/Plugin/editpage.pm b/IkiWiki/Plugin/editpage.pm index 91d125a5c..480e82804 100644 --- a/IkiWiki/Plugin/editpage.pm +++ b/IkiWiki/Plugin/editpage.pm @@ -78,34 +78,44 @@ sub check_canedit ($$$;$) { } } }); - 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 ($$) { @@ -395,9 +405,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_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, @@ -431,12 +449,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); }