+
+ # For %pagesources.
+ IkiWiki::loadindex();
+
+ if (! exists $pagesources{$page}) {
+ IkiWiki::cgi_custom_failure(
+ $cgi,
+ "404 Not Found",
+ IkiWiki::cgitemplate($cgi, gettext("missing page"),
+ "<p>".
+ sprintf(gettext("The page %s does not exist."),
+ htmllink("", "", $page)).
+ "</p>"));
+ exit;
+ }
+
+ if (! defined pagetype($pagesources{$page})) {
+ IkiWiki::cgi_custom_failure(
+ $cgi->header(-status => "403 Forbidden"),
+ IkiWiki::cgitemplate($cgi, gettext("not a page"),
+ "<p>".
+ sprintf(gettext("%s is an attachment, not a page."),
+ htmllink("", "", $page)).
+ "</p>"));
+ exit;
+ }
+
+ if (! $config{getsource_mimetype}) {
+ $config{getsource_mimetype} = "text/plain; charset=utf-8";
+ }
+
+ print "Content-Type: $config{getsource_mimetype}\r\n";
+ print ("\r\n");
+ print readfile(srcfile($pagesources{$page}));