X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/12fd902fb1228feb4e23a1f850f215122a4c7e3f..be3483fe9:/IkiWiki.pm

diff --git a/IkiWiki.pm b/IkiWiki.pm
index bc56501da..b7080bb0b 100644
--- a/IkiWiki.pm
+++ b/IkiWiki.pm
@@ -14,15 +14,15 @@ use vars qw{%config %links %oldlinks %pagemtime %pagectime %pagecase
 	%pagestate %wikistate %renderedfiles %oldrenderedfiles
 	%pagesources %delpagesources %destsources %depends %depends_simple
 	@mass_depends %hooks %forcerebuild %loaded_plugins %typedlinks
-	%oldtypedlinks %autofiles};
+	%oldtypedlinks %autofiles @underlayfiles $lastrev};
 
 use Exporter q{import};
 our @EXPORT = qw(hook debug error htmlpage template template_depends
 	deptype add_depends pagespec_match pagespec_match_list bestlink
 	htmllink readfile writefile pagetype srcfile pagename
-	displaytime will_render gettext ngettext urlto targetpage
+	displaytime strftime_utf8 will_render gettext ngettext urlto targetpage
 	add_underlay pagetitle titlepage linkpage newpagefile
-	inject add_link add_autofile
+	inject add_link add_autofile useragent
 	%config %links %pagestate %wikistate %renderedfiles
 	%pagesources %destsources %typedlinks);
 our $VERSION = 3.00; # plugin interface version, next is ikiwiki version
@@ -118,6 +118,29 @@ sub getsetup () {
 		safe => 0,
 		rebuild => 0,
 	},
+	cgi_overload_delay => {
+		type => "string",
+		default => '',
+		example => "10",
+		description => "number of seconds to delay CGI requests when overloaded",
+		safe => 1,
+		rebuild => 0,
+	},
+	cgi_overload_message => {
+		type => "string",
+		default => '',
+		example => "Please wait",
+		description => "message to display when overloaded (may contain html)",
+		safe => 1,
+		rebuild => 0,
+	},
+	only_committed_changes => {
+		type => "boolean",
+		default => 0,
+		description => "enable optimization of only refreshing committed changes?",
+		safe => 1,
+		rebuild => 0,
+	},
 	rcs => {
 		type => "string",
 		default => '',
@@ -497,6 +520,13 @@ sub getsetup () {
 		safe => 0,
 		rebuild => 0,
 	},
+	cookiejar => {
+		type => "string",
+		default => { file => "$ENV{HOME}/.ikiwiki/cookies" },
+		description => "cookie control",
+		safe => 0, # hooks into perl module internals
+		rebuild => 0,
+	},
 }
 
 sub defaultconfig () {
@@ -1092,6 +1122,11 @@ sub cgiurl (@) {
 		join("&", map $_."=".uri_escape_utf8($params{$_}), keys %params);
 }
 
+sub cgiurl_abs (@) {
+	eval q{use URI};
+	URI->new_abs(cgiurl(@_), $config{cgiurl});
+}
+
 sub baseurl (;$) {
 	my $page=shift;
 
@@ -1148,9 +1183,19 @@ sub formattime ($;$) {
 		$format=$config{timeformat};
 	}
 
+	return strftime_utf8($format, localtime($time));
+}
+
+my $strftime_encoding;
+sub strftime_utf8 {
 	# strftime doesn't know about encodings, so make sure
-	# its output is properly treated as utf8
-	return decode_utf8(POSIX::strftime($format, localtime($time)));
+	# its output is properly treated as utf8.
+	# Note that this does not handle utf-8 in the format string.
+	($strftime_encoding) = POSIX::setlocale(&POSIX::LC_TIME) =~ m#\.([^@]+)#
+		unless defined $strftime_encoding;
+	$strftime_encoding
+		? Encode::decode($strftime_encoding, POSIX::strftime(@_))
+		: POSIX::strftime(@_);
 }
 
 sub date_3339 ($) {
@@ -1402,7 +1447,7 @@ sub preprocess ($$$;$$) {
 			# consider it significant.
 			my @params;
 			while ($params =~ m{
-				(?:([-\w]+)=)?		# 1: named parameter key?
+				(?:([-.\w]+)=)?		# 1: named parameter key?
 				(?:
 					"""(.*?)"""	# 2: triple-quoted value
 				|
@@ -1499,7 +1544,7 @@ sub preprocess ($$$;$$) {
 			(		# 4: the parameters..
 				\s+	# Must have space if parameters present
 				(?:
-					(?:[-\w]+=)?		# named parameter key?
+					(?:[-.\w]+=)?		# named parameter key?
 					(?:
 						""".*?"""	# triple-quoted value
 						|
@@ -1527,7 +1572,7 @@ sub preprocess ($$$;$$) {
 			\s+
 			(		# 4: the parameters..
 				(?:
-					(?:[-\w]+=)?		# named parameter key?
+					(?:[-.\w]+=)?		# named parameter key?
 					(?:
 						""".*?"""	# triple-quoted value
 						|
@@ -1743,7 +1788,8 @@ sub enable_commit_hook () {
 
 sub loadindex () {
 	%oldrenderedfiles=%pagectime=();
-	if (! $config{rebuild}) {
+	my $rebuild=$config{rebuild};
+	if (! $rebuild) {
 		%pagesources=%pagemtime=%oldlinks=%links=%depends=
 		%destsources=%renderedfiles=%pagecase=%pagestate=
 		%depends_simple=%typedlinks=%oldtypedlinks=();
@@ -1783,10 +1829,16 @@ sub loadindex () {
 
 	foreach my $src (keys %$pages) {
 		my $d=$pages->{$src};
-		my $page=pagename($src);
+		my $page;
+		if (exists $d->{page} && ! $rebuild) {
+			$page=$d->{page};
+		}
+		else {
+			$page=pagename($src);
+		}
 		$pagectime{$page}=$d->{ctime};
 		$pagesources{$page}=$src;
-		if (! $config{rebuild}) {
+		if (! $rebuild) {
 			$pagemtime{$page}=$d->{mtime};
 			$renderedfiles{$page}=$d->{dest};
 			if (exists $d->{links} && ref $d->{links}) {
@@ -1836,6 +1888,8 @@ sub loadindex () {
 	foreach my $page (keys %renderedfiles) {
 		$destsources{$_}=$page foreach @{$renderedfiles{$page}};
 	}
+	$lastrev=$index->{lastrev};
+	@underlayfiles=@{$index->{underlayfiles}} if ref $index->{underlayfiles};
 	return close($in);
 }
 
@@ -1857,6 +1911,7 @@ sub saveindex () {
 		my $src=$pagesources{$page};
 
 		$index{page}{$src}={
+			page => $page,
 			ctime => $pagectime{$page},
 			mtime => $pagemtime{$page},
 			dest => $renderedfiles{$page},
@@ -1876,11 +1931,7 @@ sub saveindex () {
 		}
 
 		if (exists $pagestate{$page}) {
-			foreach my $id (@plugins) {
-				foreach my $key (keys %{$pagestate{$page}{$id}}) {
-					$index{page}{$src}{state}{$id}{$key}=$pagestate{$page}{$id}{$key};
-				}
-			}
+			$index{page}{$src}{state}=$pagestate{$page};
 		}
 	}
 
@@ -1892,6 +1943,9 @@ sub saveindex () {
 		}
 	}
 	
+	$index{lastrev}=$lastrev;
+	$index{underlayfiles}=\@underlayfiles;
+
 	$index{version}="3";
 	my $ret=Storable::nstore_fd(\%index, $out);
 	return if ! defined $ret || ! $ret;
@@ -2243,6 +2297,13 @@ sub add_autofile ($$$) {
 	$autofiles{$file}{generator}=$generator;
 }
 
+sub useragent () {
+	return LWP::UserAgent->new(
+		cookie_jar => $config{cookiejar},
+		env_proxy => 1,		# respect proxy env vars
+	);
+}
+
 sub sortspec_translate ($$) {
 	my $spec = shift;
 	my $reverse = shift;
@@ -2745,12 +2806,12 @@ sub match_user ($$;@) {
 	my $user=shift;
 	my %params=@_;
 	
-	my $regexp=IkiWiki::glob2re($user);
-	
 	if (! exists $params{user}) {
 		return IkiWiki::ErrorReason->new("no user specified");
 	}
 
+	my $regexp=IkiWiki::glob2re($user);
+	
 	if (defined $params{user} && $params{user}=~$regexp) {
 		return IkiWiki::SuccessReason->new("user is $user");
 	}
@@ -2790,8 +2851,10 @@ sub match_ip ($$;@) {
 	if (! exists $params{ip}) {
 		return IkiWiki::ErrorReason->new("no IP specified");
 	}
+	
+	my $regexp=IkiWiki::glob2re(lc $ip);
 
-	if (defined $params{ip} && lc $params{ip} eq lc $ip) {
+	if (defined $params{ip} && lc $params{ip}=~$regexp) {
 		return IkiWiki::SuccessReason->new("IP is $ip");
 	}
 	else {