]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/editpage.pm
remove redundant use
[git.ikiwiki.info.git] / IkiWiki / Plugin / editpage.pm
index 91d125a5ca1ca30e836706a6e5e2aa43df6eced2..480e82804a3beb599df3969d788508dd550bccb6 100644 (file)
@@ -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 "") {
                if (defined $ret) {
                        if ($ret eq "") {
-                               $cansave=1;
+                               $ok=1;
                        }
                        elsif (ref $ret eq 'CODE') {
                        }
                        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 ($$) {
 }
 
 sub cgi_editpage ($$) {
@@ -395,9 +405,17 @@ sub cgi_editpage ($$) {
                        showform($form, \@buttons, $session, $q, forcebaseurl => $baseurl);
                        exit;
                }
                        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');
                
                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,
                run_hooks(editcontent => sub {
                        $content=shift->(
                                content => $content,
@@ -431,12 +449,6 @@ sub cgi_editpage ($$) {
                
                my $conflict;
                if ($config{rcs}) {
                
                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);
                        }
                        if (! $exists) {
                                rcs_add($file);
                        }