use warnings;
use strict;
use Encode;
+use Fcntl q{:flock};
use URI::Escape q{uri_escape_utf8};
use POSIX ();
use Storable;
%pagestate %wikistate %renderedfiles %oldrenderedfiles
%pagesources %delpagesources %destsources %depends %depends_simple
@mass_depends %hooks %forcerebuild %loaded_plugins %typedlinks
- %oldtypedlinks %autofiles @underlayfiles $lastrev};
+ %oldtypedlinks %autofiles @underlayfiles $lastrev $phase};
use Exporter q{import};
our @EXPORT = qw(hook debug error htmlpage template template_depends
our $DEPEND_PRESENCE=2;
our $DEPEND_LINKS=4;
+# Phases of processing.
+sub PHASE_SCAN () { 0 }
+sub PHASE_RENDER () { 1 }
+$phase = PHASE_SCAN;
+
# Optimisation.
use Memoize;
memoize("abs2rel");
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 => '',
type => "internal",
default => [qw{mdwn link inline meta htmlscrubber passwordauth
openid signinedit lockedit conditional
- recentchanges parentlinks editpage}],
+ recentchanges parentlinks editpage
+ templatebody}],
description => "plugins to enable by default",
safe => 0,
rebuild => 1,
html5 => {
type => "boolean",
default => 0,
- description => "generate HTML5?",
+ description => "use elements new in HTML5 like <section>?",
advanced => 0,
safe => 1,
rebuild => 1,
safe => 0, # paranoia
rebuild => 0,
},
+ libdirs => {
+ type => "string",
+ default => [],
+ example => ["$ENV{HOME}/.local/share/ikiwiki"],
+ description => "extra library and plugin directories",
+ advanced => 1,
+ safe => 0, # directory
+ rebuild => 0,
+ },
libdir => {
type => "string",
default => "",
example => "$ENV{HOME}/.ikiwiki/",
- description => "extra library and plugin directory",
+ description => "extra library and plugin directory (searched after libdirs)",
advanced => 1,
safe => 0, # directory
rebuild => 0,
},
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 getlibdirs () {
+ my @libdirs;
+ if ($config{libdirs}) {
+ @libdirs = @{$config{libdirs}};
+ }
+ if (length $config{libdir}) {
+ push @libdirs, $config{libdir};
+ }
+ return @libdirs;
}
sub defaultconfig () {
$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{//$}{/};
sub listplugins () {
my %ret;
- foreach my $dir (@INC, $config{libdir}) {
+ foreach my $dir (@INC, getlibdirs()) {
next unless defined $dir && length $dir;
foreach my $file (glob("$dir/IkiWiki/Plugin/*.pm")) {
my ($plugin)=$file=~/.*\/(.*)\.pm$/;
$ret{$plugin}=1;
}
}
- foreach my $dir ($config{libdir}, "$installdir/lib/ikiwiki") {
+ foreach my $dir (getlibdirs(), "$installdir/lib/ikiwiki") {
next unless defined $dir && length $dir;
foreach my $file (glob("$dir/plugins/*")) {
$ret{basename($file)}=1 if -x $file;
}
sub loadplugins () {
- if (defined $config{libdir} && length $config{libdir}) {
- unshift @INC, possibly_foolish_untaint($config{libdir});
+ foreach my $dir (getlibdirs()) {
+ unshift @INC, possibly_foolish_untaint($dir);
}
foreach my $plugin (@{$config{default_plugins}}, @{$config{add_plugins}}) {
return if ! $force && grep { $_ eq $plugin} @{$config{disable_plugins}};
- foreach my $dir (defined $config{libdir} ? possibly_foolish_untaint($config{libdir}) : undef,
- "$installdir/lib/ikiwiki") {
+ foreach my $possiblytainteddir (getlibdirs(), "$installdir/lib/ikiwiki") {
+ my $dir = possibly_foolish_untaint($possiblytainteddir);
if (defined $dir && -x "$dir/plugins/$plugin") {
eval { require IkiWiki::Plugin::external };
if ($@) {
}
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;
}
if (defined $page && defined $tpage) {
add_depends($page, $tpage);
}
-
+
my @opts=(
filter => sub {
my $text_ref = shift;
${$text_ref} = decode_utf8(${$text_ref});
+ run_hooks(readtemplate => sub {
+ ${$text_ref} = shift->(
+ id => $name,
+ page => $tpage,
+ content => ${$text_ref},
+ untrusted => $untrusted,
+ );
+ });
},
loop_context_vars => 1,
die_on_bad_params => 0,
# { bar => DEPEND_LINKS } is an influence on that result, because changing
# bar's links could change the outcome; so its influences are not the same
# as when testing whether link(foo) matches baz.
+#
+# Static influences are one of the things that make pagespec_match_list
+# more efficient than repeated calls to pagespec_match.
sub influences_static {
return ! $_[0][1]->{""};