]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/CGI.pm
oops
[ikiwiki.git] / IkiWiki / CGI.pm
index ede194ff9aee945dc0fb471bedaa47bf93eda829..e8850cc548174efaa630b35a8578db3dc8772e3b 100644 (file)
@@ -49,10 +49,36 @@ sub showform ($$$$;@) {
        print misctemplate($form->title, $form->render(submit => $buttons), @_);
 }
 
+# Like showform, but the base url will be set to allow edit previews
+# that use links relative to the specified page.
+sub showform_preview ($$$$;@) {
+       my $form=shift;
+       my $buttons=shift;
+       my $session=shift;
+       my $cgi=shift;
+       my %params=@_;
+
+       # The base url needs to be a full URL, and urlto may return a path.
+       my $baseurl = absurl(urlto($params{page}), $cgi);
+
+       showform($form, $buttons, $session, $cgi, @_,
+               forcebaseurl => $baseurl);
+}
+
+# Forces a partial url (path only) to absolute, using the same
+# URL scheme as the CGI. Full URLs are left unchanged.
+sub absurl ($$) {
+       my $partialurl=shift;
+       my $q=shift;
+
+       eval q{use URI};
+       return URI->new_abs($partialurl, $q->url);
+}
+
 sub redirect ($$) {
        my $q=shift;
        eval q{use URI};
-       my $url=URI->new(shift);
+       my $url=URI->new(absurl(shift, $q));
        if (! $config{w3mmode}) {
                print $q->redirect($url);
        }