aboutsummaryrefslogtreecommitdiff
path: root/IkiWiki.pm
diff options
context:
space:
mode:
authorJoey Hess <joey@kitenet.net>2010-11-29 14:43:57 -0400
committerJoey Hess <joey@kitenet.net>2010-11-29 14:43:57 -0400
commit0ae1e4cc0e598eacfeb508d11db81c33169631fd (patch)
treef779fd1bd4b4eaae315473ea70f9c1e85a7981d1 /IkiWiki.pm
parentb3f7c6a9a579208f555a9ae7a409474d68897d04 (diff)
parent18bb93f5744c1b57b929d9f8a6042e51fc5256f0 (diff)
downloadikiwiki-0ae1e4cc0e598eacfeb508d11db81c33169631fd.tar
ikiwiki-0ae1e4cc0e598eacfeb508d11db81c33169631fd.tar.gz
Merge remote branch 'smcv/ready/localurl'
Diffstat (limited to 'IkiWiki.pm')
-rw-r--r--IkiWiki.pm50
1 files changed, 47 insertions, 3 deletions
diff --git a/IkiWiki.pm b/IkiWiki.pm
index c06751dd3..a893edb3b 100644
--- a/IkiWiki.pm
+++ b/IkiWiki.pm
@@ -501,6 +501,12 @@ sub defaultconfig () {
return @ret;
}
+# URL to top of wiki as a path starting with /, valid from any wiki page or
+# the CGI; if that's not possible, an absolute URL. Either way, it ends with /
+my $local_url;
+# URL to CGI script, similar to $local_url
+my $local_cgiurl;
+
sub checkconfig () {
# locale stuff; avoid LC_ALL since it overrides everything
if (defined $ENV{LC_ALL}) {
@@ -537,7 +543,33 @@ sub checkconfig () {
if ($config{cgi} && ! length $config{url}) {
error(gettext("Must specify url to wiki with --url when using --cgi"));
}
-
+
+ if (length $config{url}) {
+ eval q{use URI};
+ my $baseurl = URI->new($config{url});
+
+ $local_url = $baseurl->path . "/";
+ $local_cgiurl = undef;
+
+ if (length $config{cgiurl}) {
+ my $cgiurl = URI->new($config{cgiurl});
+
+ $local_cgiurl = $cgiurl->path;
+
+ if ($cgiurl->scheme ne $baseurl->scheme or
+ $cgiurl->authority ne $baseurl->authority) {
+ # too far apart, fall back to absolute URLs
+ $local_url = "$config{url}/";
+ $local_cgiurl = $config{cgiurl};
+ }
+ }
+
+ $local_url =~ s{//$}{/};
+ }
+ else {
+ $local_cgiurl = $config{cgiurl};
+ }
+
$config{wikistatedir}="$config{srcdir}/.ikiwiki"
unless exists $config{wikistatedir} && defined $config{wikistatedir};
@@ -1010,11 +1042,17 @@ sub linkpage ($) {
sub cgiurl (@) {
my %params=@_;
- my $cgiurl=$config{cgiurl};
+ my $cgiurl=$local_cgiurl;
+
if (exists $params{cgiurl}) {
$cgiurl=$params{cgiurl};
delete $params{cgiurl};
}
+
+ unless (%params) {
+ return $cgiurl;
+ }
+
return $cgiurl."?".
join("&amp;", map $_."=".uri_escape_utf8($params{$_}), keys %params);
}
@@ -1022,7 +1060,7 @@ sub cgiurl (@) {
sub baseurl (;$) {
my $page=shift;
- return "$config{url}/" if ! defined $page;
+ return $local_url if ! defined $page;
$page=htmlpage($page);
$page=~s/[^\/]+$//;
@@ -1113,6 +1151,12 @@ sub urlto ($$;$) {
return $config{url}.beautify_urlpath("/".$to);
}
+ if (! defined $from) {
+ my $u = $local_url;
+ $u =~ s{/$}{};
+ return $u.beautify_urlpath("/".$to);
+ }
+
my $link = abs2rel($to, dirname(htmlpage($from)));
return beautify_urlpath($link);