]> sipb.mit.edu Git - ikiwiki.git/commitdiff
* meta: Add redir support, based on a patch by Thomas Schwinge.
authorJoey Hess <joey@kitenet.net>
Sat, 8 Dec 2007 19:58:29 +0000 (14:58 -0500)
committerJoey Hess <joey@kitenet.net>
Sat, 8 Dec 2007 19:58:29 +0000 (14:58 -0500)
IkiWiki/Plugin/meta.pm
debian/changelog
doc/plugins/meta.mdwn
doc/todo/__42__forward__42__ing_functionality_for_the_meta_plugin.mdwn

index cfa4b84b1d9d92382a28e60ae54501683c5dff31..134c0ce5d1065f5520407c2d671c52073c569040 100644 (file)
@@ -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("<link href=\"".encode_entities($value)."\" ".
-                               join(" ", map { encode_entities($_)."=\"".encode_entities(decode_entities($params{$_}))."\"" } keys %params).
+                               join(" ", map {
+                                       encode_entities($_)."=\"".encode_entities(decode_entities($params{$_}))."\""
+                               } keys %params).
                                " />\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="<meta http-equiv=\"refresh\" content=\"$delay; URL=$value\">";
+               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}.="<link rel=\"copyright\" href=\"#page_copyright\" />\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="<a href=\"$dest_url\">$dest_url</a>";
-                       $dest_url=$value;
-               }
-# TODO.                $meta{$page}.=scrub("<meta http-equiv=\"refresh\" content=\"$delay; URL=$dest_url\">");
-               $meta{$page}.="<meta http-equiv=\"refresh\" content=\"$delay; URL=$dest_url\">";
-               return "You are being forwarded to $text.";
-       }
        else {
                $meta{$page}.=scrub("<meta name=\"".encode_entities($key).
                        "\" content=\"".encode_entities($value)."\" />\n");
index 5e2944152137f3eceb88d06cf3ae4f8214c2616e..f23b77813964676d9f6b6be111578cfad2371e33 100644 (file)
@@ -1,6 +1,7 @@
 ikiwiki (2.16) UNRELEASED; urgency=low
 
   * Remove .otl file from sandbox to avoid build ugliness. Closes: #454181
+  * meta: Add redir support, based on a patch by Thomas Schwinge.
 
  -- Joey Hess <joeyh@debian.org>  Mon, 03 Dec 2007 14:47:36 -0500
 
index 0937667089d930715fe41e38e4d8653ccd44482d..073482a4c31ff55bfd329676913fdabbeb7f8d53 100644 (file)
@@ -30,6 +30,22 @@ You can use any field names you like, but here are some predefined ones:
   However, this latter syntax won't be allowed if the [[htmlscrubber]] is
   enabled, since it can be used to insert unsafe content.
 
+* redir
+
+  Causes the page to redirect to another page in the wiki.
+
+       \[[meta redir=otherpage]]
+
+  Optionally, a delay (in seconds) can be specified. The default is to
+  redirect without delay.
+
+  It can also be used to redirect to an external url. For example:
+
+       \[[meta redir="http://example.com/"]]
+
+  However, this latter syntax won't be allowed if the [[htmlscrubber]] is
+  enabled, since it can be used to insert unsafe content.
+
 * title
 
   Overrides the title of the page, which is generally the same as the
index c3c2b82f316f36502bd554967aac75eae9fb2d1f..b584341c66123ae1d1bfdff31c723a3e8c0cbe14 100644 (file)
@@ -1,6 +1,8 @@
 Here is a patch [[tag patch]] to add a *forward*ing functionality
 to the [[`meta`_plugin|plugins/meta]].
 
+> [[done]], with some changes --[[Joey]]
+
 Find the most recent version at
 <http://www.schwinge.homeip.net/~thomas/tmp/meta_forward.patch>.