factored out an urlabs from aggregate and cgi
authorJoey Hess <joey@kitenet.net>
Wed, 5 Jan 2011 20:18:25 +0000 (16:18 -0400)
committerJoey Hess <joey@kitenet.net>
Wed, 5 Jan 2011 20:18:25 +0000 (16:18 -0400)
IkiWiki.pm
IkiWiki/CGI.pm
IkiWiki/Plugin/aggregate.pm

index e963471e41c766d1ddfb92c9f54c282acf57b7b5..ef8ccb2da51e4b763418344237280cf563011fba 100644 (file)
@@ -1068,6 +1068,14 @@ sub baseurl (;$) {
        return $page;
 }
 
+sub urlabs ($$) {
+       my $url=shift;
+       my $urlbase=shift;
+
+       eval q{use URI};
+       URI->new_abs($url, $urlbase)->as_string;
+}
+
 sub abs2rel ($$) {
        # Work around very innefficient behavior in File::Spec if abs2rel
        # is passed two relative paths. It's much faster if paths are
index e8850cc548174efaa630b35a8578db3dc8772e3b..f1bec6b8fc3a7d18f02a1b7ee2bacbe990af7381 100644 (file)
@@ -59,26 +59,16 @@ sub showform_preview ($$$$;@) {
        my %params=@_;
 
        # The base url needs to be a full URL, and urlto may return a path.
-       my $baseurl = absurl(urlto($params{page}), $cgi);
+       my $baseurl = urlabs(urlto($params{page}), $cgi->url);
 
        showform($form, $buttons, $session, $cgi, @_,
                forcebaseurl => $baseurl);
 }
 
-# Forces a partial url (path only) to absolute, using the same
-# URL scheme as the CGI. Full URLs are left unchanged.
-sub absurl ($$) {
-       my $partialurl=shift;
-       my $q=shift;
-
-       eval q{use URI};
-       return URI->new_abs($partialurl, $q->url);
-}
-
 sub redirect ($$) {
        my $q=shift;
        eval q{use URI};
-       my $url=URI->new(absurl(shift, $q));
+       my $url=URI->new(urlabs(shift, $q->url));
        if (! $config{w3mmode}) {
                print $q->redirect($url);
        }
index 9b70e5df053731866c5ad7a494432e6e0b72b4bc..59185e97ffdd43eb283fbbf2d454cbbb40b3d894 100644 (file)
@@ -8,7 +8,6 @@ use IkiWiki 3.00;
 use HTML::Parser;
 use HTML::Tagset;
 use HTML::Entities;
-use URI;
 use open qw{:utf8 :std};
 
 my %feeds;
@@ -660,7 +659,7 @@ sub add_page (@) {
        $template->param(url => $feed->{url});
        $template->param(copyright => $params{copyright})
                if defined $params{copyright} && length $params{copyright};
-       $template->param(permalink => urlabs($params{link}, $feed->{feedurl}))
+       $template->param(permalink => IkiWiki::urlabs($params{link}, $feed->{feedurl}))
                if defined $params{link};
        if (ref $feed->{tags}) {
                $template->param(tags => [map { tag => $_ }, @{$feed->{tags}}]);
@@ -688,13 +687,6 @@ sub wikiescape ($) {
        return encode_entities(shift, '\[\]');
 }
 
-sub urlabs ($$) {
-       my $url=shift;
-       my $urlbase=shift;
-
-       URI->new_abs($url, $urlbase)->as_string;
-}
-
 sub htmlabs ($$) {
        # Convert links in html from relative to absolute.
        # Note that this is a heuristic, which is not specified by the rss
@@ -720,7 +712,7 @@ sub htmlabs ($$) {
                                next unless $v_offset; # 0 v_offset means no value
                                my $v = substr($text, $v_offset, $v_len);
                                $v =~ s/^([\'\"])(.*)\1$/$2/;
-                               my $new_v=urlabs($v, $urlbase);
+                               my $new_v=IkiWiki::urlabs($v, $urlbase);
                                $new_v =~ s/\"/&quot;/g; # since we quote with ""
                                substr($text, $v_offset, $v_len) = qq("$new_v");
                        }