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);
45 if (! IkiWiki::isinternal($page)) {
46 $link = bestlink("", $page);
48 elsif (defined $pagestate{$page}{meta}{permalink}) {
49 # Can only redirect to an internal page if it has a
51 IkiWiki::redirect($q, $pagestate{$page}{meta}{permalink});
55 IkiWiki::cgi_custom_failure(
58 IkiWiki::misctemplate(gettext("missing page"),
60 sprintf(gettext("The page %s does not exist."),
61 htmllink("", "", $page)).
66 IkiWiki::redirect($q, urlto($link, undef, 1));
74 my $do = $cgi->param('do');
76 if (defined $do && ($do eq 'goto' || $do eq 'commenter' ||
77 $do eq 'recentchanges_link')) {
78 # goto is the preferred name for this; recentchanges_link and
79 # commenter are for compatibility with any saved URLs