summaryrefslogtreecommitdiff
path: root/IkiWiki
diff options
context:
space:
mode:
Diffstat (limited to 'IkiWiki')
-rw-r--r--IkiWiki/Plugin/brokenlinks.pm14
-rw-r--r--IkiWiki/Plugin/calendar.pm86
-rw-r--r--IkiWiki/Plugin/conditional.pm26
-rw-r--r--IkiWiki/Plugin/edittemplate.pm2
-rw-r--r--IkiWiki/Plugin/img.pm2
-rw-r--r--IkiWiki/Plugin/inline.pm60
-rw-r--r--IkiWiki/Plugin/linkmap.pm15
-rw-r--r--IkiWiki/Plugin/listdirectives.pm2
-rw-r--r--IkiWiki/Plugin/map.pm24
-rw-r--r--IkiWiki/Plugin/meta.pm10
-rw-r--r--IkiWiki/Plugin/orphans.pm44
-rw-r--r--IkiWiki/Plugin/pagecount.pm24
-rw-r--r--IkiWiki/Plugin/pagestats.pm24
-rw-r--r--IkiWiki/Plugin/postsparkline.pm14
-rw-r--r--IkiWiki/Plugin/progress.pm16
-rw-r--r--IkiWiki/Render.pm355
16 files changed, 402 insertions, 316 deletions
diff --git a/IkiWiki/Plugin/brokenlinks.pm b/IkiWiki/Plugin/brokenlinks.pm
index eb698b0be..8ee734bf9 100644
--- a/IkiWiki/Plugin/brokenlinks.pm
+++ b/IkiWiki/Plugin/brokenlinks.pm
@@ -23,19 +23,15 @@ sub preprocess (@) {
my %params=@_;
$params{pages}="*" unless defined $params{pages};
- # Needs to update whenever a page is added or removed, so
- # register a dependency.
- add_depends($params{page}, $params{pages});
-
my @broken;
foreach my $link (keys %IkiWiki::brokenlinks) {
next if $link =~ /.*\/\Q$config{discussionpage}\E/i && $config{discussion};
- my @pages;
- foreach my $page (@{$IkiWiki::brokenlinks{$link}}) {
- push @pages, $page
- if pagespec_match($page, $params{pages}, location => $params{page});
- }
+ my @pages=pagespec_match_list($params{page}, $params{pages},
+ list => $IkiWiki::brokenlinks{$link},
+ # needs to update when links on a page change
+ deptype => deptype("links")
+ );
next unless @pages;
my $page=$IkiWiki::brokenlinks{$link}->[0];
diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm
index 5d16dff75..c50d038df 100644
--- a/IkiWiki/Plugin/calendar.pm
+++ b/IkiWiki/Plugin/calendar.pm
@@ -24,8 +24,6 @@ use IkiWiki 3.00;
use Time::Local;
use POSIX;
-my %cache;
-my %linkcache;
my $time=time;
my @now=localtime($time);
@@ -75,6 +73,23 @@ sub format_month (@) {
my $pyear = $params{pyear};
my $nyear = $params{nyear};
+ my %linkcache;
+ foreach my $p (pagespec_match_list($params{page}, $params{pagespec},
+ # add presence dependencies to update
+ # month calendar when pages are added/removed
+ deptype => deptype("presence"))) {
+ my $mtime = $IkiWiki::pagectime{$p};
+ my $src = $pagesources{$p};
+ my @date = localtime($mtime);
+ my $mday = $date[3];
+ my $month = $date[4] + 1;
+ my $year = $date[5] + 1900;
+ my $mtag = sprintf("%02d", $month);
+
+ # Only one posting per day is being linked to.
+ $linkcache{"$year/$mtag/$mday"} = "$src";
+ }
+
my @list;
my $calendar="\n";
@@ -99,24 +114,27 @@ sub format_month (@) {
# Calculate URL's for monthly archives.
my ($url, $purl, $nurl)=("$monthname",'','');
- if (exists $cache{$pagespec}{"$year/$month"}) {
+ if (exists $pagesources{"$archivebase/$year/$month"}) {
$url = htmllink($params{page}, $params{destpage},
"$archivebase/$year/".sprintf("%02d", $month),
linktext => " $monthname ");
}
- add_depends($params{page}, "$archivebase/$year/".sprintf("%02d", $month));
- if (exists $cache{$pagespec}{"$pyear/$pmonth"}) {
+ add_depends($params{page}, "$archivebase/$year/".sprintf("%02d", $month),
+ deptype("presence"));
+ if (exists $pagesources{"$archivebase/$pyear/$pmonth"}) {
$purl = htmllink($params{page}, $params{destpage},
"$archivebase/$pyear/" . sprintf("%02d", $pmonth),
linktext => " $pmonthname ");
}
- add_depends($params{page}, "$archivebase/$pyear/".sprintf("%02d", $pmonth));
- if (exists $cache{$pagespec}{"$nyear/$nmonth"}) {
+ add_depends($params{page}, "$archivebase/$pyear/".sprintf("%02d", $pmonth),
+ deptype("presence"));
+ if (exists $pagesources{"$archivebase/$nyear/$nmonth"}) {
$nurl = htmllink($params{page}, $params{destpage},
"$archivebase/$nyear/" . sprintf("%02d", $nmonth),
linktext => " $nmonthname ");
}
- add_depends($params{page}, "$archivebase/$nyear/".sprintf("%02d", $nmonth));
+ add_depends($params{page}, "$archivebase/$nyear/".sprintf("%02d", $nmonth),
+ deptype("presence"));
# Start producing the month calendar
$calendar=<<EOF;
@@ -170,7 +188,7 @@ EOF
my $tag;
my $mtag = sprintf("%02d", $month);
- if (defined $cache{$pagespec}{"$year/$mtag/$day"}) {
+ if (defined $pagesources{"$archivebase/$year/$mtag/$day"}) {
if ($day == $today) {
$tag='month-calendar-day-this-day';
}
@@ -207,15 +225,6 @@ EOF
</table>
EOF
- # Add dependencies to update the calendar whenever pages
- # matching the pagespec are added or removed.
- add_depends($params{page}, $params{pages});
- # 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);
- }
-
return $calendar;
}
@@ -241,24 +250,24 @@ sub format_year (@) {
# calculate URL's for previous and next years
my ($url, $purl, $nurl)=("$year",'','');
- if (exists $cache{$pagespec}{"$year"}) {
+ if (exists $pagesources{"$archivebase/$year"}) {
$url = htmllink($params{page}, $params{destpage},
"$archivebase/$year",
linktext => "$year");
}
- add_depends($params{page}, "$archivebase/$year");
- if (exists $cache{$pagespec}{"$pyear"}) {
+ add_depends($params{page}, "$archivebase/$year", deptype("presence"));
+ if (exists $pagesources{"$archivebase/$pyear"}) {
$purl = htmllink($params{page}, $params{destpage},
"$archivebase/$pyear",
linktext => "\&larr;");
}
- add_depends($params{page}, "$archivebase/$pyear");
- if (exists $cache{$pagespec}{"$nyear"}) {
+ add_depends($params{page}, "$archivebase/$pyear", deptype("presence"));
+ if (exists $pagesources{"$archivebase/$nyear"}) {
$nurl = htmllink($params{page}, $params{destpage},
"$archivebase/$nyear",
linktext => "\&rarr;");
}
- add_depends($params{page}, "$archivebase/$nyear");
+ add_depends($params{page}, "$archivebase/$nyear", deptype("presence"));
# Start producing the year calendar
$calendar=<<EOF;
@@ -282,14 +291,14 @@ EOF
my $tag;
my $mtag=sprintf("%02d", $month);
if ($month == $params{month}) {
- if ($cache{$pagespec}{"$year/$mtag"}) {
+ if ($pagesources{"$archivebase/$year/$mtag"}) {
$tag = 'this_month_link';
}
else {
$tag = 'this_month_nolink';
}
}
- elsif ($cache{$pagespec}{"$year/$mtag"}) {
+ elsif ($pagesources{"$archivebase/$year/$mtag"}) {
$tag = 'month_link';
}
elsif ($future_month && $month >= $future_month) {
@@ -299,7 +308,7 @@ EOF
$tag = 'month_nolink';
}
- if ($cache{$pagespec}{"$year/$mtag"}) {
+ if ($pagesources{"$archivebase/$year/$mtag"}) {
$murl = htmllink($params{page}, $params{destpage},
"$archivebase/$year/$mtag",
linktext => "$monthabbr");
@@ -310,7 +319,8 @@ EOF
else {
$calendar.=qq{\t<td class="$tag">$monthabbr</td>\n};
}
- add_depends($params{page}, "$archivebase/$year/$mtag");
+ add_depends($params{page}, "$archivebase/$year/$mtag",
+ deptype("presence"));
$calendar.=qq{\t</tr>\n} if ($month % $params{months_per_row} == 0);
}
@@ -367,26 +377,6 @@ sub preprocess (@) {
$params{nyear} =$nyear;
my $calendar="\n";
- my $pagespec=$params{pages};
- my $page =$params{page};
-
- if (! defined $cache{$pagespec}) {
- foreach my $p (pagespec_match_list([keys %pagesources], $pagespec)) {
- my $mtime = $IkiWiki::pagectime{$p};
- my $src = $pagesources{$p};
- my @date = localtime($mtime);
- my $mday = $date[3];
- my $month = $date[4] + 1;
- my $year = $date[5] + 1900;
- my $mtag = sprintf("%02d", $month);
-
- # Only one posting per day is being linked to.
- $linkcache{"$year/$mtag/$mday"} = "$src";
- $cache{$pagespec}{"$year"}++;
- $cache{$pagespec}{"$year/$mtag"}++;
- $cache{$pagespec}{"$year/$mtag/$mday"}++;
- }
- }
if ($params{type} =~ /month/i) {
$calendar=format_month(%params);
diff --git a/IkiWiki/Plugin/conditional.pm b/IkiWiki/Plugin/conditional.pm
index 7445dbdad..aad617812 100644
--- a/IkiWiki/Plugin/conditional.pm
+++ b/IkiWiki/Plugin/conditional.pm
@@ -29,11 +29,10 @@ sub preprocess_if (@) {
}
my $result=0;
- if ((exists $params{all} && lc $params{all} eq "no") ||
- # An optimisation to avoid needless looping over every page
- # and adding of dependencies for simple uses of some of the
- # tests.
- $params{test} =~ /^([\s\!()]*((enabled|sourcepage|destpage|included)\([^)]*\)|(and|or))[\s\!()]*)+$/) {
+ if (! IkiWiki::yesno($params{all}) ||
+ # An optimisation to avoid needless looping over every page
+ # for simple uses of some of the tests.
+ $params{test} =~ /^([\s\!()]*((enabled|sourcepage|destpage|included)\([^)]*\)|(and|or))[\s\!()]*)+$/) {
add_depends($params{page}, "($params{test}) and $params{page}");
$result=pagespec_match($params{page}, $params{test},
location => $params{page},
@@ -41,17 +40,12 @@ sub preprocess_if (@) {
destpage => $params{destpage});
}
else {
- add_depends($params{page}, $params{test});
-
- foreach my $page (keys %pagesources) {
- if (pagespec_match($page, $params{test},
- location => $params{page},
- sourcepage => $params{page},
- destpage => $params{destpage})) {
- $result=1;
- last;
- }
- }
+ $result=pagespec_match_list($params{page}, $params{test},
+ # stop after first match
+ num => 1,
+ sourcepage => $params{page},
+ destpage => $params{destpage},
+ );
}
my $ret;
diff --git a/IkiWiki/Plugin/edittemplate.pm b/IkiWiki/Plugin/edittemplate.pm
index 0bafc95d0..7d2eba194 100644
--- a/IkiWiki/Plugin/edittemplate.pm
+++ b/IkiWiki/Plugin/edittemplate.pm
@@ -58,7 +58,7 @@ sub preprocess (@) {
$pagestate{$params{page}}{edittemplate}{$params{match}}=$link;
return "" if ($params{silent} && IkiWiki::yesno($params{silent}));
- add_depends($params{page}, $link);
+ add_depends($params{page}, $link, deptype("presence"));
return sprintf(gettext("edittemplate %s registered for %s"),
htmllink($params{page}, $params{destpage}, $link),
$params{match});
diff --git a/IkiWiki/Plugin/img.pm b/IkiWiki/Plugin/img.pm
index e2f541506..32023fa97 100644
--- a/IkiWiki/Plugin/img.pm
+++ b/IkiWiki/Plugin/img.pm
@@ -170,7 +170,7 @@ sub preprocess (@) {
my $b = bestlink($params{page}, $params{link});
if (length $b) {
- add_depends($params{page}, $b);
+ add_depends($params{page}, $b, deptype("presence"));
$imgtag=htmllink($params{page}, $params{destpage},
$params{link}, linktext => $imgtag,
noimageinline => 1);
diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm
index ccfadfd69..0fe0bd2e1 100644
--- a/IkiWiki/Plugin/inline.pm
+++ b/IkiWiki/Plugin/inline.pm
@@ -195,41 +195,38 @@ sub preprocess_inline (@) {
@list = map { bestlink($params{page}, $_) }
split ' ', $params{pagenames};
- }
- else {
- add_depends($params{page}, $params{pages});
- @list = pagespec_match_list(
- [ grep { $_ ne $params{page} } keys %pagesources ],
- $params{pages}, location => $params{page});
-
- if (exists $params{sort} && $params{sort} eq 'title') {
- @list=sort { pagetitle(basename($a)) cmp pagetitle(basename($b)) } @list;
+ if (yesno($params{reverse})) {
+ @list=reverse(@list);
}
- elsif (exists $params{sort} && $params{sort} eq 'title_natural') {
- eval q{use Sort::Naturally};
- if ($@) {
- error(gettext("Sort::Naturally needed for title_natural sort"));
- }
- @list=sort { Sort::Naturally::ncmp(pagetitle(basename($a)), pagetitle(basename($b))) } @list;
+
+ foreach my $p (@list) {
+ add_depends($params{page}, $p, deptype($quick ? "presence" : "content"));
}
- elsif (exists $params{sort} && $params{sort} eq 'mtime') {
- @list=sort { $pagemtime{$b} <=> $pagemtime{$a} } @list;
+ }
+ else {
+ my $num=0;
+ if ($params{show}) {
+ $num=$params{show};
}
- elsif (! exists $params{sort} || $params{sort} eq 'age') {
- @list=sort { $pagectime{$b} <=> $pagectime{$a} } @list;
+ if ($params{feedshow} && $num < $params{feedshow}) {
+ $num=$params{feedshow};
}
- else {
- error sprintf(gettext("unknown sort type %s"), $params{sort});
+ if ($params{skip}) {
+ $num+=$params{skip};
}
- }
- if (yesno($params{reverse})) {
- @list=reverse(@list);
+ @list = pagespec_match_list($params{page}, $params{pages},
+ deptype => deptype($quick ? "presence" : "content"),
+ filter => sub { $_[0] eq $params{page} },
+ sort => exists $params{sort} ? $params{sort} : "age",
+ reverse => yesno($params{reverse}),
+ num => $num,
+ );
}
if (exists $params{skip}) {
- @list=@list[$params{skip} .. scalar @list - 1];
+ @list=@list[$params{skip} .. $#list];
}
my @feedlist;
@@ -247,15 +244,12 @@ sub preprocess_inline (@) {
@list=@list[0..$params{show} - 1];
}
- # Explicitly add all currently displayed pages as dependencies, so
- # that if they are removed or otherwise changed, the inline will be
- # sure to be updated.
- foreach my $p ($#list >= $#feedlist ? @list : @feedlist) {
- add_depends($params{page}, $p);
- }
-
if ($feeds && exists $params{feedpages}) {
- @feedlist=pagespec_match_list(\@feedlist, $params{feedpages}, location => $params{page});
+ @feedlist = pagespec_match_list(
+ $params{page}, "($params{pages}) and ($params{feedpages})",
+ deptype => deptype($quick ? "presence" : "content"),
+ list => \@feedlist,
+ );
}
my ($feedbase, $feednum);
diff --git a/IkiWiki/Plugin/linkmap.pm b/IkiWiki/Plugin/linkmap.pm
index 941ed5f36..9540bd112 100644
--- a/IkiWiki/Plugin/linkmap.pm
+++ b/IkiWiki/Plugin/linkmap.pm
@@ -28,10 +28,6 @@ sub preprocess (@) {
$params{pages}="*" unless defined $params{pages};
- # Needs to update whenever a page is added or removed, so
- # register a dependency.
- add_depends($params{page}, $params{pages});
-
# Can't just return the linkmap here, since the htmlscrubber
# scrubs out all <object> tags (with good reason!)
# Instead, insert a placeholder tag, which will be expanded during
@@ -55,12 +51,11 @@ sub genmap ($) {
my %params=%{$maps{$mapnum}};
# Get all the items to map.
- my %mapitems = ();
- foreach my $item (keys %links) {
- if (pagespec_match($item, $params{pages}, location => $params{page})) {
- $mapitems{$item}=urlto($item, $params{destpage});
- }
- }
+ my %mapitems = map { $_ => urlto($_, $params{destpage}) }
+ pagespec_match_list($params{page}, $params{pages},
+ # update when a page is added or removed, or its
+ # links change
+ deptype => deptype("presence", "links"));
my $dest=$params{page}."/linkmap.png";
diff --git a/IkiWiki/Plugin/listdirectives.pm b/IkiWiki/Plugin/listdirectives.pm
index bd73f1a04..09f08c567 100644
--- a/IkiWiki/Plugin/listdirectives.pm
+++ b/IkiWiki/Plugin/listdirectives.pm
@@ -84,7 +84,7 @@ sub preprocess (@) {
foreach my $plugin (@pluginlist) {
$result .= '<li class="listdirectives">';
my $link=linkpage($config{directive_description_dir}."/".$plugin);
- add_depends($params{page}, $link);
+ add_depends($params{page}, $link, deptype("presence"));
$result .= htmllink($params{page}, $params{destpage}, $link);
$result .= '</li>';
}
diff --git a/IkiWiki/Plugin/map.pm b/IkiWiki/Plugin/map.pm
index 54146dc46..788b96827 100644
--- a/IkiWiki/Plugin/map.pm
+++ b/IkiWiki/Plugin/map.pm
@@ -28,12 +28,16 @@ sub preprocess (@) {
my %params=@_;
$params{pages}="*" unless defined $params{pages};
+ # Needs to update whenever a page is added or removed (or in some
+ # cases, when its content changes, if show= is specified).
+ my $deptype=deptype(exists $params{show} ? "content" : "presence");
+
my $common_prefix;
# Get all the items to map.
my %mapitems;
- foreach my $page (pagespec_match_list([keys %pagesources],
- $params{pages}, location => $params{page})) {
+ foreach my $page (pagespec_match_list($params{page}, $params{pages},
+ deptype => $deptype)) {
if (exists $params{show} &&
exists $pagestate{$page} &&
exists $pagestate{$page}{meta}{$params{show}}) {
@@ -67,16 +71,6 @@ sub preprocess (@) {
$common_prefix=IkiWiki::dirname($common_prefix);
}
- # Needs to update whenever a page is added or removed (or in some
- # cases, when its content changes, if show=title), so register a
- # dependency.
- add_depends($params{page}, $params{pages});
- # Explicitly add all currently shown pages, to detect when pages
- # are removed.
- foreach my $item (keys %mapitems) {
- add_depends($params{page}, $item);
- }
-
# Create the map.
my $parent="";
my $indent=0;
@@ -84,12 +78,12 @@ sub preprocess (@) {
my $addparent="";
my $map = "<div class='map'>\n";
- # Return empty div if %mapitems is empty
- if (!scalar(keys %mapitems)) {
+ if (! keys %mapitems) {
+ # return empty div for empty map
$map .= "</div>\n";
return $map;
}
- else { # continue populating $map
+ else {
$map .= "<ul>\n";
}
diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm
index 514b09369..8dcd73a1a 100644
--- a/IkiWiki/Plugin/meta.pm
+++ b/IkiWiki/Plugin/meta.pm
@@ -195,7 +195,7 @@ sub preprocess (@) {
if (! length $link) {
error gettext("redir page not found")
}
- add_depends($page, $link);
+ add_depends($page, $link, deptype("presence"));
$value=urlto($link, $page);
$value.='#'.$redir_anchor if defined $redir_anchor;
@@ -291,21 +291,21 @@ sub match {
if (defined $val) {
if ($val=~/^$re$/i) {
- return IkiWiki::SuccessReason->new("$re matches $field of $page");
+ return IkiWiki::SuccessReason->new("$re matches $field of $page", $page => $IkiWiki::DEPEND_CONTENT, "" => 1);
}
else {
- return IkiWiki::FailReason->new("$re does not match $field of $page");
+ return IkiWiki::FailReason->new("$re does not match $field of $page", "" => 1);
}
}
else {
- return IkiWiki::FailReason->new("$page does not have a $field");
+ return IkiWiki::FailReason->new("$page does not have a $field", "" => 1);
}
}
package IkiWiki::PageSpec;
sub match_title ($$;@) {
- IkiWiki::Plugin::meta::match("title", @_);
+ IkiWiki::Plugin::meta::match("title", @_);
}
sub match_author ($$;@) {
diff --git a/IkiWiki/Plugin/orphans.pm b/IkiWiki/Plugin/orphans.pm
index 711226772..702943f87 100644
--- a/IkiWiki/Plugin/orphans.pm
+++ b/IkiWiki/Plugin/orphans.pm
@@ -23,24 +23,34 @@ sub preprocess (@) {
my %params=@_;
$params{pages}="*" unless defined $params{pages};
- # Needs to update whenever a page is added or removed, so
- # register a dependency.
- add_depends($params{page}, $params{pages});
+ # Needs to update whenever a link changes, on any page
+ # since any page could link to one of the pages we're
+ # considering as orphans.
+ add_depends($params{page}, "*", deptype("links"));
- my @orphans;
- foreach my $page (pagespec_match_list(
- [ grep { ! IkiWiki::backlink_pages($_) && $_ ne 'index' }
- keys %pagesources ],
- $params{pages}, location => $params{page})) {
- # If the page has a link to some other page, it's
- # indirectly linked to a page via that page's backlinks.
- next if grep {
- length $_ &&
- ($_ !~ /\/\Q$config{discussionpage}\E$/i || ! $config{discussion}) &&
- bestlink($page, $_) !~ /^(\Q$page\E|)$/
- } @{$links{$page}};
- push @orphans, $page;
- }
+ my @orphans=pagespec_match_list($params{page}, $params{pages},
+ # update when orphans are added/removed
+ deptype => deptype("presence"),
+ filter => sub {
+ my $page=shift;
+
+ # Filter out pages that other pages link to.
+ return 1 if IkiWiki::backlink_pages($page);
+
+ # Toplevel index is assumed to never be orphaned.
+ return 1 if $page eq 'index';
+
+ # If the page has a link to some other page, it's
+ # indirectly linked via that page's backlinks.
+ return 1 if grep {
+ length $_ &&
+ ($_ !~ /\/\Q$config{discussionpage}\E$/i || ! $config{discussion}) &&
+ bestlink($page, $_) !~ /^(\Q$page\E|)$/
+ } @{$links{$page}};
+
+ return 0;
+ },
+ );
return gettext("All pages have other pages linking to them.") unless @orphans;
return "<ul>\n".
diff --git a/IkiWiki/Plugin/pagecount.pm b/IkiWiki/Plugin/pagecount.pm
index 5a2301af4..8d36f057e 100644
--- a/IkiWiki/Plugin/pagecount.pm
+++ b/IkiWiki/Plugin/pagecount.pm
@@ -20,20 +20,20 @@ sub getsetup () {
sub preprocess (@) {
my %params=@_;
- $params{pages}="*" unless defined $params{pages};
+ my $pages=defined $params{pages} ? $params{pages} : "*";
- # Needs to update count whenever a page is added or removed, so
- # register a dependency.
- add_depends($params{page}, $params{pages});
-
- my @pages;
- if ($params{pages} eq "*") {
- @pages=keys %pagesources;
- }
- else {
- @pages=pagespec_match_list([keys %pagesources], $params{pages}, location => $params{page});
+ # Just get a list of all the pages, and count the items in it.
+ # Use a presence dependency to only update when pages are added
+ # or removed.
+
+ if ($pages eq '*') {
+ # optimisation to avoid needing to try matching every page
+ add_depends($params{page}, $pages, deptype("presence"));
+ return scalar keys %pagesources;
}
- return $#pages+1;
+
+ return scalar pagespec_match_list($params{page}, $pages,
+ deptype => deptype("presence"));
}
1
diff --git a/IkiWiki/Plugin/pagestats.pm b/IkiWiki/Plugin/pagestats.pm
index 874ead7e6..47638210a 100644
--- a/IkiWiki/Plugin/pagestats.pm
+++ b/IkiWiki/Plugin/pagestats.pm
@@ -35,22 +35,28 @@ sub preprocess (@) {
$params{pages}="*" unless defined $params{pages};
my $style = ($params{style} or 'cloud');
- # Needs to update whenever a page is added or removed, so
- # register a dependency.
- add_depends($params{page}, $params{pages});
- add_depends($params{page}, $params{among}) if exists $params{among};
-
my %counts;
my $max = 0;
- foreach my $page (pagespec_match_list([keys %links],
- $params{pages}, location => $params{page})) {
+ foreach my $page (pagespec_match_list($params{page}, $params{pages},
+ # update when a displayed page is added/removed
+ deptype => deptype("presence"))) {
use IkiWiki::Render;
my @backlinks = IkiWiki::backlink_pages($page);
if (exists $params{among}) {
- @backlinks = pagespec_match_list(\@backlinks,
- $params{among}, location => $params{page});
+ # only consider backlinks from the amoung pages
+ @backlinks = pagespec_match_list(
+ $params{page}, $params{among},
+ # update whenever links on those pages change
+ deptype => deptype("links"),
+ list => \@backlinks
+ );
+ }
+ else {
+ # update when any page with links changes,
+ # in case the links point to our displayed pages
+ add_depends($params{page}, "*", deptype("links"));
}
$counts{$page} = scalar(@backlinks);
diff --git a/IkiWiki/Plugin/postsparkline.pm b/IkiWiki/Plugin/postsparkline.pm
index d2e5c2378..0d5a12e33 100644
--- a/IkiWiki/Plugin/postsparkline.pm
+++ b/IkiWiki/Plugin/postsparkline.pm
@@ -30,11 +30,16 @@ sub preprocess (@) {
return "";
}
+ my $deptype;
if (! exists $params{time} || $params{time} ne 'mtime') {
$params{timehash} = \%IkiWiki::pagectime;
+ # need to update when pages are added or removed
+ $deptype = deptype("presence");
}
else {
$params{timehash} = \%IkiWiki::pagemtime;
+ # need to update when pages are changed
+ $deptype = deptype("content");
}
if (! exists $params{formula}) {
@@ -48,12 +53,11 @@ sub preprocess (@) {
error gettext("unknown formula");
}
- add_depends($params{page}, $params{pages});
-
my @list=sort { $params{timehash}->{$b} <=> $params{timehash}->{$a} }
- pagespec_match_list(
- [ grep { $_ ne $params{page} } keys %pagesources],
- $params{pages}, location => $params{page});
+ pagespec_match_list($params{page}, $params{pages},
+ deptype => $deptype,
+ filter => sub { $_[0] eq $params{page} },
+ );
my @data=eval qq{IkiWiki::Plugin::postsparkline::formula::$formula(\\\%params, \@list)};
if ($@) {
diff --git a/IkiWiki/Plugin/progress.pm b/IkiWiki/Plugin/progress.pm
index 76d994acc..fe64b40b1 100644
--- a/IkiWiki/Plugin/progress.pm
+++ b/IkiWiki/Plugin/progress.pm
@@ -36,16 +36,12 @@ sub preprocess (@) {
$fill.="%";
}
elsif (defined $params{totalpages} and defined $params{donepages}) {
- add_depends($params{page}, $params{totalpages});
- add_depends($params{page}, $params{donepages});
-
- my @pages=keys %pagesources;
- my $totalcount=0;
- my $donecount=0;
- foreach my $page (@pages) {
- $totalcount++ if pagespec_match($page, $params{totalpages}, location => $params{page});
- $donecount++ if pagespec_match($page, $params{donepages}, location => $params{page});
- }
+ my $totalcount=pagespec_match_list(
+ $params{page}, $params{totalpages},
+ deptype => deptype("presence"));
+ my $donecount=pagespec_match_list(
+ $params{page}, $params{donepages},
+ deptype => deptype("presence"));
if ($totalcount == 0) {
$fill = "100%";
diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm
index a8236b954..0fe20c64f 100644
--- a/IkiWiki/Render.pm
+++ b/IkiWiki/Render.pm
@@ -7,7 +7,7 @@ use strict;
use IkiWiki;
use Encode;
-my %backlinks;
+my (%backlinks, %rendered);
our %brokenlinks;
my $links_calculated=0;
@@ -147,6 +147,8 @@ sub genpage ($$) {
sub scan ($) {
my $file=shift;
+ debug(sprintf(gettext("scanning %s"), $file));
+
my $type=pagetype($file);
if (defined $type) {
my $srcfile=srcfile($file);
@@ -202,8 +204,11 @@ sub fast_file_copy (@) {
}
}
-sub render ($) {
+sub render ($$) {
my $file=shift;
+ return if $rendered{$file};
+ debug(shift);
+ $rendered{$file}=1;
my $type=pagetype($file);
my $srcfile=srcfile($file);
@@ -273,7 +278,8 @@ sub srcdir_check () {
}
sub find_src_files () {
- my (@files, %pages);
+ my @files;
+ my %pages;
eval q{use File::Find};
error($@) if $@;
find({
@@ -334,19 +340,14 @@ sub find_src_files () {
},
}, $dir);
};
-
- # Returns a list of all source files found, and a hash of
- # the corresponding page names.
return \@files, \%pages;
}
-sub refresh () {
- srcdir_check();
- run_hooks(refresh => sub { shift->() });
- my ($files, $exists)=find_src_files();
+sub find_new_files ($) {
+ my $files=shift;
+ my @new;
+ my @internal_new;
- my (%rendered, @add, @del, @internal);
- # check for added or removed pages
foreach my $file (@$files) {
my $page=pagename($file);
if (exists $pagesources{$page} && $pagesources{$page} ne $file) {
@@ -356,10 +357,10 @@ sub refresh () {
$pagesources{$page}=$file;
if (! $pagemtime{$page}) {
if (isinternal($page)) {
- push @internal, $file;
+ push @internal_new, $file;
}
else {
- push @add, $file;
+ push @new, $file;
if ($config{getctime} && -e "$config{srcdir}/$file") {
eval {
my $time=rcs_getctime("$config{srcdir}/$file");
@@ -376,10 +377,19 @@ sub refresh () {
}
}
}
+
+ return \@new, \@internal_new;
+}
+
+sub find_del_files ($) {
+ my $pages=shift;
+ my @del;
+ my @internal_del;
+
foreach my $page (keys %pagemtime) {
- if (! $exists->{$page}) {
+ if (! $pages->{$page}) {
if (isinternal($page)) {
- push @internal, $pagesources{$page};
+ push @internal_del, $pagesources{$page};
}
else {
debug(sprintf(gettext("removing old page %s"), $page));
@@ -400,8 +410,13 @@ sub refresh () {
}
}
- # find changed and new files
- my @needsbuild;
+ return \@del, \@internal_del;
+}
+
+sub find_changed ($) {
+ my $files=shift;
+ my @changed;
+ my @internal_changed;
foreach my $file (@$files) {
my $page=pagename($file);
my ($srcfile, @stat)=srcfile_stat($file);
@@ -409,150 +424,242 @@ sub refresh () {
$stat[9] > $pagemtime{$page} ||
$forcerebuild{$page}) {
$pagemtime{$page}=$stat[9];
+
if (isinternal($page)) {
- push @internal, $file;
# Preprocess internal page in scan-only mode.
preprocess($page, $page, readfile($srcfile), 1);
+ push @internal_changed, $file;
}
else {
- push @needsbuild, $file;
+ push @changed, $file;
}
}
}
- run_hooks(needsbuild => sub { shift->(\@needsbuild) });
+ return \@changed, \@internal_changed;
+}
- # scan and render files
- foreach my $file (@needsbuild) {
- debug(sprintf(gettext("scanning %s"), $file));
- scan($file);
- }
- calculate_links();
- foreach my $file (@needsbuild) {
- debug(sprintf(gettext("building %s"), $file));
- render($file);
- $rendered{$file}=1;
- }
- foreach my $file (@internal) {
- # internal pages are not rendered
+sub calculate_old_links ($$) {
+ my ($changed, $del)=@_;
+ my %oldlink_targets;
+ foreach my $file (@$changed, @$del) {
my $page=pagename($file);
- delete $depends{$page};
- delete $depends_simple{$page};
- foreach my $old (@{$renderedfiles{$page}}) {
- delete $destsources{$old};
+ if (exists $oldlinks{$page}) {
+ foreach my $l (@{$oldlinks{$page}}) {
+ $oldlink_targets{$page}{$l}=bestlink($page, $l);
+ }
}
- $renderedfiles{$page}=[];
}
-
- # rebuild pages that link to added or removed pages
- if (@add || @del) {
- foreach my $f (@add, @del) {
- my $p=pagename($f);
- foreach my $page (keys %{$backlinks{$p}}) {
- my $file=$pagesources{$page};
- next if $rendered{$file};
- debug(sprintf(gettext("building %s, which links to %s"), $file, $p));
- render($file);
- $rendered{$file}=1;
+ return \%oldlink_targets;
+}
+
+sub derender_internal ($) {
+ my $file=shift;
+ my $page=pagename($file);
+ delete $depends{$page};
+ delete $depends_simple{$page};
+ foreach my $old (@{$renderedfiles{$page}}) {
+ delete $destsources{$old};
+ }
+ $renderedfiles{$page}=[];
+}
+
+sub render_linkers ($) {
+ my $f=shift;
+ my $p=pagename($f);
+ foreach my $page (keys %{$backlinks{$p}}) {
+ my $file=$pagesources{$page};
+ render($file, sprintf(gettext("building %s, which links to %s"), $file, $p));
+ }
+}
+
+sub remove_unrendered () {
+ foreach my $src (keys %rendered) {
+ my $page=pagename($src);
+ foreach my $file (@{$oldrenderedfiles{$page}}) {
+ if (! grep { $_ eq $file } @{$renderedfiles{$page}}) {
+ debug(sprintf(gettext("removing %s, no longer built by %s"), $file, $page));
+ prune($config{destdir}."/".$file);
}
}
}
+}
- if (%rendered || @del || @internal) {
- my @changed=(keys %rendered, @del);
+sub calculate_changed_links ($$$) {
+ my ($changed, $del, $oldlink_targets)=@_;
- my %lcchanged = map { lc(pagename($_)) => 1 } @changed;
-
- # rebuild dependant pages
- foreach my $f (@$files) {
- next if $rendered{$f};
- my $p=pagename($f);
- my $reason = undef;
+ my (%backlinkchanged, %linkchangers);
- if (exists $depends_simple{$p}) {
- foreach my $d (keys %{$depends_simple{$p}}) {
- if (exists $lcchanged{$d}) {
- $reason = $d;
- last;
- }
+ foreach my $file (@$changed, @$del) {
+ my $page=pagename($file);
+
+ if (exists $links{$page}) {
+ foreach my $l (@{$links{$page}}) {
+ my $target=bestlink($page, $l);
+ if (! exists $oldlink_targets->{$page}{$l} ||
+ $target ne $oldlink_targets->{$page}{$l}) {
+ $backlinkchanged{$target}=1;
+ $linkchangers{lc($page)}=1;
}
+ delete $oldlink_targets->{$page}{$l};
}
+ }
+ if (exists $oldlink_targets->{$page} &&
+ %{$oldlink_targets->{$page}}) {
+ foreach my $target (values %{$oldlink_targets->{$page}}) {
+ $backlinkchanged{$target}=1;
+ }
+ $linkchangers{lc($page)}=1;
+ }
+ }
- if (exists $depends{$p} && ! defined $reason) {
- D: foreach my $d (keys %{$depends{$p}}) {
- my $sub=pagespec_translate($d);
- next if $@ || ! defined $sub;
+ return \%backlinkchanged, \%linkchangers;
+}
- # only consider internal files
- # if the page explicitly depends
- # on such files
- foreach my $file (@changed, $d =~ /internal\(/ ? @internal : ()) {
+sub render_dependent ($$$$$$$) {
+ my ($files, $new, $internal_new, $del, $internal_del,
+ $internal_changed, $linkchangers)=@_;
+
+ my @changed=(keys %rendered, @$del);
+ my @exists_changed=(@$new, @$del);
+
+ my %lc_changed = map { lc(pagename($_)) => 1 } @changed;
+ my %lc_exists_changed = map { lc(pagename($_)) => 1 } @exists_changed;
+
+ foreach my $f (@$files) {
+ next if $rendered{$f};
+ my $p=pagename($f);
+ my $reason = undef;
+
+ if (exists $depends_simple{$p}) {
+ foreach my $d (keys %{$depends_simple{$p}}) {
+ if (($depends_simple{$p}{$d} & $IkiWiki::DEPEND_CONTENT &&
+ $lc_changed{$d})
+ ||
+ ($depends_simple{$p}{$d} & $IkiWiki::DEPEND_PRESENCE &&
+ $lc_exists_changed{$d})
+ ||
+ ($depends_simple{$p}{$d} & $IkiWiki::DEPEND_LINKS &&
+ $linkchangers->{$d})
+ ) {
+ $reason = $d;
+ last;
+ }
+ }
+ }
+
+ if (exists $depends{$p} && ! defined $reason) {
+ foreach my $dep (keys %{$depends{$p}}) {
+ my $sub=pagespec_translate($dep);
+ next if $@ || ! defined $sub;
+
+ # only consider internal files
+ # if the page explicitly depends
+ # on such files
+ my $internal_dep=$dep =~ /internal\(/;
+
+ my $in=sub {
+ my $list=shift;
+ my $type=shift;
+ foreach my $file (@$list) {
next if $file eq $f;
my $page=pagename($file);
if ($sub->($page, location => $p)) {
- $reason = $page;
- last D;
+ if ($type == $IkiWiki::DEPEND_LINKS) {
+ next unless $linkchangers->{lc($page)};
+ }
+ return $page;
}
}
+ return undef;
+ };
+
+ if ($depends{$p}{$dep} & $IkiWiki::DEPEND_CONTENT) {
+ last if $reason =
+ $in->(\@changed, $IkiWiki::DEPEND_CONTENT);
+ last if $internal_dep && ($reason =
+ $in->($internal_new, $IkiWiki::DEPEND_CONTENT) ||
+ $in->($internal_del, $IkiWiki::DEPEND_CONTENT) ||
+ $in->($internal_changed, $IkiWiki::DEPEND_CONTENT));
}
- }
-
- if (defined $reason) {
- debug(sprintf(gettext("building %s, which depends on %s"), $f, $reason));
- render($f);
- $rendered{$f}=1;
- }
- }
-
- # handle backlinks; if a page has added/removed links,
- # update the pages it links to
- my %linkchanged;
- foreach my $file (@changed) {
- my $page=pagename($file);
-
- if (exists $links{$page}) {
- foreach my $link (map { bestlink($page, $_) } @{$links{$page}}) {
- if (length $link &&
- (! exists $oldlinks{$page} ||
- ! grep { bestlink($page, $_) eq $link } @{$oldlinks{$page}})) {
- $linkchanged{$link}=1;
- }
+ if ($depends{$p}{$dep} & $IkiWiki::DEPEND_PRESENCE) {
+ last if $reason =
+ $in->(\@exists_changed, $IkiWiki::DEPEND_PRESENCE);
+ last if $internal_dep && ($reason =
+ $in->($internal_new, $IkiWiki::DEPEND_PRESENCE) ||
+ $in->($internal_del, $IkiWiki::DEPEND_PRESENCE));
}
- }
- if (exists $oldlinks{$page}) {
- foreach my $link (map { bestlink($page, $_) } @{$oldlinks{$page}}) {
- if (length $link &&
- (! exists $links{$page} ||
- ! grep { bestlink($page, $_) eq $link } @{$links{$page}})) {
- $linkchanged{$link}=1;
- }
+ if ($depends{$p}{$dep} & $IkiWiki::DEPEND_LINKS) {
+ last if $reason =
+ $in->(\@changed, $IkiWiki::DEPEND_LINKS);
+ last if $internal_dep && ($reason =
+ $in->($internal_new, $IkiWiki::DEPEND_LINKS) ||
+ $in->($internal_del, $IkiWiki::DEPEND_LINKS) ||
+ $in->($internal_changed, $IkiWiki::DEPEND_LINKS));
}
}
}
-
- foreach my $link (keys %linkchanged) {
- my $linkfile=$pagesources{$link};
- if (defined $linkfile) {
- next if $rendered{$linkfile};
- debug(sprintf(gettext("building %s, to update its backlinks"), $linkfile));
- render($linkfile);
- $rendered{$linkfile}=1;
- }
+
+ if (defined $reason) {
+ render($f, sprintf(gettext("building %s, which depends on %s"), $f, $reason));
+ return 1;
}
}
- # remove no longer rendered files
- foreach my $src (keys %rendered) {
- my $page=pagename($src);
- foreach my $file (@{$oldrenderedfiles{$page}}) {
- if (! grep { $_ eq $file } @{$renderedfiles{$page}}) {
- debug(sprintf(gettext("removing %s, no longer built by %s"), $file, $page));
- prune($config{destdir}."/".$file);
- }
+ return 0;
+}
+
+sub render_backlinks ($) {
+ my $backlinkchanged=shift;
+ foreach my $link (keys %$backlinkchanged) {
+ my $linkfile=$pagesources{$link};
+ if (defined $linkfile) {
+ render($linkfile, sprintf(gettext("building %s, to update its backlinks"), $linkfile));
}
}
+}
+
+sub refresh () {
+ srcdir_check();
+ run_hooks(refresh => sub { shift->() });
+ my ($files, $pages)=find_src_files();
+ my ($new, $internal_new)=find_new_files($files);
+ my ($del, $internal_del)=find_del_files($pages);
+ my ($changed, $internal_changed)=find_changed($files);
+ run_hooks(needsbuild => sub { shift->($changed) });
+ my $oldlink_targets=calculate_old_links($changed, $del);
+
+ foreach my $file (@$changed) {
+ scan($file);
+ }
+
+ calculate_links();
+
+ foreach my $file (@$changed) {
+ render($file, sprintf(gettext("building %s"), $file));
+ }
+ foreach my $file (@$internal_new, @$internal_del, @$internal_changed) {
+ derender_internal($file);
+ }
+
+ my ($backlinkchanged, $linkchangers)=calculate_changed_links($changed,
+ $del, $oldlink_targets);
+
+ foreach my $file (@$new, @$del) {
+ render_linkers($file);
+ }
+
+ if (@$changed || @$internal_changed ||
+ @$del || @$internal_del || @$internal_new) {
+ 1 while render_dependent($files, $new, $internal_new,
+ $del, $internal_del, $internal_changed,
+ $linkchangers);
+ }
+
+ render_backlinks($backlinkchanged);
+ remove_unrendered();
- if (@del) {
- run_hooks(delete => sub { shift->(@del) });
+ if (@$del) {
+ run_hooks(delete => sub { shift->(@$del) });
}
if (%rendered) {
run_hooks(change => sub { shift->(keys %rendered) });