X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/aadb21422065dc225cfbf487c56382e2b0ae8bcd..0b784b5593ea9db6664d0ceb5001939f7597f044:/IkiWiki.pm diff --git a/IkiWiki.pm b/IkiWiki.pm index fdb62f7da..6b74bf08a 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -54,6 +54,7 @@ sub defaultconfig () { #{{{ syslog => 0, wikiname => "wiki", default_pageext => "mdwn", + htmlext => "html", cgi => 0, post_commit => 0, rcs => '', @@ -85,6 +86,7 @@ sub defaultconfig () { #{{{ adminemail => undef, plugin => [qw{mdwn inline htmlscrubber passwordauth openid signinedit lockedit conditional}], + libdir => undef, timeformat => '%c', locale => undef, sslcookie => 0, @@ -126,7 +128,7 @@ sub checkconfig () { #{{{ unless exists $config{wikistatedir}; if ($config{rcs}) { - eval qq{require IkiWiki::Rcs::$config{rcs}}; + eval qq{use IkiWiki::Rcs::$config{rcs}}; if ($@) { error("Failed to load RCS module IkiWiki::Rcs::$config{rcs}: $@"); } @@ -139,8 +141,12 @@ sub checkconfig () { #{{{ } #}}} sub loadplugins () { #{{{ + if (defined $config{libdir}) { + unshift @INC, $config{libdir}; + } + loadplugin($_) foreach @{$config{plugin}}; - + run_hooks(getopt => sub { shift->() }); if (grep /^-/, @ARGV) { print STDERR "Unknown option: $_\n" @@ -154,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 ($;$) { #{{{ @@ -256,7 +271,7 @@ sub targetpage ($$) { #{{{ sub htmlpage ($) { #{{{ my $page=shift; - return targetpage($page, "html"); + return targetpage($page, $config{htmlext}); } #}}} sub srcfile ($) { #{{{ @@ -277,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; } #}}} @@ -316,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); } #}}} @@ -466,7 +481,7 @@ sub displaytime ($) { #{{{ sub beautify_url ($) { #{{{ my $url=shift; - $url =~ s!/index.html$!/!; + $url =~ s!/index.$config{htmlext}$!/!; $url =~ s!^$!./!; # Browsers don't like empty links... return $url; @@ -540,7 +555,12 @@ sub htmllink ($$$;@) { #{{{ $bestlink.="#".$opts{anchor}; } - return "$linktext"; + my @attrs; + if (defined $opts{rel}) { + push @attrs, ' rel="'.$opts{rel}.'"'; + } + + return "$linktext"; } #}}} sub htmlize ($$$) { #{{{ @@ -667,7 +687,7 @@ sub preprocess ($$$;$$) { #{{{ return $ret; } else { - return "\\[[$command $params]]"; + return "[[$command $params]]"; } }; @@ -767,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; @@ -795,7 +815,7 @@ sub loadindex () { #{{{ $oldrenderedfiles{$page}=[@{$items{dest}}]; $pagectime{$page}=$items{ctime}[0]; } - close IN; + close $in; } #}}} sub saveindex () { #{{{ @@ -806,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} ". @@ -818,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); } #}}} @@ -842,7 +862,6 @@ sub template_params (@) { #{{{ return ""; } - require HTML::Template; my @ret=( filter => sub { my $text_ref = shift; @@ -857,6 +876,7 @@ sub template_params (@) { #{{{ } #}}} sub template ($;@) { #{{{ + require HTML::Template; HTML::Template->new(template_params(@_)); } #}}} @@ -1030,7 +1050,7 @@ sub pagespec_translate ($) { #{{{ | \) # ) | - \w+\([^\)]+\) # command(params) + \w+\([^\)]*\) # command(params) | [^\s()]+ # any other text )