From 2c784773879b228b7dfec2c6d092c9e1e98ab97b Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 8 Dec 2007 14:58:29 -0500 Subject: * meta: Add redir support, based on a patch by Thomas Schwinge. --- IkiWiki/Plugin/meta.pm | 50 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 20 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm index cfa4b84b1..134c0ce5d 100644 --- a/IkiWiki/Plugin/meta.pm +++ b/IkiWiki/Plugin/meta.pm @@ -13,6 +13,7 @@ my %author; my %authorurl; my %license; my %copyright; +my %redirected; sub import { #{{{ hook(type => "preprocess", id => "meta", call => \&preprocess, scan => 1); @@ -59,7 +60,9 @@ sub preprocess (@) { #{{{ if ($key eq 'link') { if (%params) { $meta{$page}.=scrub("\n"); } else { @@ -67,6 +70,32 @@ sub preprocess (@) { #{{{ push @{$links{$page}}, $value; } } + elsif ($key eq 'redir') { + $redirected{$page}=1; + my $safe=0; + if ($value =~ /^$config{wiki_link_regexp}$/) { + my $link=bestlink($page, $value); + if (! length $link) { + return "[[meta ".gettext("redir page not found")."]]"; + } + if ($redirected{$link}) { + # TODO this is a cheap way of avoiding + # redir cycles, but it is really too strict. + return "[[meta ".gettext("redir to page that itself redirs is not allowed")."]]"; + } + $value=urlto($link, $destpage); + $safe=1; + } + else { + $value=encode_entities($value); + } + my $delay=int(exists $params{delay} ? $params{delay} : 0); + my $redir=""; + if (! $safe) { + $redir=scrub($redir); + } + $meta{$page}.=$redir; + } elsif ($key eq 'title') { $title{$page}=HTML::Entities::encode_numeric($value); } @@ -111,25 +140,6 @@ sub preprocess (@) { #{{{ $meta{$page}.="\n"; $copyright{$page}=$value; } - elsif ($key eq 'forward') { - my $delay=0; - my $dest_url; - my $text; - if (exists $params{delay}) { - $delay=$params{delay}; - } - # Is this a wikilink? - if ($value =~ /^\[\[(.*)\]\]$/) { - $text=htmllink($page, $destpage, $1); - $dest_url=urlto(bestlink($page, $1), $destpage); - } else { - $text="$dest_url"; - $dest_url=$value; - } -# TODO. $meta{$page}.=scrub(""); - $meta{$page}.=""; - return "You are being forwarded to $text."; - } else { $meta{$page}.=scrub("\n"); -- cgit v1.2.3