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");
35 # It's possible that $page is not a valid page name;
36 # if so attempt to turn it into one.
37 if ($page !~ /$config{wiki_file_regexp}/) {
38 $page=titlepage($page);
43 # If the page is internal (like a comment), see if it has a
44 # permalink. Comments do.
45 if (IkiWiki::isinternal($page) &&
46 defined $pagestate{$page}{meta}{permalink}) {
47 IkiWiki::redirect($q, $pagestate{$page}{meta}{permalink});
50 my $link = bestlink("", $page);
53 IkiWiki::cgi_custom_failure(
54 $q->header(-status => "404 Not Found"),
55 IkiWiki::misctemplate(gettext("missing page"),
57 sprintf(gettext("The page %s does not exist."),
58 htmllink("", "", $page)).
63 IkiWiki::redirect($q, urlto($link, undef, 1));
71 my $do = $cgi->param('do');
73 if (defined $do && ($do eq 'goto' || $do eq 'commenter' ||
74 $do eq 'recentchanges_link')) {
75 # goto is the preferred name for this; recentchanges_link and
76 # commenter are for compatibility with any saved URLs