2 package IkiWiki::Plugin::goto;
9 hook(type => "cgi", id => 'goto', call => \&cgi);
20 # cgi_goto(CGI, [page])
21 # Redirect to a specified page, or display "not found". If not specified,
22 # the page param from the CGI object is used.
28 $page = IkiWiki::decode_utf8($q->param("page"));
31 error("missing page parameter");
37 # If the page is internal (like a comment), see if it has a
38 # permalink. Comments do.
39 if (IkiWiki::isinternal($page) &&
40 defined $pagestate{$page}{meta}{permalink}) {
41 redirect($q, $pagestate{$page}{meta}{permalink});
44 my $link = bestlink("", $page);
47 print $q->header(-status => "404 Not Found");
48 print IkiWiki::misctemplate(gettext("missing page"),
50 sprintf(gettext("The page %s does not exist."),
51 htmllink("", "", $page)).
53 # Internet Explorer won't show custom 404 responses
54 # unless they're >= 512 bytes
58 IkiWiki::redirect($q, urlto($link, undef, 1));
66 my $do = $cgi->param('do');
68 if (defined $do && ($do eq 'goto' || $do eq 'commenter' ||
69 $do eq 'recentchanged_link')) {
70 # goto is the preferred name for this; recentchanges_link and
71 # commenter are for compatibility with any saved URLs