]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki.pm
Track whether we're in the scan or render phase
[ikiwiki.git] / IkiWiki.pm
index b7080bb0b3ff14f1af78dd1633a1f05ed722d6d6..9511c8303dfadc056107ae35e5fb6dca3417911b 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 @underlayfiles $lastrev};
+       %oldtypedlinks %autofiles @underlayfiles $lastrev $phase};
 
 use Exporter q{import};
 our @EXPORT = qw(hook debug error htmlpage template template_depends
@@ -34,6 +34,11 @@ our $DEPEND_CONTENT=1;
 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");
@@ -152,7 +157,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,
@@ -527,6 +533,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 () {
@@ -735,6 +749,7 @@ sub debug ($) {
 }
 
 my $log_open=0;
+my $log_failed=0;
 sub log_message ($$) {
        my $type=shift;
 
@@ -745,9 +760,18 @@ sub log_message ($$) {
                        Sys::Syslog::openlog('ikiwiki', '', 'user');
                        $log_open=1;
                }
-               return eval {
-                       Sys::Syslog::syslog($type, "[$config{wikiname}] %s", join(" ", @_));
+               eval {
+                       # keep a copy to avoid editing the original config repeatedly
+                       my $wikiname = $config{wikiname};
+                       utf8::encode($wikiname);
+                       Sys::Syslog::syslog($type, "[$wikiname] %s", join(" ", @_));
                };
+                if ($@) {
+                    print STDERR "failed to syslog: $@" unless $log_failed;
+                    $log_failed=1;
+                    print STDERR "@_\n";
+                }
+                return $@;
        }
        elsif (! $config{cgi}) {
                return print "@_\n";
@@ -1490,7 +1514,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\">".
@@ -2003,11 +2027,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,
@@ -2301,6 +2333,7 @@ sub useragent () {
        return LWP::UserAgent->new(
                cookie_jar => $config{cookiejar},
                env_proxy => 1,         # respect proxy env vars
+               agent => $config{useragent},
        );
 }