]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki.pm
Add templatebody plugin and directive, and enable it by default
[ikiwiki.git] / IkiWiki.pm
index 86c8508119fa203bd5ed372b777c6a1fe054e138..d8cfc31ccb972b5ee615cb041ad64fbeca38cc52 100644 (file)
@@ -14,7 +14,7 @@ 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
@@ -134,6 +134,13 @@ sub getsetup () {
                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 => '',
@@ -145,7 +152,8 @@ sub getsetup () {
                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,
@@ -520,6 +528,14 @@ sub getsetup () {
                safe => 0, # hooks into perl module internals
                rebuild => 0,
        },
+       useragent => {
+               type => "string",
+               default => undef,
+               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,
+       },
 }
 
 sub defaultconfig () {
@@ -1493,7 +1509,7 @@ sub preprocess ($$$;$$) {
                                        push @params, $val, '';
                                }
                        }
-                       if ($preprocessing{$page}++ > 3) {
+                       if ($preprocessing{$page}++ > 8) {
                                # Avoid loops of preprocessed pages preprocessing
                                # other pages that preprocess them, etc.
                                return "[[!$command <span class=\"error\">".
@@ -1791,7 +1807,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=();
@@ -1831,10 +1848,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}) {
@@ -1884,6 +1907,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);
 }
 
@@ -1905,6 +1930,7 @@ sub saveindex () {
                my $src=$pagesources{$page};
 
                $index{page}{$src}={
+                       page => $page,
                        ctime => $pagectime{$page},
                        mtime => $pagemtime{$page},
                        dest => $renderedfiles{$page},
@@ -1924,11 +1950,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};
                }
        }
 
@@ -1940,6 +1962,9 @@ sub saveindex () {
                }
        }
        
+       $index{lastrev}=$lastrev;
+       $index{underlayfiles}=\@underlayfiles;
+
        $index{version}="3";
        my $ret=Storable::nstore_fd(\%index, $out);
        return if ! defined $ret || ! $ret;
@@ -1997,11 +2022,19 @@ sub template_depends ($$;@) {
        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,
@@ -2295,6 +2328,7 @@ sub useragent () {
        return LWP::UserAgent->new(
                cookie_jar => $config{cookiejar},
                env_proxy => 1,         # respect proxy env vars
+               agent => $config{useragent},
        );
 }