2 package IkiWiki::Plugin::goto;
9 hook(type => "cgi", id => 'goto', call => \&cgi);
21 # cgi_goto(CGI, [page])
22 # Redirect to a specified page, or display "not found". If not specified,
23 # the page param from the CGI object is used.
29 $page = IkiWiki::decode_utf8($q->param("page"));
32 error("missing page parameter");
36 # It's possible that $page is not a valid page name;
37 # if so attempt to turn it into one.
38 if ($page !~ /$config{wiki_file_regexp}/) {
39 $page=titlepage($page);
44 # If the page is internal (like a comment), see if it has a
45 # permalink. Comments do.
46 if (IkiWiki::isinternal($page) &&
47 defined $pagestate{$page}{meta}{permalink}) {
48 IkiWiki::redirect($q, $pagestate{$page}{meta}{permalink});
51 my $link = bestlink("", $page);
54 IkiWiki::cgi_custom_failure(
57 IkiWiki::misctemplate(gettext("missing page"),
59 sprintf(gettext("The page %s does not exist."),
60 htmllink("", "", $page)).
65 IkiWiki::redirect($q, urlto($link, undef, 1));
73 my $do = $cgi->param('do');
75 if (defined $do && ($do eq 'goto' || $do eq 'commenter' ||
76 $do eq 'recentchanges_link')) {
77 # goto is the preferred name for this; recentchanges_link and
78 # commenter are for compatibility with any saved URLs