From c886bea32084a920f3ba26b3f96327681f5db917 Mon Sep 17 00:00:00 2001
From: Simon McVittie
Date: Sat, 31 Jan 2009 23:01:10 +0000
Subject: Split cgi_goto into a goto plugin
---
IkiWiki/Plugin/goto.pm | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 76 insertions(+)
create mode 100644 IkiWiki/Plugin/goto.pm
(limited to 'IkiWiki/Plugin/goto.pm')
diff --git a/IkiWiki/Plugin/goto.pm b/IkiWiki/Plugin/goto.pm
new file mode 100644
index 000000000..9e7a2621f
--- /dev/null
+++ b/IkiWiki/Plugin/goto.pm
@@ -0,0 +1,76 @@
+#!/usr/bin/perl
+package IkiWiki::Plugin::goto;
+
+use warnings;
+use strict;
+use IkiWiki 3.00;
+
+sub import {
+ hook(type => "cgi", id => 'goto', call => \&cgi);
+}
+
+sub getsetup () {
+ return
+ plugin => {
+ safe => 1,
+ rebuild => 0,
+ }
+}
+
+# cgi_goto(CGI, [page])
+# Redirect to a specified page, or display "not found". If not specified,
+# the page param from the CGI object is used.
+sub cgi_goto ($;$) {
+ my $q = shift;
+ my $page = shift;
+
+ if (!defined $page) {
+ $page = IkiWiki::decode_utf8($q->param("page"));
+
+ if (!defined $page) {
+ error("missing page parameter");
+ }
+ }
+
+ IkiWiki::loadindex();
+
+ # If the page is internal (like a comment), see if it has a
+ # permalink. Comments do.
+ if (IkiWiki::isinternal($page) &&
+ defined $pagestate{$page}{meta}{permalink}) {
+ redirect($q, $pagestate{$page}{meta}{permalink});
+ }
+
+ my $link = bestlink("", $page);
+
+ if (! length $link) {
+ print $q->header(-status => "404 Not Found");
+ print IkiWiki::misctemplate(gettext("missing page"),
+ "
".
+ sprintf(gettext("The page %s does not exist."),
+ htmllink("", "", $page)).
+ "
".
+ # Internet Explorer won't show custom 404 responses
+ # unless they're >= 512 bytes
+ (" " x 512));
+ }
+ else {
+ IkiWiki::redirect($q, urlto($link, undef, 1));
+ }
+
+ exit;
+}
+
+sub cgi ($) {
+ my $cgi=shift;
+ my $do = $cgi->param('do');
+
+ if (defined $do && ($do eq 'goto' || $do eq 'commenter' ||
+ $do eq 'recentchanged_link')) {
+ # goto is the preferred name for this; recentchanges_link and
+ # commenter are for compatibility with any saved URLs
+ cgi_goto($cgi);
+ }
+}
+
+1;
--
cgit v1.2.3
From b0361b8efde26fbf4f3207be6c3c8f39eb16a9f3 Mon Sep 17 00:00:00 2001
From: Joey Hess
Date: Sat, 31 Jan 2009 19:02:50 -0500
Subject: factor out IE stupididy workaround
---
IkiWiki/CGI.pm | 23 +++++++++++++++++------
IkiWiki/Plugin/goto.pm | 17 ++++++++---------
2 files changed, 25 insertions(+), 15 deletions(-)
(limited to 'IkiWiki/Plugin/goto.pm')
diff --git a/IkiWiki/CGI.pm b/IkiWiki/CGI.pm
index c91914564..3000ed100 100644
--- a/IkiWiki/CGI.pm
+++ b/IkiWiki/CGI.pm
@@ -229,6 +229,20 @@ sub cgi_prefs ($$) {
showform($form, $buttons, $session, $q);
}
+sub cgi_custom_failure ($$) {
+ my $header=shift;
+ my $message=shift;
+
+ print $header;
+ print $message;
+
+ # Internet Explod^Hrer won't show custom 404 responses
+ # unless they're >= 512 bytes
+ print ' ' x 512;
+
+ exit;
+}
+
sub check_banned ($$) {
my $q=shift;
my $session=shift;
@@ -236,14 +250,11 @@ sub check_banned ($$) {
my $name=$session->param("name");
if (defined $name) {
if (grep { $name eq $_ } @{$config{banned_users}}) {
- print $q->header(-status => "403 Forbidden");
$session->delete();
- print gettext("You are banned.");
- # Internet Explorer won't show custom 404 responses
- # unless they're >= 512 bytes
- print " " x 512;
cgi_savesession($session);
- exit;
+ cgi_custom_failure(
+ $q->header(-status => "403 Forbidden"),
+ gettext("You are banned."));
}
}
}
diff --git a/IkiWiki/Plugin/goto.pm b/IkiWiki/Plugin/goto.pm
index 9e7a2621f..7cc8cb484 100644
--- a/IkiWiki/Plugin/goto.pm
+++ b/IkiWiki/Plugin/goto.pm
@@ -44,15 +44,14 @@ sub cgi_goto ($;$) {
my $link = bestlink("", $page);
if (! length $link) {
- print $q->header(-status => "404 Not Found");
- print IkiWiki::misctemplate(gettext("missing page"),
- "".
- sprintf(gettext("The page %s does not exist."),
- htmllink("", "", $page)).
- "
".
- # Internet Explorer won't show custom 404 responses
- # unless they're >= 512 bytes
- (" " x 512));
+ IkiWiki::cgi_custom_failure(
+ $q->header(-status => "404 Not Found"),
+ IkiWiki::misctemplate(gettext("missing page"),
+ "".
+ sprintf(gettext("The page %s does not exist."),
+ htmllink("", "", $page)).
+ "
")
+ )
}
else {
IkiWiki::redirect($q, urlto($link, undef, 1));
--
cgit v1.2.3
From 52f2235e6072bfb2e39a52bd8c106ae890ba4a5a Mon Sep 17 00:00:00 2001
From: Joey Hess
Date: Tue, 17 Feb 2009 19:36:58 -0500
Subject: goto: Fix redirect to comments.
---
IkiWiki/Plugin/goto.pm | 2 +-
debian/changelog | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)
(limited to 'IkiWiki/Plugin/goto.pm')
diff --git a/IkiWiki/Plugin/goto.pm b/IkiWiki/Plugin/goto.pm
index 7cc8cb484..4fd1471e9 100644
--- a/IkiWiki/Plugin/goto.pm
+++ b/IkiWiki/Plugin/goto.pm
@@ -38,7 +38,7 @@ sub cgi_goto ($;$) {
# permalink. Comments do.
if (IkiWiki::isinternal($page) &&
defined $pagestate{$page}{meta}{permalink}) {
- redirect($q, $pagestate{$page}{meta}{permalink});
+ Ikiwiki::redirect($q, $pagestate{$page}{meta}{permalink});
}
my $link = bestlink("", $page);
diff --git a/debian/changelog b/debian/changelog
index c28d36c84..b644ac99c 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -5,6 +5,7 @@ ikiwiki (3.05) UNRELEASED; urgency=low
This is potentially expensive, but is necessary so that meta and tag
directives, and other links on templates affect the page using the
template reliably.
+ * goto: Fix redirect to comments.
-- Joey Hess Sun, 15 Feb 2009 20:11:57 -0500
--
cgit v1.2.3
From 5f96944dd5ad099d96adbf0273b4dc7d1da98829 Mon Sep 17 00:00:00 2001
From: Joey Hess
Date: Tue, 17 Feb 2009 19:37:36 -0500
Subject: typo
---
IkiWiki/Plugin/goto.pm | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'IkiWiki/Plugin/goto.pm')
diff --git a/IkiWiki/Plugin/goto.pm b/IkiWiki/Plugin/goto.pm
index 4fd1471e9..06ec0bdca 100644
--- a/IkiWiki/Plugin/goto.pm
+++ b/IkiWiki/Plugin/goto.pm
@@ -38,7 +38,7 @@ sub cgi_goto ($;$) {
# permalink. Comments do.
if (IkiWiki::isinternal($page) &&
defined $pagestate{$page}{meta}{permalink}) {
- Ikiwiki::redirect($q, $pagestate{$page}{meta}{permalink});
+ IkiWiki::redirect($q, $pagestate{$page}{meta}{permalink});
}
my $link = bestlink("", $page);
--
cgit v1.2.3
From affd4ca3daa8da233d915516fb668c8f99fffe51 Mon Sep 17 00:00:00 2001
From: Joey Hess
Date: Fri, 27 Feb 2009 13:21:29 -0500
Subject: goto: Fix typo that broke recentchanges_link compatability.
---
IkiWiki/Plugin/goto.pm | 2 +-
debian/changelog | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)
(limited to 'IkiWiki/Plugin/goto.pm')
diff --git a/IkiWiki/Plugin/goto.pm b/IkiWiki/Plugin/goto.pm
index 06ec0bdca..3f40c5859 100644
--- a/IkiWiki/Plugin/goto.pm
+++ b/IkiWiki/Plugin/goto.pm
@@ -65,7 +65,7 @@ sub cgi ($) {
my $do = $cgi->param('do');
if (defined $do && ($do eq 'goto' || $do eq 'commenter' ||
- $do eq 'recentchanged_link')) {
+ $do eq 'recentchanges_link')) {
# goto is the preferred name for this; recentchanges_link and
# commenter are for compatibility with any saved URLs
cgi_goto($cgi);
diff --git a/debian/changelog b/debian/changelog
index 90b672e8d..0b1eec6cf 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -12,6 +12,7 @@ ikiwiki (3.05) UNRELEASED; urgency=low
* Setup automator: Prompt for password twice. Closes: #516973
* bzr: Add missing rcs_diff. (liw)
* comments: Avoid showing comment moderation button in prefs to non-admins.
+ * goto: Fix typo that broke recentchanges_link compatability.
-- Joey Hess Sun, 15 Feb 2009 20:11:57 -0500
--
cgit v1.2.3