]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki.pm
Add page() PageSpec, which is like glob() but matches only pages, not other files.
[ikiwiki.git] / IkiWiki.pm
index 7382f11e4202f4960895b447de94ee4fb55f6f09..623396c9c4180929613a3b9ccbcdb139e923ebf6 100644 (file)
@@ -13,8 +13,8 @@ use open qw{:utf8 :std};
 
 use vars qw{%config %links %oldlinks %pagemtime %pagectime %pagecase
        %pagestate %wikistate %renderedfiles %oldrenderedfiles
-       %pagesources %destsources %depends %depends_simple %hooks
-       %forcerebuild %loaded_plugins %typedlinks %oldtypedlinks
+       %pagesources %destsources %depends %depends_simple @mass_depends 
+       %hooks %forcerebuild %loaded_plugins %typedlinks %oldtypedlinks
        %autofiles};
 
 use Exporter q{import};
@@ -152,7 +152,7 @@ sub getsetup () {
        templatedir => {
                type => "string",
                default => "$installdir/share/ikiwiki/templates",
-               description => "location of template files",
+               description => "additional directory to search for template files",
                advanced => 1,
                safe => 0, # path
                rebuild => 1,
@@ -1531,8 +1531,8 @@ sub loadindex () {
                my $d=$pages->{$src};
                my $page=pagename($src);
                $pagectime{$page}=$d->{ctime};
+               $pagesources{$page}=$src;
                if (! $config{rebuild}) {
-                       $pagesources{$page}=$src;
                        $pagemtime{$page}=$d->{mtime};
                        $renderedfiles{$page}=$d->{dest};
                        if (exists $d->{links} && ref $d->{links}) {
@@ -1654,7 +1654,7 @@ sub saveindex () {
 sub template_file ($) {
        my $name=shift;
        
-       my $tpage=($name =~ /^\//) ? $name : "templates/$name";
+       my $tpage=($name =~ s/^\///) ? $name : "templates/$name";
        if ($name !~ /\.tmpl$/ && exists $pagesources{$tpage}) {
                $tpage=$pagesources{$tpage};
                $name.=".tmpl";
@@ -1690,8 +1690,7 @@ sub template_depends ($$;@) {
 
        return unless defined $filename;
 
-       require HTML::Template;
-       return HTML::Template->new(
+       my @opts=(
                filter => sub {
                        my $text_ref = shift;
                        ${$text_ref} = decode_utf8(${$text_ref});
@@ -1702,6 +1701,10 @@ sub template_depends ($$;@) {
                @_,
                no_includes => 1,
        );
+       return @opts if wantarray;
+
+       require HTML::Template;
+       return HTML::Template->new(@opts);
 }
 
 sub template ($;@) {
@@ -1712,7 +1715,8 @@ sub misctemplate ($$;@) {
        my $title=shift;
        my $pagebody=shift;
        
-       my $template=template("misc.tmpl",
+       my $template=template("misc.tmpl");
+       $template->param(
                title => $title,
                indexlink => indexlink(),
                wikiname => $config{wikiname},
@@ -2295,7 +2299,11 @@ sub match_glob ($$;@) {
 
        my $regexp=IkiWiki::glob2re($glob);
        if ($page=~/^$regexp$/i) {
-               if (! IkiWiki::isinternal($page) || $params{internal}) {
+               if ($params{onlypage} &&
+                   ! defined IkiWiki::pagetype($IkiWiki::pagesources{$page})) {
+                       return IkiWiki::FailReason->new("$page is not a page");
+               }
+               elsif (! IkiWiki::isinternal($page) || $params{internal}) {
                        return IkiWiki::SuccessReason->new("$glob matches $page");
                }
                else {
@@ -2311,6 +2319,10 @@ sub match_internal ($$;@) {
        return match_glob($_[0], $_[1], @_, internal => 1)
 }
 
+sub match_page ($$;@) {
+       return match_glob($_[0], $_[1], @_, onlypage => 1)
+}
+
 sub match_link ($$;@) {
        my $page=shift;
        my $link=lc(shift);