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();
if ($IkiWiki::pagesources{$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;
if (! exists $IkiWiki::pagesources{$page}) {
IkiWiki::cgi_custom_failure(
$cgi->header(-status => "404 Not Found"),
IkiWiki::misctemplate(gettext("missing page"),
"<p>".
sprintf(gettext("The page %s does not exist."),
htmllink("", "", $page)).
"</p>"));
exit;
}
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;
}