X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/34e8c78c1c9bf65564c1a3086584158e5c3cc415..54898d16d4c86fddcb1b5588eac67a729c14deeb:/IkiWiki.pm diff --git a/IkiWiki.pm b/IkiWiki.pm index adae5d8c1..03441b594 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -18,8 +18,8 @@ use vars qw{%config %links %oldlinks %pagemtime %pagectime %pagecase %autofiles}; use Exporter q{import}; -our @EXPORT = qw(hook debug error template htmlpage deptype - add_depends pagespec_match pagespec_match_list bestlink +our @EXPORT = qw(hook debug error htmlpage template template_depends + deptype add_depends pagespec_match pagespec_match_list bestlink htmllink readfile writefile pagetype srcfile pagename displaytime will_render gettext ngettext urlto targetpage add_underlay pagetitle titlepage linkpage newpagefile @@ -157,13 +157,6 @@ sub getsetup () { safe => 0, # path rebuild => 1, }, - templatedirs => { - type => "internal", - default => [], - description => "additional directories containing template files", - safe => 0, - rebuild => 0, - }, underlaydir => { type => "string", default => "$installdir/share/ikiwiki/basewiki", @@ -1087,14 +1080,16 @@ sub htmllink ($$$;@) { $bestlink=htmlpage($bestlink); if (! $destsources{$bestlink}) { - return $linktext unless length $config{cgiurl}; - return " "create", - page => lc($link), - from => $lpage - ). - "\" rel=\"nofollow\">?$linktext" + my $cgilink = ""; + if (length $config{cgiurl}) { + $cgilink = " "create", + page => lc($link), + from => $lpage + )."\" rel=\"nofollow\">?"; + } + return "$cgilink$linktext" } } @@ -1657,47 +1652,61 @@ sub saveindex () { } sub template_file ($) { - my $template=shift; + my $name=shift; + + my $tpage="templates/$name"; + if ($name !~ /\.tmpl$/ && exists $pagesources{$tpage}) { + $tpage=$pagesources{$tpage}; + $name.=".tmpl"; + } - foreach my $dir ($config{templatedir}, @{$config{templatedirs}}, + my $template=srcfile($tpage, 1); + if (defined $template) { + return $template, $tpage if wantarray; + return $template; + } + + foreach my $dir ($config{templatedir}, "$installdir/share/ikiwiki/templates") { - return "$dir/$template" if -e "$dir/$template"; + return "$dir/$name" if -e "$dir/$name"; } return; } -sub template_params (@) { - my $filename=template_file(shift); - - if (! defined $filename) { - return if wantarray; - return ""; +sub template_depends ($$;@) { + my $name=shift; + my $page=shift; + + my ($filename, $tpage)=template_file($name); + if (defined $page && defined $tpage) { + add_depends($page, $tpage); } - my @ret=( + return unless defined $filename; + + require HTML::Template; + return HTML::Template->new( filter => sub { my $text_ref = shift; ${$text_ref} = decode_utf8(${$text_ref}); }, - filename => $filename, loop_context_vars => 1, die_on_bad_params => 0, - @_ + filename => $filename, + @_, + no_includes => 1, ); - return wantarray ? @ret : {@ret}; } sub template ($;@) { - require HTML::Template; - return HTML::Template->new(template_params(@_)); + template_depends(shift, undef, @_); } sub misctemplate ($$;@) { my $title=shift; my $pagebody=shift; - my $template=template("misc.tmpl"); - $template->param( + my $template=template("misc.tmpl", title => $title, indexlink => indexlink(), wikiname => $config{wikiname}, @@ -1817,10 +1826,12 @@ sub add_depends ($$;$) { foreach my $p (keys %pagesources) { my $r=$sub->($p, location => $page); my $i=$r->influences; + my $static=$r->influences_static; foreach my $k (keys %$i) { + next unless $r || $static || $k eq $page; $depends_simple{$page}{lc $k} |= $i->{$k}; } - last if $r->influences_static; + last if $static; } $depends{$page}{$pagespec} |= $deptype; @@ -2144,6 +2155,9 @@ sub pagespec_match_list ($$;@) { my $r=$sub->($p, %params, location => $page); error(sprintf(gettext("cannot match pages: %s"), $r)) if $r->isa("IkiWiki::ErrorReason"); + unless ($r || $r->influences_static) { + $r->remove_influence($p); + } $accum |= $r; if ($r) { push @matches, $p; @@ -2229,7 +2243,7 @@ sub merge_influences { my $anded=shift; if (! $anded || (($this || %{$this->[1]}) && - ($other || %{$other->[1]}))) { + ($other || %{$other->[1]}))) { foreach my $influence (keys %{$other->[1]}) { $this->[1]{$influence} |= $other->[1]{$influence}; } @@ -2240,6 +2254,13 @@ sub merge_influences { } } +sub remove_influence { + my $this=shift; + my $torm=shift; + + delete $this->[1]{$torm}; +} + package IkiWiki::ErrorReason; our @ISA = 'IkiWiki::FailReason'; @@ -2253,7 +2274,7 @@ sub derel ($$) { if ($path =~ m!^\./!) { $from=~s#/?[^/]+$## if defined $from; $path=~s#^\./##; - $path="$from/$path" if length $from; + $path="$from/$path" if defined $from && length $from; } return $path;