X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/9ff9ea55f70a455a96fad3d34266343327528723..b79547385ac6643cf4db6bece97ec99ad6bf6b4b:/IkiWiki.pm diff --git a/IkiWiki.pm b/IkiWiki.pm index b70f51175..c078a0055 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -17,6 +17,7 @@ use Exporter q{import}; our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match bestlink htmllink readfile writefile pagetype srcfile pagename displaytime will_render gettext urlto targetpage + add_underlay %config %links %renderedfiles %pagesources %destsources); our $VERSION = 2.00; # plugin interface version, next is ikiwiki version our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE @@ -38,7 +39,7 @@ sub defaultconfig () { #{{{ wiki_link_regexp => qr{ \[\[ # beginning of link (?: - ([^\]\|]+) # 1: link text + ([^\]\|\n\s]+) # 1: link text \| # followed by '|' )? # optional @@ -83,6 +84,7 @@ sub defaultconfig () { #{{{ pingurl => [], templatedir => "$installdir/share/ikiwiki/templates", underlaydir => "$installdir/share/ikiwiki/basewiki", + underlaydirs => [], setup => undef, adminuser => undef, adminemail => undef, @@ -166,7 +168,7 @@ sub loadplugin ($) { #{{{ return if grep { $_ eq $plugin} @{$config{disable_plugins}}; - foreach my $dir (possibly_foolish_untaint($config{libdir}), + foreach my $dir (defined $config{libdir} ? possibly_foolish_untaint($config{libdir}) : undef, "$installdir/lib/ikiwiki") { if (defined $dir && -x "$dir/plugins/$plugin") { require IkiWiki::Plugin::external; @@ -285,11 +287,26 @@ sub srcfile ($) { #{{{ my $file=shift; return "$config{srcdir}/$file" if -e "$config{srcdir}/$file"; - return "$config{underlaydir}/$file" if -e "$config{underlaydir}/$file"; - error("internal error: $file cannot be found in $config{srcdir} or $config{underlaydir}"); + foreach my $dir (@{$config{underlaydirs}}, $config{underlaydir}) { + return "$dir/$file" if -e "$dir/$file"; + } + error("internal error: $file cannot be found in $config{srcdir} or underlay"); return; } #}}} +sub add_underlay ($) { #{{{ + my $dir=shift; + + if ($dir=~/^\//) { + unshift @{$config{underlaydirs}}, $dir; + } + else { + unshift @{$config{underlaydirs}}, "$config{underlaydir}/../$dir"; + } + + return 1; +} #}}} + sub readfile ($;$$) { #{{{ my $file=shift; my $binary=shift; @@ -390,6 +407,7 @@ sub bestlink ($$) { #{{{ # absolute links $cwd=""; } + $link=~s/\/$//; do { my $l=$cwd; @@ -481,19 +499,24 @@ sub abs2rel ($$) { #{{{ return $ret; } #}}} -sub displaytime ($) { #{{{ +sub displaytime ($;$) { #{{{ my $time=shift; + my $format=shift; + if (! defined $format) { + $format=$config{timeformat}; + } # strftime doesn't know about encodings, so make sure # its output is properly treated as utf8 - return decode_utf8(POSIX::strftime( - $config{timeformat}, localtime($time))); + return decode_utf8(POSIX::strftime($format, localtime($time))); } #}}} sub beautify_url ($) { #{{{ my $url=shift; - $url =~ s!/index.$config{htmlext}$!/!; + if ($config{usedirs}) { + $url =~ s!/index.$config{htmlext}$!/!; + } $url =~ s!^$!./!; # Browsers don't like empty links... return $url; @@ -522,6 +545,8 @@ sub htmllink ($$$;@) { #{{{ my $link=shift; my %opts=@_; + $link=~s/\/$//; + my $bestlink; if (! $opts{forcesubpage}) { $bestlink=bestlink($lpage, $link); @@ -539,14 +564,15 @@ sub htmllink ($$$;@) { #{{{ } return "$linktext" - if length $bestlink && $page eq $bestlink; + if length $bestlink && $page eq $bestlink && + ! defined $opts{anchor}; if (! $destsources{$bestlink}) { $bestlink=htmlpage($bestlink); if (! $destsources{$bestlink}) { return $linktext unless length $config{cgiurl}; - return " "create", page => pagetitle(lc($link), 1), @@ -571,6 +597,9 @@ sub htmllink ($$$;@) { #{{{ if (defined $opts{rel}) { push @attrs, ' rel="'.$opts{rel}.'"'; } + if (defined $opts{class}) { + push @attrs, ' class="'.$opts{class}.'"'; + } return "$linktext"; } #}}} @@ -774,7 +803,8 @@ sub lockwiki (;$) { #{{{ } #}}} sub unlockwiki () { #{{{ - return close($wikilock); + return close($wikilock) if $wikilock; + return; } #}}} my $commitlock; @@ -800,10 +830,16 @@ sub disable_commit_hook () { #{{{ } #}}} sub enable_commit_hook () { #{{{ - return close($commitlock); + return close($commitlock) if $commitlock; + return; } #}}} sub loadindex () { #{{{ + %oldrenderedfiles=%pagectime=(); + if (! $config{rebuild}) { + %pagesources=%pagemtime=%oldlinks=%links=%depends= + %destsources=%renderedfiles=%pagecase=(); + } open (my $in, "<", "$config{wikistatedir}/index") || return; while (<$in>) { $_=possibly_foolish_untaint($_); @@ -884,7 +920,7 @@ sub template_params (@) { #{{{ my @ret=( filter => sub { my $text_ref = shift; - ${$text_ref} = Encode::decode_utf8(${$text_ref}); + ${$text_ref} = decode_utf8(${$text_ref}); }, filename => $filename, loop_context_vars => 1, @@ -1017,7 +1053,9 @@ sub file_pruned ($$) { #{{{ sub gettext { #{{{ # Only use gettext in the rare cases it's needed. - if (exists $ENV{LANG} || exists $ENV{LC_ALL} || exists $ENV{LC_MESSAGES}) { + if ((exists $ENV{LANG} && length $ENV{LANG}) || + (exists $ENV{LC_ALL} && length $ENV{LC_ALL}) || + (exists $ENV{LC_MESSAGES} && length $ENV{LC_MESSAGES})) { if (! $gettext_obj) { $gettext_obj=eval q{ use Locale::gettext q{textdomain}; @@ -1199,7 +1237,7 @@ sub match_link ($$;@) { #{{{ if $bestlink eq IkiWiki::bestlink($page, $p); } else { - return IkiWiki::SuccessReason->new("$page links to page matching $link") + return IkiWiki::SuccessReason->new("$page links to page $p matching $link") if match_glob($p, $link, %params); } }