getsource: turn missing pages into a 404

Also restructure so we return early on missing pages.
master
Simon McVittie 2009-07-26 16:45:01 +01:00
parent 3f520da78a
commit 0afcec7346
1 changed files with 21 additions and 17 deletions

View File

@ -55,25 +55,29 @@ sub cgi_getsource ($) {
IkiWiki::loadindex(); IkiWiki::loadindex();
if ($IkiWiki::pagesources{$page}) { if (! exists $IkiWiki::pagesources{$page}) {
IkiWiki::cgi_custom_failure(
my $data = IkiWiki::readfile(IkiWiki::srcfile($IkiWiki::pagesources{$page})); $cgi->header(-status => "404 Not Found"),
IkiWiki::misctemplate(gettext("missing page"),
if (! $config{getsource_mimetype}) { "<p>".
$config{getsource_mimetype} = "text/plain; charset=utf-8"; sprintf(gettext("The page %s does not exist."),
} htmllink("", "", $page)).
"</p>"));
print "Content-Type: $config{getsource_mimetype}\r\n"; exit;
print ("\r\n");
print $data;
exit 0;
} }
error("Unable to find page source for page: $page");
my $data = IkiWiki::readfile(IkiWiki::srcfile($IkiWiki::pagesources{$page}));
if (! $config{getsource_mimetype}) {
$config{getsource_mimetype} = "text/plain; charset=utf-8";
}
print "Content-Type: $config{getsource_mimetype}\r\n";
print ("\r\n");
print $data;
exit 0; exit 0;
} }