our $installdir='/usr'; # INSTALLDIR_AUTOREPLACE done by Makefile, DNE
# Page dependency types.
-our $DEPEND_EXISTS=1;
-our $DEPEND_CONTENT=2;
+our $DEPEND_CONTENT=1;
+our $DEPEND_PRESENCE=2;
# Optimisation.
use Memoize;
if (exists $d->{dependslist}) {
# old format
$depends{$page}={
- map { $_ => $DEPEND_CONTENT | $DEPEND_EXISTS }
+ map { $_ => $DEPEND_CONTENT }
@{$d->{dependslist}}
};
}
elsif (exists $d->{depends} && ! ref $d->{depends}) {
# old format
- $depends{$page}={$d->{depends} => $DEPEND_CONTENT | $DEPEND_EXISTS};
+ $depends{$page}={$d->{depends} => $DEPEND_CONTENT };
}
elsif (exists $d->{depends}) {
$depends{$page}=$d->{depends};
my $page=shift;
my $pagespec=shift;
+ # Is the pagespec a simple page name?
my $simple=$pagespec =~ /$config{wiki_file_regexp}/ &&
$pagespec !~ /[\s*?()!]/;
- my $deptype=$DEPEND_CONTENT | $DEPEND_EXISTS;
+ my $deptype=$DEPEND_CONTENT;
if (@_) {
my %params=@_;
- if (defined $params{content} && $params{content} == 0 &&
- ($simple || pagespec_contentless($pagespec))) {
- $deptype=$deptype & ~$DEPEND_CONTENT;
+
+ # Is the pagespec limited to terms that will continue
+ # to match pages as long as those pages exist?
+ my $limited=1;
+ while ($limited && $pagespec=~m/(\w+)\([^\)]*\)/g) {
+ $limited = $1 =~ /^(glob|internal|creation_month|creation_day|creation_year|created_before|created_after)$/;
}
+
+ $deptype=$deptype & ~$DEPEND_CONTENT & $DEPEND_PRESENCE
+ if $params{presence} && $limited;
}
if ($simple) {
return ! $@;
}
-sub pagespec_contentless ($) {
- my $spec=shift;
-
- while ($spec=~m{
- (\w+)\([^\)]*\) # only match pagespec functions
- }igx) {
- return 0 unless $1=~/^(glob|internal|creation_month|creation_day|creation_year|created_before|created_after)$/;
- }
-
- return 1;
-}
-
sub glob2re ($) {
my $re=quotemeta(shift);
$re=~s/\\\*/.*/g;
linktext => " $monthname ");
}
add_depends($params{page}, "$archivebase/$year/".sprintf("%02d", $month),
- content => 0);
+ presence => 1);
if (exists $cache{$pagespec}{"$pyear/$pmonth"}) {
$purl = htmllink($params{page}, $params{destpage},
"$archivebase/$pyear/" . sprintf("%02d", $pmonth),
linktext => " $pmonthname ");
}
add_depends($params{page}, "$archivebase/$pyear/".sprintf("%02d", $pmonth),
- content => 0);
+ presence => 1);
if (exists $cache{$pagespec}{"$nyear/$nmonth"}) {
$nurl = htmllink($params{page}, $params{destpage},
"$archivebase/$nyear/" . sprintf("%02d", $nmonth),
linktext => " $nmonthname ");
}
add_depends($params{page}, "$archivebase/$nyear/".sprintf("%02d", $nmonth),
- content => 0);
+ presence => 1);
# Start producing the month calendar
$calendar=<<EOF;
# Add dependencies to update the calendar whenever pages
# matching the pagespec are added or removed.
- add_depends($params{page}, $params{pages}, content => 0);
+ add_depends($params{page}, $params{pages}, presence => 1);
# Explicitly add all currently linked pages as dependencies, so
# that if they are removed, the calendar will be sure to be updated.
foreach my $p (@list) {
- add_depends($params{page}, $p, content => 0);
+ add_depends($params{page}, $p, presence => 1);
}
return $calendar;
"$archivebase/$year",
linktext => "$year");
}
- add_depends($params{page}, "$archivebase/$year", content => 0);
+ add_depends($params{page}, "$archivebase/$year", presence => 1);
if (exists $cache{$pagespec}{"$pyear"}) {
$purl = htmllink($params{page}, $params{destpage},
"$archivebase/$pyear",
linktext => "\←");
}
- add_depends($params{page}, "$archivebase/$pyear", content => 0);
+ add_depends($params{page}, "$archivebase/$pyear", presence => 1);
if (exists $cache{$pagespec}{"$nyear"}) {
$nurl = htmllink($params{page}, $params{destpage},
"$archivebase/$nyear",
linktext => "\→");
}
- add_depends($params{page}, "$archivebase/$nyear", content => 0);
+ add_depends($params{page}, "$archivebase/$nyear", presence => 1);
# Start producing the year calendar
$calendar=<<EOF;
else {
$calendar.=qq{\t<td class="$tag">$monthabbr</td>\n};
}
- add_depends($params{page}, "$archivebase/$year/$mtag", content => 0);
+ add_depends($params{page}, "$archivebase/$year/$mtag", presence => 1);
$calendar.=qq{\t</tr>\n} if ($month % $params{months_per_row} == 0);
}
$pagestate{$params{page}}{edittemplate}{$params{match}}=$link;
return "" if ($params{silent} && IkiWiki::yesno($params{silent}));
- add_depends($params{page}, $link, content => 0);
+ add_depends($params{page}, $link, presence => 1);
return sprintf(gettext("edittemplate %s registered for %s"),
htmllink($params{page}, $params{destpage}, $link),
$params{match});
foreach my $plugin (@pluginlist) {
$result .= '<li class="listdirectives">';
my $link=linkpage($config{directive_description_dir}."/".$plugin);
- add_depends($params{page}, $link, content => 0);
+ add_depends($params{page}, $link, presence => 1);
$result .= htmllink($params{page}, $params{destpage}, $link);
$result .= '</li>';
}
if (! length $link) {
error gettext("redir page not found")
}
- add_depends($page, $link, content => 0);
+ add_depends($page, $link, presence => 1);
$value=urlto($link, $page);
$value.='#'.$redir_anchor if defined $redir_anchor;
$params{pages}="*" unless defined $params{pages};
# Needs to update count whenever a page is added or removed, so
- # register a contentless dependency.
- add_depends($params{page}, $params{pages}, content => 0);
+ # register a presence dependency.
+ add_depends($params{page}, $params{pages}, presence => 1);
my @pages;
if ($params{pages} eq "*") {
error gettext("unknown formula");
}
- add_depends($params{page}, $params{pages}, content => 0);
+ add_depends($params{page}, $params{pages}, presence => 1);
my @list=sort { $params{timehash}->{$b} <=> $params{timehash}->{$a} }
pagespec_match_list(
$fill.="%";
}
elsif (defined $params{totalpages} and defined $params{donepages}) {
- add_depends($params{page}, $params{totalpages}, content => 0);
- add_depends($params{page}, $params{donepages}, content => 0);
+ add_depends($params{page}, $params{totalpages}, presence => 1);
+ add_depends($params{page}, $params{donepages}, presence => 1);
my @pages=keys %pagesources;
my $totalcount=0;
if (exists $depends_simple{$p}) {
foreach my $d (keys %{$depends_simple{$p}}) {
- if ($depends_simple{$p}{$d} == $IkiWiki::DEPEND_EXISTS) {
- if (exists $lc_exists_changed{$d}) {
- $reason = $d;
- last;
- }
- }
- elsif (exists $lc_changed{$d}) {
+ if (($depends_simple{$p}{$d} & $IkiWiki::DEPEND_CONTENT &&
+ exists $lc_changed{$d})
+ ||
+ ($depends_simple{$p}{$d} & $IkiWiki::DEPEND_PRESENCE &&
+ exists $lc_exists_changed{$d})) {
$reason = $d;
last;
}
next if $@ || ! defined $sub;
my @candidates;
- if ($depends{$p}{$d} == $IkiWiki::DEPEND_EXISTS) {
- @candidates=@exists_changed;
- }
- else {
+ if ($depends_simple{$p}{$d} & $IkiWiki::DEPEND_CONTENT) {
@candidates=@changed;
}
+ elsif ($depends{$p}{$d} & $IkiWiki::DEPEND_PRESENCE) {
+ @candidates=@exists_changed;
+ }
# only consider internal files
# if the page explicitly depends
# on such files
if ($d =~ /internal\(/) {
- if ($depends{$p}{$d} == $IkiWiki::DEPEND_EXISTS) {
- push @candidates, @internal;
- }
- else {
+ if ($depends_simple{$p}{$d} & $IkiWiki::DEPEND_CONTENT) {
push @candidates, @internal, @internal_change;
}
+ elsif ($depends{$p}{$d} & $IkiWiki::DEPEND_PRESENCE) {
+ push @candidates, @internal;
+ }
}
foreach my $file (@candidates) {
Makes the specified page depend on the specified [[ikiwiki/PageSpec]].
-Additional named parameters can be passed, to indicate what type of
-dependency this is.
-
-Currently, only a "content" parameter is specified. If set to 0, the
-dependency does not involve the content of pages matching the PageSpec, but
-only their existence.
+By default, dependencies are full content dependencies, meaning that the
+page will be updated whenever anything matching the PageSpec is modified.
+This default can be overridden by additional named parameters, which can be
+used to indicate weaker types of dependencies:
+
+* `presence` if set to true, only the presence of a matching page triggers
+ the dependency.
+* `links` if set to true, any change in the text of links on a matching page
+ triggers the dependency
#### `pagespec_match($$;@)`
$pagemtime{$page}=$items{mtime}[0];
$oldlinks{$page}=[@{$items{link}}];
$links{$page}=[@{$items{link}}];
- $depends{$page}={ $items{depends}[0] => $IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_EXISTS } if exists $items{depends};
+ $depends{$page}={ $items{depends}[0] => $IkiWiki::DEPEND_CONTENT } if exists $items{depends};
$destsources{$_}=$page foreach @{$items{dest}};
$renderedfiles{$page}=[@{$items{dest}}];
$pagecase{lc $page}=$page;