diff options
author | Simon McVittie <smcv@debian.org> | 2010-11-22 23:13:52 +0000 |
---|---|---|
committer | Simon McVittie <smcv@debian.org> | 2010-11-22 23:13:52 +0000 |
commit | 8f64c69e084c698a389565203bd18bccb33f5d69 (patch) | |
tree | 8cfac53df0429dbd78fe32c0f19b34dcb1f02f6b /IkiWiki.pm | |
parent | 1968317cacc2f555af17286acf26a60ce616cc40 (diff) | |
download | ikiwiki-8f64c69e084c698a389565203bd18bccb33f5d69.tar ikiwiki-8f64c69e084c698a389565203bd18bccb33f5d69.tar.gz |
Compute local paths to the top of the wiki
"local" here is short for "locally valid" - the idea is that we can use
URLs that are relative in the sense of only having the path part, but
absolute in the sense that they start from '/', such as
'/~smcv/ikiwiki.cgi'. There's no particularly good name that I can find
for these between-relative-and-absolute URLs.
They're useful because in the common case where the pages and the CGI
script have the same scheme and authority component, each page is
identified by the same locally-valid URL when linking from any page or
from the CGI, without hard-coding a choice between HTTP and HTTPS, or
between multiple virtual hostnames with the same path layout. As such,
we can use them in many situations that previously used an absolute URL.
If there's no suitable semi-absolute value for local_url (for instance,
if your pages and your CGI reside on different servers), we can just fall
back to using the absolute URL. I append '/' because $config{url} doesn't
end with '/', but the common case for local_url (on all branchable.com
sites, for instance) is that it's just '/'.
Diffstat (limited to 'IkiWiki.pm')
-rw-r--r-- | IkiWiki.pm | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/IkiWiki.pm b/IkiWiki.pm index f57ef8c6c..1d37e7f8e 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,30 @@ 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{//$}{/}; + } + $config{wikistatedir}="$config{srcdir}/.ikiwiki" unless exists $config{wikistatedir} && defined $config{wikistatedir}; |