]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki.pm
bugfixen
[ikiwiki.git] / IkiWiki.pm
index 7084e9627aa5258d3f3f9bc34d3b82f867d89c3e..5f7bdfd060c2b566fcea0323021c2d593f90a32e 100644 (file)
@@ -30,6 +30,7 @@ sub defaultconfig () { #{{{
        wiki_file_prune_regexp => qr{((^|/).svn/|\.\.|^\.|\/\.|\.x?html?$|\.rss$|\.atom$|.arch-ids/|{arch}/)},
        wiki_link_regexp => qr/\[\[(?:([^\]\|]+)\|)?([^\s\]]+)\]\]/,
        wiki_file_regexp => qr/(^[-[:alnum:]_.:\/+]+$)/,
+       web_commit_regexp => qr/^web commit (by (.*?(?=: |$))|from (\d+\.\d+\.\d+\.\d+)):?(.*)/,
        verbose => 0,
        syslog => 0,
        wikiname => "wiki",
@@ -61,7 +62,7 @@ sub defaultconfig () { #{{{
        setup => undef,
        adminuser => undef,
        adminemail => undef,
-       plugin => [qw{mdwn inline htmlscrubber}],
+       plugin => [qw{mdwn inline htmlscrubber passwordauth}],
        timeformat => '%c',
        locale => undef,
        sslcookie => 0,
@@ -76,12 +77,14 @@ sub checkconfig () { #{{{
        }
        if (defined $config{locale}) {
                eval q{use POSIX};
+               error($@) if $@;
                $ENV{LANG} = $config{locale}
                        if POSIX::setlocale(&POSIX::LC_TIME, $config{locale});
        }
 
        if ($config{w3mmode}) {
                eval q{use Cwd q{abs_path}};
+               error($@) if $@;
                $config{srcdir}=possibly_foolish_untaint(abs_path($config{srcdir}));
                $config{destdir}=possibly_foolish_untaint(abs_path($config{destdir}));
                $config{cgiurl}="file:///\$LIB/ikiwiki-w3m.cgi/".$config{cgiurl}
@@ -113,13 +116,8 @@ sub checkconfig () { #{{{
 } #}}}
 
 sub loadplugins () { #{{{
-       foreach my $plugin (@{$config{plugin}}) {
-               my $mod="IkiWiki::Plugin::".possibly_foolish_untaint($plugin);
-               eval qq{use $mod};
-               if ($@) {
-                       error("Failed to load plugin $mod: $@");
-               }
-       }
+       loadplugin($_) foreach @{$config{plugin}};
+       
        run_hooks(getopt => sub { shift->() });
        if (grep /^-/, @ARGV) {
                print STDERR "Unknown option: $_\n"
@@ -128,6 +126,16 @@ sub loadplugins () { #{{{
        }
 } #}}}
 
+sub loadplugin ($) { #{{{
+       my $plugin=shift;
+
+       my $mod="IkiWiki::Plugin::".possibly_foolish_untaint($plugin);
+       eval qq{use $mod};
+       if ($@) {
+               error("Failed to load plugin $mod: $@");
+       }
+} #}}}
+
 sub error ($) { #{{{
        if ($config{cgi}) {
                print "Content-type: text/html\n\n";
@@ -264,6 +272,7 @@ sub writefile ($$$;$) { #{{{
        close OUT;
 } #}}}
 
+my %cleared;
 sub will_render ($$;$) { #{{{
        my $page=shift;
        my $dest=shift;
@@ -275,11 +284,12 @@ sub will_render ($$;$) { #{{{
                error("$config{destdir}/$dest independently created, not overwriting with version from $page");
        }
 
-       if (! $clear) {
+       if (! $clear || $cleared{$page}) {
                $renderedfiles{$page}=[$dest, grep { $_ ne $dest } @{$renderedfiles{$page}}];
        }
        else {
                $renderedfiles{$page}=[$dest];
+               $cleared{$page}=1;
        }
 } #}}}
 
@@ -358,6 +368,7 @@ sub displaytime ($) { #{{{
        my $time=shift;
 
        eval q{use POSIX};
+       error($@) if $@;
        # strftime doesn't know about encodings, so make sure
        # its output is properly treated as utf8
        return decode_utf8(POSIX::strftime(
@@ -444,10 +455,11 @@ sub linkify ($$$) { #{{{
 } #}}}
 
 my %preprocessing;
-sub preprocess ($$$) { #{{{
+sub preprocess ($$$;$) { #{{{
        my $page=shift; # the page the data comes from
        my $destpage=shift; # the page the data will appear in (different for inline)
        my $content=shift;
+       my $scan=shift;
 
        my $handle=sub {
                my $escape=shift;
@@ -457,6 +469,7 @@ sub preprocess ($$$) { #{{{
                        return "[[$command $params]]";
                }
                elsif (exists $hooks{preprocess}{$command}) {
+                       return "" if $scan && ! $hooks{preprocess}{$command}{scan};
                        # Note: preserve order of params, some plugins may
                        # consider it significant.
                        my @params;
@@ -505,7 +518,7 @@ sub preprocess ($$$) { #{{{
        return $content;
 } #}}}
 
-sub filter ($$) {
+sub filter ($$) { #{{{
        my $page=shift;
        my $content=shift;
 
@@ -514,7 +527,7 @@ sub filter ($$) {
        });
 
        return $content;
-}
+} #}}}
 
 sub indexlink () { #{{{
        return "<a href=\"$config{url}\">$config{wikiname}</a>";
@@ -589,7 +602,8 @@ sub saveindex () { #{{{
                        "ctime=$pagectime{$page} ".
                        "src=$pagesources{$page}";
                $line.=" dest=$_" foreach @{$renderedfiles{$page}};
-               $line.=" link=$_" foreach @{$links{$page}};
+               my %count;
+               $line.=" link=$_" foreach grep { ++$count{$_} == 1 } @{$links{$page}};
                if (exists $depends{$page}) {
                        $line.=" depends=".encode_entities($depends{$page}, " \t\n");
                }
@@ -654,7 +668,15 @@ sub run_hooks ($$) { # {{{
        my $sub=shift;
 
        if (exists $hooks{$type}) {
+               my @deferred;
                foreach my $id (keys %{$hooks{$type}}) {
+                       if ($hooks{$type}{$id}{last}) {
+                               push @deferred, $id;
+                               next;
+                       }
+                       $sub->($hooks{$type}{$id}{call});
+               }
+               foreach my $id (@deferred) {
                        $sub->($hooks{$type}{$id}{call});
                }
        }