X-Git-Url: https://scripts.mit.edu/gitweb/www/ikiwiki.git/blobdiff_plain/09b0a3b73f7c9ca873c3e20a64b124c0749b3d3b..2d4b27330e41706af493f49ff8d215357a2a4f35:/IkiWiki.pm diff --git a/IkiWiki.pm b/IkiWiki.pm index 0af4a4fe9..18efaea71 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -11,7 +11,7 @@ use open qw{:utf8 :std}; use vars qw{%config %links %oldlinks %pagemtime %pagectime %pagecase %renderedfiles %oldrenderedfiles %pagesources %destsources - %depends %hooks %forcerebuild $gettext_obj}; + %depends %hooks %forcerebuild $gettext_obj}; use Exporter q{import}; our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match @@ -96,7 +96,7 @@ sub defaultconfig () { #{{{ numbacklinks => 10, account_creation_password => "", } #}}} - + sub checkconfig () { #{{{ # locale stuff; avoid LC_ALL since it overrides everything if (defined $ENV{LC_ALL}) { @@ -160,11 +160,20 @@ sub loadplugin ($) { #{{{ return if grep { $_ eq $plugin} @{$config{disable_plugins}}; + foreach my $dir ($config{libdir}, "$installdir/lib/ikiwiki") { + if (defined $dir && -x "$dir/plugins/$plugin") { + require IkiWiki::Plugin::external; + import IkiWiki::Plugin::external "$dir/plugins/$plugin"; + return 1; + } + } + my $mod="IkiWiki::Plugin::".possibly_foolish_untaint($plugin); eval qq{use $mod}; if ($@) { error("Failed to load plugin $mod: $@"); } + return 1; } #}}} sub error ($;$) { #{{{ @@ -283,11 +292,11 @@ sub readfile ($;$$) { #{{{ } local $/=undef; - open (IN, $file) || error("failed to read $file: $!"); - binmode(IN) if ($binary); - return \*IN if $wantfd; - my $ret=; - close IN || error("failed to read $file: $!"); + open (my $in, $file) || error("failed to read $file: $!"); + binmode($in) if ($binary); + return \*$in if $wantfd; + my $ret=<$in>; + close $in || error("failed to read $file: $!"); return $ret; } #}}} @@ -322,15 +331,15 @@ sub writefile ($$$;$$) { #{{{ } my $cleanup = sub { unlink($newfile) }; - open (OUT, ">$newfile") || error("failed to write $newfile: $!", $cleanup); - binmode(OUT) if ($binary); + open (my $out, '>', $newfile) || error("failed to write $newfile: $!", $cleanup); + binmode($out) if ($binary); if ($writer) { - $writer->(\*OUT, $cleanup); + $writer->(\*$out, $cleanup); } else { - print OUT $content or error("failed writing to $newfile: $!", $cleanup); + print $out $content or error("failed writing to $newfile: $!", $cleanup); } - close OUT || error("failed saving $newfile: $!", $cleanup); + close $out || error("failed saving $newfile: $!", $cleanup); rename($newfile, "$destdir/$file") || error("failed renaming $newfile to $destdir/$file: $!", $cleanup); } #}}} @@ -617,7 +626,7 @@ sub preprocess ($$$;$$) { #{{{ my $command=shift; my $params=shift; if (length $escape) { - return "\\[[$command $params]]"; + return "[[$command $params]]"; } elsif (exists $hooks{preprocess}{$command}) { return "" if $scan && ! $hooks{preprocess}{$command}{scan}; @@ -678,7 +687,7 @@ sub preprocess ($$$;$$) { #{{{ return $ret; } else { - return "\\[[$command $params]]"; + return "[[$command $params]]"; } }; @@ -778,8 +787,8 @@ sub enable_commit_hook () { #{{{ } #}}} sub loadindex () { #{{{ - open (IN, "$config{wikistatedir}/index") || return; - while () { + open (my $in, "$config{wikistatedir}/index") || return; + while (<$in>) { $_=possibly_foolish_untaint($_); chomp; my %items; @@ -806,7 +815,7 @@ sub loadindex () { #{{{ $oldrenderedfiles{$page}=[@{$items{dest}}]; $pagectime{$page}=$items{ctime}[0]; } - close IN; + close $in; } #}}} sub saveindex () { #{{{ @@ -817,7 +826,7 @@ sub saveindex () { #{{{ } my $newfile="$config{wikistatedir}/index.new"; my $cleanup = sub { unlink($newfile) }; - open (OUT, ">$newfile") || error("cannot write to $newfile: $!", $cleanup); + open (my $out, '>', $newfile) || error("cannot write to $newfile: $!", $cleanup); foreach my $page (keys %pagemtime) { next unless $pagemtime{$page}; my $line="mtime=$pagemtime{$page} ". @@ -829,9 +838,9 @@ sub saveindex () { #{{{ if (exists $depends{$page}) { $line.=" depends=".encode_entities($depends{$page}, " \t\n"); } - print OUT $line."\n" || error("failed writing to $newfile: $!", $cleanup); + print $out $line."\n" || error("failed writing to $newfile: $!", $cleanup); } - close OUT || error("failed saving to $newfile: $!", $cleanup); + close $out || error("failed saving to $newfile: $!", $cleanup); rename($newfile, "$config{wikistatedir}/index") || error("failed renaming $newfile to $config{wikistatedir}/index", $cleanup); } #}}} @@ -1041,7 +1050,7 @@ sub pagespec_translate ($) { #{{{ | \) # ) | - \w+\([^\)]+\) # command(params) + \w+\([^\)]*\) # command(params) | [^\s()]+ # any other text )