2 package IkiWiki::Plugin::goto;
9 hook(type => "cgi", id => 'goto', call => \&cgi);
10 hook(type => "getsetup", id => 'goto', call => \&getsetup);
22 # cgi_goto(CGI, [page])
23 # Redirect to a specified page, or display "not found". If not specified,
24 # the page param from the CGI object is used.
30 $page = IkiWiki::decode_utf8($q->param("page"));
33 error("missing page parameter");
37 # It's possible that $page is not a valid page name;
38 # if so attempt to turn it into one.
39 if ($page !~ /$config{wiki_file_regexp}/) {
40 $page=titlepage($page);
46 if (! IkiWiki::isinternal($page)) {
47 $link = bestlink("", $page);
49 elsif (defined $pagestate{$page}{meta}{permalink}) {
50 # Can only redirect to an internal page if it has a
52 IkiWiki::redirect($q, $pagestate{$page}{meta}{permalink});
55 if (! defined $link || ! length $link) {
56 IkiWiki::cgi_custom_failure(
59 IkiWiki::misctemplate(gettext("missing page"),
61 sprintf(gettext("The page %s does not exist."),
62 htmllink("", "", $page)).
67 IkiWiki::redirect($q, urlto($link, undef, 1));
75 my $do = $cgi->param('do');
77 if (defined $do && ($do eq 'goto' || $do eq 'commenter' ||
78 $do eq 'recentchanges_link')) {
79 # goto is the preferred name for this; recentchanges_link and
80 # commenter are for compatibility with any saved URLs