]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki.pm
entab
[ikiwiki.git] / IkiWiki.pm
index d5d11ee857c02b1520fc6a971032cc592df78d23..83679243fe3706a1ec42669df74ceb8ff4733eed 100644 (file)
@@ -5,6 +5,7 @@ package IkiWiki;
 use warnings;
 use strict;
 use Encode;
+use Fcntl q{:flock};
 use URI::Escape q{uri_escape_utf8};
 use POSIX ();
 use Storable;
@@ -108,6 +109,14 @@ sub getsetup () {
                safe => 1,
                rebuild => 1,
        },
+       reverse_proxy => {
+               type => "boolean",
+               default => 0,
+               description => "do not adjust cgiurl if CGI is accessed via different URL",
+               advanced => 0,
+               safe => 1,
+               rebuild => 0, # only affects CGI requests
+       },
        cgi_wrapper => {
                type => "string",
                default => '',
@@ -266,7 +275,7 @@ sub getsetup () {
        html5 => {
                type => "boolean",
                default => 0,
-               description => "generate HTML5?",
+               description => "use elements new in HTML5 like <section>?",
                advanced => 0,
                safe => 1,
                rebuild => 1,
@@ -535,12 +544,19 @@ sub getsetup () {
        },
        useragent => {
                type => "string",
-               default => undef,
+               default => "ikiwiki/$version",
                example => "Wget/1.13.4 (linux-gnu)",
                description => "set custom user agent string for outbound HTTP requests e.g. when fetching aggregated RSS feeds",
                safe => 0,
                rebuild => 0,
        },
+       responsive_layout => {
+               type => "boolean",
+               default => 1,
+               description => "theme has a responsive layout? (mobile-optimized)",
+               safe => 1,
+               rebuild => 1,
+       },
 }
 
 sub defaultconfig () {
@@ -613,12 +629,39 @@ sub checkconfig () {
 
                        $local_cgiurl = $cgiurl->path;
 
-                       if ($cgiurl->scheme ne $baseurl->scheme or
-                               $cgiurl->authority ne $baseurl->authority) {
+                       if ($cgiurl->scheme eq 'https' &&
+                               $baseurl->scheme eq 'http') {
+                               # We assume that the same content is available
+                               # over both http and https, because if it
+                               # wasn't, accessing the static content
+                               # from the CGI would be mixed-content,
+                               # which would be a security flaw.
+
+                               if ($cgiurl->authority ne $baseurl->authority) {
+                                       # use protocol-relative URL for
+                                       # static content
+                                       $local_url = "$config{url}/";
+                                       $local_url =~ s{^http://}{//};
+                               }
+                               # else use host-relative URL for static content
+
+                               # either way, CGI needs to be absolute
+                               $local_cgiurl = $config{cgiurl};
+                       }
+                       elsif ($cgiurl->scheme ne $baseurl->scheme) {
                                # too far apart, fall back to absolute URLs
                                $local_url = "$config{url}/";
                                $local_cgiurl = $config{cgiurl};
                        }
+                       elsif ($cgiurl->authority ne $baseurl->authority) {
+                               # slightly too far apart, fall back to
+                               # protocol-relative URLs
+                               $local_url = "$config{url}/";
+                               $local_url =~ s{^https?://}{//};
+                               $local_cgiurl = $config{cgiurl};
+                               $local_cgiurl =~ s{^https?://}{//};
+                       }
+                       # else keep host-relative URLs
                }
 
                $local_url =~ s{//$}{/};
@@ -1771,8 +1814,11 @@ sub lockwiki () {
        }
        open($wikilock, '>', "$config{wikistatedir}/lockfile") ||
                error ("cannot write to $config{wikistatedir}/lockfile: $!");
-       if (! flock($wikilock, 2)) { # LOCK_EX
-               error("failed to get lock");
+       if (! flock($wikilock, LOCK_EX | LOCK_NB)) {
+               debug("failed to get lock; waiting...");
+               if (! flock($wikilock, LOCK_EX)) {
+                       error("failed to get lock");
+               }
        }
        return 1;
 }