X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/841617c9ff35d25dd7a89f6905a67a911c22e430..dd464e4ca84f5305c19faa375dbded8f4ce8cc3b:/IkiWiki/CGI.pm

diff --git a/IkiWiki/CGI.pm b/IkiWiki/CGI.pm
index cfb2c0b1d..470677088 100644
--- a/IkiWiki/CGI.pm
+++ b/IkiWiki/CGI.pm
@@ -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) {
@@ -343,6 +344,12 @@ sub cgi_editpage ($$) { #{{{
 		return;
 	}
 	elsif ($form->submitted eq "Preview") {
+		my $new=not exists $pagesources{$page};
+		if ($new) {
+			# temporarily record its type
+			$pagesources{$page}=$page.".".$type;
+		}
+
 		my $content=$form->field('editcontent');
 		run_hooks(editcontent => sub {
 			$content=shift->(
@@ -354,9 +361,13 @@ 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))));
+		
+		if ($new) {
+			delete $pagesources{$page};
+		}
 		# previewing may have created files on disk
 		saveindex();
 	}
@@ -458,7 +469,7 @@ sub cgi_editpage ($$) { #{{{
 			$form->title(sprintf(gettext("editing %s"), pagetitle($page)));
 		}
 		
-		showform($form, \@buttons, $session, $q);
+		showform($form, \@buttons, $session, $q, forcebaseurl => $baseurl);
 	}
 	else {
 		# save page
@@ -474,7 +485,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) {
@@ -488,7 +499,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;
 		}
 		
@@ -518,7 +529,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;
 		}
 		
@@ -562,7 +574,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 {