]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/CGI.pm
close
[git.ikiwiki.info.git] / IkiWiki / CGI.pm
index c800ddf6eab22d4d0b0fa9b91cfb3f7fcbd4f3a4..155010a97e6d606a1fff8af7b85ff93aef8fc0f5 100644 (file)
@@ -335,7 +335,8 @@ sub cgi_editpage ($$) { #{{{
        # characters.
        my ($page)=$form->field('page');
        $page=titlepage(possibly_foolish_untaint($page));
-       if (! defined $page || ! length $page || file_pruned($page, $config{srcdir}) || $page=~/^\//) {
+       if (! defined $page || ! length $page ||
+           file_pruned($page, $config{srcdir}) || $page=~/^\//) {
                error("bad page name");
        }
        
@@ -401,19 +402,27 @@ sub cgi_editpage ($$) { #{{{
                return;
        }
        elsif ($form->submitted eq "Preview") {
+               my $content=$form->field('editcontent');
+               run_hooks(editcontent => sub {
+                       $content=shift->(
+                               content => $content,
+                               page => $page,
+                               cgi => $q,
+                               session => $session,
+                       );
+               });
                $form->tmpl_param("page_preview",
                        htmlize($page, $type,
                        linkify($page, "",
                        preprocess($page, $page,
-                       filter($page, $page, $form->field('editcontent')), 0, 1))));
+                       filter($page, $page, $content), 0, 1))));
        }
        elsif ($form->submitted eq "Save Page") {
                $form->tmpl_param("page_preview", "");
        }
        $form->tmpl_param("page_conflict", "");
        
-       if ($form->submitted ne "Save Page" || 
-           ! $form->validate) {
+       if ($form->submitted ne "Save Page" || ! $form->validate) {
                if ($form->field("do") eq "create") {
                        my @page_locs;
                        my $best_loc;
@@ -497,6 +506,7 @@ sub cgi_editpage ($$) { #{{{
                }
                
                showform($form, \@buttons, $session, $q);
+               saveindex();
        }
        else {
                # save page
@@ -504,8 +514,8 @@ sub cgi_editpage ($$) { #{{{
 
                my $exists=-e "$config{srcdir}/$file";
 
-               if ($form->field("do") ne "create" &&
-                   ! $exists && ! -e "$config{underlaydir}/$file") {
+               if ($form->field("do") ne "create" && ! $exists &&
+                   ! eval { srcfile($file) }) {
                        $form->tmpl_param("page_gone", 1);
                        $form->field(name => "do", value => "create", force => 1);
                        $form->tmpl_param("page_select", 0);
@@ -531,7 +541,14 @@ sub cgi_editpage ($$) { #{{{
                }
                
                my $content=$form->field('editcontent');
-
+               run_hooks(editcontent => sub {
+                       $content=shift->(
+                               content => $content,
+                               page => $page,
+                               cgi => $q,
+                               session => $session,
+                       );
+               });
                $content=~s/\r\n/\n/g;
                $content=~s/\r/\n/g;