]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/commitdiff
Merge remote branch 'smcv/ready/localurl'
authorJoey Hess <joey@kitenet.net>
Mon, 29 Nov 2010 18:43:57 +0000 (14:43 -0400)
committerJoey Hess <joey@kitenet.net>
Mon, 29 Nov 2010 18:43:57 +0000 (14:43 -0400)
1  2 
IkiWiki.pm
IkiWiki/Plugin/rename.pm

diff --combined IkiWiki.pm
index c06751dd36bc0bf656e9b7abfc49d5c8a9455c47,140f7f740ce034100bcaec8478ba71dff83f56f1..a893edb3be4765f14f55b8b37509539bc4041a66
@@@ -501,6 -501,12 +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}) {
        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 +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);
  }
  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 +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);
@@@ -1201,7 -1245,7 +1245,7 @@@ sub userpage ($) 
  sub openiduser ($) {
        my $user=shift;
  
 -      if ($user =~ m!^https?://! &&
 +      if (defined $user && $user =~ m!^https?://! &&
            eval q{use Net::OpenID::VerifiedIdentity; 1} && !$@) {
                my $display;
  
diff --combined IkiWiki/Plugin/rename.pm
index a05e85be0106462f263a47468f72cf2f2c1261ff,614a4cf5c57eb697e8d13c7fc70b340f257b3be8..57747d3c9df00141a1ade61e823c453a2ecbcc33
@@@ -126,7 -126,7 +126,7 @@@ sub rename_form ($$$) 
                method => 'POST',
                javascript => 0,
                params => $q,
-               action => $config{cgiurl},
+               action => IkiWiki::cgiurl(),
                stylesheet => 1,
                fields => [qw{do page new_name attachment}],
        );
@@@ -574,10 -574,11 +574,10 @@@ sub fixlinks ($$$) 
                                eval { writefile($file, $config{srcdir}, $content) };
                                next if $@;
                                my $conflict=IkiWiki::rcs_commit(
 -                                      $file,
 -                                      sprintf(gettext("update for rename of %s to %s"), $rename->{srcfile}, $rename->{destfile}),
 -                                      $token,
 -                                      $session->param("name"),
 -                                      $session->remote_addr(),
 +                                      file => $file,
 +                                      message => sprintf(gettext("update for rename of %s to %s"), $rename->{srcfile}, $rename->{destfile}),
 +                                      token => $token,
 +                                      session => $session,
                                );
                                push @fixedlinks, $page if ! defined $conflict;
                        }