]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/CGI.pm
web commit by https://jaroslav.klaus.myopenid.com/: poll vote (Accept only OpenID...
[git.ikiwiki.info.git] / IkiWiki / CGI.pm
index 1ec23df68c4075788a4d301bd83c14277cba7876..042e168aa8dc501613746ea3af45b2ecbbc4fafa 100644 (file)
@@ -21,7 +21,7 @@ sub printheader ($) { #{{{
 
 } #}}}
 
-sub showform ($$$$) { #{{{
+sub showform ($$$$;@) { #{{{
        my $form=shift;
        my $buttons=shift;
        my $session=shift;
@@ -35,7 +35,7 @@ sub showform ($$$$) { #{{{
        }
 
        printheader($session);
-       print misctemplate($form->title, $form->render(submit => $buttons));
+       print misctemplate($form->title, $form->render(submit => $buttons), @_);
 }
 
 sub redirect ($$) { #{{{
@@ -276,6 +276,8 @@ sub cgi_editpage ($$) { #{{{
            file_pruned($page, $config{srcdir}) || $page=~/^\//) {
                error("bad page name");
        }
+
+       my $baseurl=$config{url}."/".htmlpage($page);
        
        my $from;
        if (defined $form->field('from')) {
@@ -325,10 +327,9 @@ sub cgi_editpage ($$) { #{{{
        $form->tmpl_param("can_commit", $config{rcs});
        $form->tmpl_param("indexlink", indexlink());
        $form->tmpl_param("helponformattinglink",
-               htmllink("", "", "ikiwiki/formatting",
+               htmllink($page, $page, "ikiwiki/formatting",
                        noimageinline => 1,
                        linktext => "FormattingHelp"));
-       $form->tmpl_param("baseurl", baseurl());
        
        if ($form->submitted eq "Cancel") {
                if ($form->field("do") eq "create" && defined $from) {
@@ -354,9 +355,11 @@ sub cgi_editpage ($$) { #{{{
                });
                $form->tmpl_param("page_preview",
                        htmlize($page, $type,
-                       linkify($page, "",
+                       linkify($page, $page,
                        preprocess($page, $page,
                        filter($page, $page, $content), 0, 1))));
+               # previewing may have created files on disk
+               saveindex();
        }
        elsif ($form->submitted eq "Save Page") {
                $form->tmpl_param("page_preview", "");
@@ -392,9 +395,10 @@ sub cgi_editpage ($$) { #{{{
                                        $dir=~s![^/]+/+$!!;
                                        push @page_locs, $dir.$page;
                                }
+                       
+                               push @page_locs, "$config{userdir}/$page"
+                                       if length $config{userdir};
                        }
-                       push @page_locs, "$config{userdir}/$page"
-                               if length $config{userdir};
 
                        @page_locs = grep {
                                ! exists $pagecase{lc $_}
@@ -402,8 +406,16 @@ sub cgi_editpage ($$) { #{{{
                        if (! @page_locs) {
                                # hmm, someone else made the page in the
                                # meantime?
-                               redirect($q, "$config{url}/".htmlpage($page));
-                               return;
+                               if ($form->submitted eq "Preview") {
+                                       # let them go ahead with the edit
+                                       # and resolve the conflict at save
+                                       # time
+                                       @page_locs=$page;
+                               }
+                               else {
+                                       redirect($q, "$config{url}/".htmlpage($page));
+                                       return;
+                               }
                        }
 
                        my @editable_locs = grep {
@@ -447,8 +459,7 @@ sub cgi_editpage ($$) { #{{{
                        $form->title(sprintf(gettext("editing %s"), pagetitle($page)));
                }
                
-               showform($form, \@buttons, $session, $q);
-               saveindex();
+               showform($form, \@buttons, $session, $q, forcebaseurl => $baseurl);
        }
        else {
                # save page
@@ -464,7 +475,7 @@ sub cgi_editpage ($$) { #{{{
                        $form->field(name => "page", type => 'hidden');
                        $form->field(name => "type", type => 'hidden');
                        $form->title(sprintf(gettext("editing %s"), $page));
-                       showform($form, \@buttons, $session, $q);
+                       showform($form, \@buttons, $session, $q, forcebaseurl => $baseurl);
                        return;
                }
                elsif ($form->field("do") eq "create" && $exists) {
@@ -478,7 +489,7 @@ sub cgi_editpage ($$) { #{{{
                                value => readfile("$config{srcdir}/$file").
                                         "\n\n\n".$form->field("editcontent"),
                                force => 1);
-                       showform($form, \@buttons, $session, $q);
+                       showform($form, \@buttons, $session, $q, forcebaseurl => $baseurl);
                        return;
                }
                
@@ -508,7 +519,8 @@ sub cgi_editpage ($$) { #{{{
                        $form->field(name => "page", type => 'hidden');
                        $form->field(name => "type", type => 'hidden');
                        $form->title(sprintf(gettext("editing %s"), $page));
-                       showform($form, \@buttons, $session, $q);
+                       showform($form, \@buttons, $session, $q,
+                               forcebaseurl => $baseurl);
                        return;
                }
                
@@ -552,7 +564,8 @@ sub cgi_editpage ($$) { #{{{
                        $form->field(name => "page", type => 'hidden');
                        $form->field(name => "type", type => 'hidden');
                        $form->title(sprintf(gettext("editing %s"), $page));
-                       showform($form, \@buttons, $session, $q);
+                       showform($form, \@buttons, $session, $q,
+                               forcebaseurl => $baseurl);
                        return;
                }
                else {