X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/b973ed82699903c23b3feeb5e73e1ebd6f587f43..fb0068c6da03bb58e1b1a27936e392a5de266f47:/IkiWiki.pm diff --git a/IkiWiki.pm b/IkiWiki.pm index 7084e9627..61725ab84 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -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( @@ -385,9 +396,6 @@ sub htmllink ($$$;$$$) { #{{{ return "$linktext" if length $bestlink && $page eq $bestlink; - # TODO BUG: %renderedfiles may not have it, if the linked to page - # was also added and isn't yet rendered! Note that this bug is - # masked by the bug that makes all new files be rendered twice. if (! grep { $_ eq $bestlink } map { @{$_} } values %renderedfiles) { $bestlink=htmlpage($bestlink); } @@ -444,10 +452,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 +466,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 +515,7 @@ sub preprocess ($$$) { #{{{ return $content; } #}}} -sub filter ($$) { +sub filter ($$) { #{{{ my $page=shift; my $content=shift; @@ -514,7 +524,7 @@ sub filter ($$) { }); return $content; -} +} #}}} sub indexlink () { #{{{ return "$config{wikiname}"; @@ -589,7 +599,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 +665,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}); } }