]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki.pm
Avoid %links accumulating duplicates. (For TOVA)
[ikiwiki.git] / IkiWiki.pm
index fca8da874f4eac31e66ad6e3f4fbde0ba286a0e2..e6efe18891069f128ff19ab87de717218b0a8797 100644 (file)
@@ -18,15 +18,15 @@ use vars qw{%config %links %oldlinks %pagemtime %pagectime %pagecase
 
 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 pagetitle titlepage linkpage newpagefile
-                inject
+                 pagespec_match_list bestlink htmllink readfile writefile
+                pagetype srcfile pagename displaytime will_render gettext urlto
+                targetpage add_underlay pagetitle titlepage linkpage
+                newpagefile inject add_link
                  %config %links %pagestate %wikistate %renderedfiles
                  %pagesources %destsources);
 our $VERSION = 3.00; # plugin interface version, next is ikiwiki version
 our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE
-our $installdir=''; # INSTALLDIR_AUTOREPLACE done by Makefile, DNE
+our $installdir='/usr'; # INSTALLDIR_AUTOREPLACE done by Makefile, DNE
 
 # Optimisation.
 use Memoize;
@@ -1757,6 +1757,14 @@ sub inject {
        use warnings;
 }
 
+sub add_link ($$) {
+       my $page=shift;
+       my $link=shift;
+
+       push @{$links{$page}}, $link
+               unless grep { $_ eq $link } @{$links{$page}};
+}
+
 sub pagespec_merge ($$) {
        my $a=shift;
        my $b=shift;
@@ -1832,6 +1840,30 @@ sub pagespec_match ($$;@) {
        return $sub->($page, @params);
 }
 
+sub pagespec_match_list ($$;@) {
+       my $pages=shift;
+       my $spec=shift;
+       my @params=@_;
+
+       my $sub=pagespec_translate($spec);
+       error "syntax error in pagespec \"$spec\""
+               if $@ || ! defined $sub;
+       
+       my @ret;
+       my $r;
+       foreach my $page (@$pages) {
+               $r=$sub->($page, @params);
+               push @ret, $page if $r;
+       }
+
+       if (! @ret && defined $r && $r->isa("IkiWiki::ErrorReason")) {
+               error(sprintf(gettext("cannot match pages: %s"), $r));
+       }
+       else {
+               return @ret;
+       }
+}
+
 sub pagespec_valid ($) {
        my $spec=shift;