]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki.pm
Merge branch 'master' into dependency-types
[git.ikiwiki.info.git] / IkiWiki.pm
index 8a86957684e1b7600b47ed5aee07b79d506e3995..7b1d24c6a2214d14543aadcbbadde9767a15af52 100644 (file)
@@ -13,8 +13,8 @@ use open qw{:utf8 :std};
 
 use vars qw{%config %links %oldlinks %pagemtime %pagectime %pagecase
            %pagestate %wikistate %renderedfiles %oldrenderedfiles
 
 use vars qw{%config %links %oldlinks %pagemtime %pagectime %pagecase
            %pagestate %wikistate %renderedfiles %oldrenderedfiles
-           %pagesources %destsources %depends %hooks %forcerebuild
-           %loaded_plugins};
+           %pagesources %destsources %depends %depends_simple %hooks
+           %forcerebuild %loaded_plugins};
 
 use Exporter q{import};
 our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
 
 use Exporter q{import};
 our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
@@ -28,11 +28,17 @@ our $VERSION = 3.00; # plugin interface version, next is ikiwiki version
 our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE
 our $installdir='/usr'; # INSTALLDIR_AUTOREPLACE done by Makefile, DNE
 
 our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE
 our $installdir='/usr'; # INSTALLDIR_AUTOREPLACE done by Makefile, DNE
 
+# Page dependency types.
+our $DEPEND_CONTENT=1;
+our $DEPEND_PRESENCE=2;
+our $DEPEND_LINKS=4;
+
 # Optimisation.
 use Memoize;
 memoize("abs2rel");
 memoize("pagespec_translate");
 memoize("file_pruned");
 # Optimisation.
 use Memoize;
 memoize("abs2rel");
 memoize("pagespec_translate");
 memoize("file_pruned");
+memoize("template_file");
 
 sub getsetup () {
        wikiname => {
 
 sub getsetup () {
        wikiname => {
@@ -149,6 +155,13 @@ sub getsetup () {
                safe => 0, # path
                rebuild => 1,
        },
                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",
        underlaydir => {
                type => "string",
                default => "$installdir/share/ikiwiki/basewiki",
@@ -336,7 +349,7 @@ sub getsetup () {
                        qr/\.x?html?$/, qr/\.ikiwiki-new$/,
                        qr/(^|\/).svn\//, qr/.arch-ids\//, qr/{arch}\//,
                        qr/(^|\/)_MTN\//, qr/(^|\/)_darcs\//,
                        qr/\.x?html?$/, qr/\.ikiwiki-new$/,
                        qr/(^|\/).svn\//, qr/.arch-ids\//, qr/{arch}\//,
                        qr/(^|\/)_MTN\//, qr/(^|\/)_darcs\//,
-                       qr/\.dpkg-tmp$/],
+                       qr/(^|\/)CVS\//, qr/\.dpkg-tmp$/],
                description => "regexps of source files to ignore",
                safe => 0,
                rebuild => 1,
                description => "regexps of source files to ignore",
                safe => 0,
                rebuild => 1,
@@ -356,7 +369,7 @@ sub getsetup () {
        },
        web_commit_regexp => {
                type => "internal",
        },
        web_commit_regexp => {
                type => "internal",
-               default => qr/^web commit (by (.*?(?=: |$))|from (\d+\.\d+\.\d+\.\d+)):?(.*)/,
+               default => qr/^web commit (by (.*?(?=: |$))|from ([0-9a-fA-F:.]+[0-9a-fA-F])):?(.*)/,
                description => "regexp to parse web commits from logs",
                safe => 0,
                rebuild => 0,
                description => "regexp to parse web commits from logs",
                safe => 0,
                rebuild => 0,
@@ -536,12 +549,12 @@ sub loadplugins () {
        }
        
        if ($config{rcs}) {
        }
        
        if ($config{rcs}) {
-               if (exists $IkiWiki::hooks{rcs}) {
+               if (exists $hooks{rcs}) {
                        error(gettext("cannot use multiple rcs plugins"));
                }
                loadplugin($config{rcs});
        }
                        error(gettext("cannot use multiple rcs plugins"));
                }
                loadplugin($config{rcs});
        }
-       if (! exists $IkiWiki::hooks{rcs}) {
+       if (! exists $hooks{rcs}) {
                loadplugin("norcs");
        }
 
                loadplugin("norcs");
        }
 
@@ -1475,7 +1488,8 @@ sub loadindex () {
        %oldrenderedfiles=%pagectime=();
        if (! $config{rebuild}) {
                %pagesources=%pagemtime=%oldlinks=%links=%depends=
        %oldrenderedfiles=%pagectime=();
        if (! $config{rebuild}) {
                %pagesources=%pagemtime=%oldlinks=%links=%depends=
-               %destsources=%renderedfiles=%pagecase=%pagestate=();
+               %destsources=%renderedfiles=%pagecase=%pagestate=
+               %depends_simple=();
        }
        my $in;
        if (! open ($in, "<", "$config{wikistatedir}/indexdb")) {
        }
        my $in;
        if (! open ($in, "<", "$config{wikistatedir}/indexdb")) {
@@ -1515,13 +1529,28 @@ sub loadindex () {
                                $links{$page}=$d->{links};
                                $oldlinks{$page}=[@{$d->{links}}];
                        }
                                $links{$page}=$d->{links};
                                $oldlinks{$page}=[@{$d->{links}}];
                        }
+                       if (ref $d->{depends_simple} eq 'ARRAY') {
+                               # old format
+                               $depends_simple{$page}={
+                                       map { $_ => 1 } @{$d->{depends_simple}}
+                               };
+                       }
+                       elsif (exists $d->{depends_simple}) {
+                               $depends_simple{$page}=$d->{depends_simple};
+                       }
                        if (exists $d->{dependslist}) {
                        if (exists $d->{dependslist}) {
+                               # old format
                                $depends{$page}={
                                $depends{$page}={
-                                       map { $_ => 1 } @{$d->{dependslist}}
+                                       map { $_ => $DEPEND_CONTENT }
+                                               @{$d->{dependslist}}
                                };
                        }
                                };
                        }
+                       elsif (exists $d->{depends} && ! ref $d->{depends}) {
+                               # old format
+                               $depends{$page}={$d->{depends} => $DEPEND_CONTENT };
+                       }
                        elsif (exists $d->{depends}) {
                        elsif (exists $d->{depends}) {
-                               $depends{$page}={$d->{depends} => 1};
+                               $depends{$page}=$d->{depends};
                        }
                        if (exists $d->{state}) {
                                $pagestate{$page}=$d->{state};
                        }
                        if (exists $d->{state}) {
                                $pagestate{$page}=$d->{state};
@@ -1567,7 +1596,11 @@ sub saveindex () {
                };
 
                if (exists $depends{$page}) {
                };
 
                if (exists $depends{$page}) {
-                       $index{page}{$src}{dependslist} = [ keys %{$depends{$page}} ];
+                       $index{page}{$src}{depends} = $depends{$page};
+               }
+
+               if (exists $depends_simple{$page}) {
+                       $index{page}{$src}{depends_simple} = $depends_simple{$page};
                }
 
                if (exists $pagestate{$page}) {
                }
 
                if (exists $pagestate{$page}) {
@@ -1599,7 +1632,8 @@ sub saveindex () {
 sub template_file ($) {
        my $template=shift;
 
 sub template_file ($) {
        my $template=shift;
 
-       foreach my $dir ($config{templatedir}, "$installdir/share/ikiwiki/templates") {
+       foreach my $dir ($config{templatedir}, @{$config{templatedirs}},
+                        "$installdir/share/ikiwiki/templates") {
                return "$dir/$template" if -e "$dir/$template";
        }
        return;
                return "$dir/$template" if -e "$dir/$template";
        }
        return;
@@ -1734,22 +1768,58 @@ sub rcs_receive () {
        $hooks{rcs}{rcs_receive}{call}->();
 }
 
        $hooks{rcs}{rcs_receive}{call}->();
 }
 
-sub add_depends ($$) {
+sub add_depends ($$;@) {
        my $page=shift;
        my $pagespec=shift;
 
        my $page=shift;
        my $pagespec=shift;
 
-       if (ref $pagespec eq 'ARRAY') {
-               foreach my $ps (@$pagespec) {
-                       if (pagespec_valid($ps)) {
-                               $depends{$page}{$ps} = 1;
+       # Is the pagespec a simple page name?
+       my $simple=$pagespec =~ /$config{wiki_file_regexp}/ &&
+               $pagespec !~ /[\s*?()!]/;
+
+       my $deptype=0;
+       if (@_) {
+               my %params=@_;
+               
+               if ($params{presence}) {
+                       # Is the pagespec limited to terms that will continue
+                       # to match pages as long as those pages exist?
+                       my $presence_limited=1;
+                       while ($presence_limited && $pagespec=~m/(\w+)\([^\)]*\)/g) {
+                               $presence_limited = $1 =~ /^(glob|internal|creation_month|creation_day|creation_year|created_before|created_after)$/;
+                       }
+                       if ($presence_limited) {
+                               $deptype=$deptype | $DEPEND_PRESENCE;
+                       }
+                       else {
+                               $deptype=$deptype | $DEPEND_CONTENT;
+                       }
+               }
+               if ($params{links}) {
+                       # Is the pagespec limited to terms that will continue
+                       # to match pages as long as those pages exist and
+                       # link to the same places?
+                       my $links_limited=1;
+                       while ($links_limited && $pagespec=~m/(\w+)\([^\)]*\)/g) {
+                               $links_limited = $1 =~ /^(glob|internal|creation_month|creation_day|creation_year|created_before|created_after|backlink)$/;
+                       }
+                       if ($links_limited) {
+                               $deptype=$deptype | $DEPEND_LINKS;
+                       }
+                       else {
+                               $deptype=$deptype | $DEPEND_CONTENT;
                        }
                }
                        }
                }
-               return;
+       }
+       $deptype=$DEPEND_CONTENT unless $deptype;
+
+       if ($simple) {
+               $depends_simple{$page}{lc $pagespec} |= $deptype;
+               return 1;
        }
 
        return unless pagespec_valid($pagespec);
 
        }
 
        return unless pagespec_valid($pagespec);
 
-       $depends{$page}{$pagespec} = 1;
+       $depends{$page}{$pagespec} |= $deptype;
        return 1;
 }
 
        return 1;
 }
 
@@ -1833,14 +1903,6 @@ sub add_link ($$) {
                unless grep { $_ eq $link } @{$links{$page}};
 }
 
                unless grep { $_ eq $link } @{$links{$page}};
 }
 
-sub pagespec_merge ($$) {
-       my $a=shift;
-       my $b=shift;
-
-       return $a if $a eq $b;
-       return "($a) or ($b)";
-}
-
 sub pagespec_translate ($) {
        my $spec=shift;
 
 sub pagespec_translate ($) {
        my $spec=shift;
 
@@ -1861,7 +1923,7 @@ sub pagespec_translate ($) {
                        [^\s()]+        # any other text
                )
                \s*             # ignore whitespace
                        [^\s()]+        # any other text
                )
                \s*             # ignore whitespace
-       }igx) {
+       }gx) {
                my $word=$1;
                if (lc $word eq 'and') {
                        $code.=' &&';
                my $word=$1;
                if (lc $word eq 'and') {
                        $code.=' &&';
@@ -2043,10 +2105,10 @@ sub match_link ($$;@) {
                else {
                        return IkiWiki::SuccessReason->new("$page links to page $p matching $link")
                                if match_glob($p, $link, %params);
                else {
                        return IkiWiki::SuccessReason->new("$page links to page $p matching $link")
                                if match_glob($p, $link, %params);
-                       $p=~s/^\///;
+                       my ($p_rel)=$p=~/^\/?(.*)/;
                        $link=~s/^\///;
                        $link=~s/^\///;
-                       return IkiWiki::SuccessReason->new("$page links to page $p matching $link")
-                               if match_glob($p, $link, %params);
+                       return IkiWiki::SuccessReason->new("$page links to page $p_rel matching $link")
+                               if match_glob($p_rel, $link, %params);
                }
        }
        return IkiWiki::FailReason->new("$page does not link to $link");
                }
        }
        return IkiWiki::FailReason->new("$page does not link to $link");