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(
56 IkiWiki::misctemplate(gettext("missing page"),
58 sprintf(gettext("The page %s does not exist."),
59 htmllink("", "", $page)).
64 IkiWiki::redirect($q, urlto($link, undef, 1));
72 my $do = $cgi->param('do');
74 if (defined $do && ($do eq 'goto' || $do eq 'commenter' ||
75 $do eq 'recentchanges_link')) {
76 # goto is the preferred name for this; recentchanges_link and
77 # commenter are for compatibility with any saved URLs