getsource: turn missing pages into a 404
authorSimon McVittie <smcv@ http://smcv.pseudorandom.co.uk/>
Sun, 26 Jul 2009 15:45:01 +0000 (16:45 +0100)
committerSimon McVittie <smcv@ http://smcv.pseudorandom.co.uk/>
Sun, 26 Jul 2009 16:04:30 +0000 (17:04 +0100)
Also restructure so we return early on missing pages.

IkiWiki/Plugin/getsource.pm

index 08d9d110cbdffc0f816dc6e834bbdc98495c56af..6a208f1e735d19791da4c5a0821fc124e9bee3a7 100644 (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;
+       }
+
+       my $data = IkiWiki::readfile(IkiWiki::srcfile($IkiWiki::pagesources{$page}));
+
+       if (! $config{getsource_mimetype}) {
+               $config{getsource_mimetype} = "text/plain; charset=utf-8";
        }
-       
-       error("Unable to find page source for page: $page");
 
+       print "Content-Type: $config{getsource_mimetype}\r\n";
+
+       print ("\r\n");
+
+       print $data;
+       
        exit 0;
 }