From dc4e44adf13bc20c0a801f2b176370f330841098 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 3 Oct 2009 15:36:23 -0400 Subject: pagecount: Use contentless dependency This will avoid lots of unnecessary updates of pages using the pagecount directive. Yay! --- IkiWiki/Plugin/pagecount.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/pagecount.pm b/IkiWiki/Plugin/pagecount.pm index 5a2301af4..17eda0618 100644 --- a/IkiWiki/Plugin/pagecount.pm +++ b/IkiWiki/Plugin/pagecount.pm @@ -23,8 +23,8 @@ sub preprocess (@) { $params{pages}="*" unless defined $params{pages}; # Needs to update count whenever a page is added or removed, so - # register a dependency. - add_depends($params{page}, $params{pages}); + # register a contentless dependency. + add_depends($params{page}, $params{pages}, content => 0); my @pages; if ($params{pages} eq "*") { -- cgit v1.2.3 From 6eaf9e40154050936ad9184d64295664da2cc83c Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 3 Oct 2009 15:55:11 -0400 Subject: orphans and brokenlinks cannot use contentless dependency Tried a contentless dep and it does not work; changes to links in pages are not noticed. Drat. --- IkiWiki/Plugin/brokenlinks.pm | 4 ++-- IkiWiki/Plugin/orphans.pm | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/brokenlinks.pm b/IkiWiki/Plugin/brokenlinks.pm index eb698b0be..b8ed2b8de 100644 --- a/IkiWiki/Plugin/brokenlinks.pm +++ b/IkiWiki/Plugin/brokenlinks.pm @@ -23,8 +23,8 @@ sub preprocess (@) { my %params=@_; $params{pages}="*" unless defined $params{pages}; - # Needs to update whenever a page is added or removed, so - # register a dependency. + # Needs to update whenever a page is changed, + # added or removed, in order to see the link changes. add_depends($params{page}, $params{pages}); my @broken; diff --git a/IkiWiki/Plugin/orphans.pm b/IkiWiki/Plugin/orphans.pm index 711226772..d981670e7 100644 --- a/IkiWiki/Plugin/orphans.pm +++ b/IkiWiki/Plugin/orphans.pm @@ -23,8 +23,8 @@ sub preprocess (@) { my %params=@_; $params{pages}="*" unless defined $params{pages}; - # Needs to update whenever a page is added or removed, so - # register a dependency. + # Needs to update whenever a page is changed, added, or removed, + # in order to see the link changes. add_depends($params{page}, $params{pages}); my @orphans; -- cgit v1.2.3 From 2fbfcd16e6d5717fea7b23d7fa82961222a6e32f Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 4 Oct 2009 15:46:23 -0400 Subject: map: Use a contentless dependency unless show= is specified. This makes simple maps efficient enough that they can be used on sidebars! --- IkiWiki/Plugin/map.pm | 8 ++++---- debian/changelog | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/map.pm b/IkiWiki/Plugin/map.pm index 54146dc46..682960777 100644 --- a/IkiWiki/Plugin/map.pm +++ b/IkiWiki/Plugin/map.pm @@ -68,13 +68,13 @@ sub preprocess (@) { } # 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}); + # cases, when its content changes, if show= is specified), so + # register a dependency. + add_depends($params{page}, $params{pages}, content => exists $params{show}); # Explicitly add all currently shown pages, to detect when pages # are removed. foreach my $item (keys %mapitems) { - add_depends($params{page}, $item); + add_depends($params{page}, $item, content => exists $params{show}); } # Create the map. diff --git a/debian/changelog b/debian/changelog index bec1a61d3..ae39d4847 100644 --- a/debian/changelog +++ b/debian/changelog @@ -16,6 +16,8 @@ ikiwiki (3.14159266) UNRELEASED; urgency=low * pagecount: Use a contentless dependency, which makes this directive much less expensive to use, since page edits will no longer trigger an unnecessary update of the page count. + * map: Use a contentless dependency unless show= is specified. + This makes simple maps efficient enough that they can be used on sidebars! -- Joey Hess Sun, 27 Sep 2009 17:40:03 -0400 -- cgit v1.2.3 From e529c561f548fa2d277b8cb7c123c3a46a0427a4 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 4 Oct 2009 16:03:01 -0400 Subject: inline: Use a contentless dependency in quick mode. --- IkiWiki/Plugin/inline.pm | 7 +++---- debian/changelog | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm index ccfadfd69..5133c4ba6 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm @@ -197,7 +197,7 @@ sub preprocess_inline (@) { split ' ', $params{pagenames}; } else { - add_depends($params{page}, $params{pages}); + add_depends($params{page}, $params{pages}, content => ! $quick); @list = pagespec_match_list( [ grep { $_ ne $params{page} } keys %pagesources ], @@ -248,10 +248,9 @@ sub preprocess_inline (@) { } # 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. + # that if they are removed, the inline will be sure to be updated. foreach my $p ($#list >= $#feedlist ? @list : @feedlist) { - add_depends($params{page}, $p); + add_depends($params{page}, $p, content => ! $quick); } if ($feeds && exists $params{feedpages}) { diff --git a/debian/changelog b/debian/changelog index ae39d4847..9d03ae990 100644 --- a/debian/changelog +++ b/debian/changelog @@ -18,6 +18,7 @@ ikiwiki (3.14159266) UNRELEASED; urgency=low no longer trigger an unnecessary update of the page count. * map: Use a contentless dependency unless show= is specified. This makes simple maps efficient enough that they can be used on sidebars! + * inline: Use a contentless dependency in quick mode. -- Joey Hess Sun, 27 Sep 2009 17:40:03 -0400 -- cgit v1.2.3 From a6689f9c7a1ecad02b51962c0858df47352c4648 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 4 Oct 2009 16:05:41 -0400 Subject: calendar: all dependencies are contentless --- IkiWiki/Plugin/calendar.pm | 21 ++++++++++++--------- debian/changelog | 6 +++--- 2 files changed, 15 insertions(+), 12 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index 5d16dff75..a5cc20882 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -104,19 +104,22 @@ sub format_month (@) { "$archivebase/$year/".sprintf("%02d", $month), linktext => " $monthname "); } - add_depends($params{page}, "$archivebase/$year/".sprintf("%02d", $month)); + add_depends($params{page}, "$archivebase/$year/".sprintf("%02d", $month), + content => 0); 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)); + add_depends($params{page}, "$archivebase/$pyear/".sprintf("%02d", $pmonth), + content => 0); 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)); + add_depends($params{page}, "$archivebase/$nyear/".sprintf("%02d", $nmonth), + content => 0); # Start producing the month calendar $calendar=< 0); # 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); + add_depends($params{page}, $p, content => 0); } return $calendar; @@ -246,19 +249,19 @@ sub format_year (@) { "$archivebase/$year", linktext => "$year"); } - add_depends($params{page}, "$archivebase/$year"); + add_depends($params{page}, "$archivebase/$year", content => 0); if (exists $cache{$pagespec}{"$pyear"}) { $purl = htmllink($params{page}, $params{destpage}, "$archivebase/$pyear", linktext => "\←"); } - add_depends($params{page}, "$archivebase/$pyear"); + add_depends($params{page}, "$archivebase/$pyear", content => 0); if (exists $cache{$pagespec}{"$nyear"}) { $nurl = htmllink($params{page}, $params{destpage}, "$archivebase/$nyear", linktext => "\→"); } - add_depends($params{page}, "$archivebase/$nyear"); + add_depends($params{page}, "$archivebase/$nyear", content => 0); # Start producing the year calendar $calendar=<$monthabbr\n}; } - add_depends($params{page}, "$archivebase/$year/$mtag"); + add_depends($params{page}, "$archivebase/$year/$mtag", content => 0); $calendar.=qq{\t\n} if ($month % $params{months_per_row} == 0); } diff --git a/debian/changelog b/debian/changelog index 9d03ae990..1a76303b1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -13,9 +13,9 @@ ikiwiki (3.14159266) UNRELEASED; urgency=low * Added support framework for multiple types of dependencies. * Allow declaring that a dependency does not encompass the content of a page. (By passing content => 0 to add_depends.) - * pagecount: Use a contentless dependency, which makes this - directive much less expensive to use, since page edits will - no longer trigger an unnecessary update of the page count. + * pagecount, calendar: Use a contentless dependency, which makes these + directives much less expensive to use, since page edits will + no longer trigger an unnecessary update. * map: Use a contentless dependency unless show= is specified. This makes simple maps efficient enough that they can be used on sidebars! * inline: Use a contentless dependency in quick mode. -- cgit v1.2.3 From ce78b699278be0797316518079474bc776d657ed Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 4 Oct 2009 16:07:02 -0400 Subject: edittemplate: contentless dependency This one is unlikely to matter much, but yeah, it's contentless. --- IkiWiki/Plugin/edittemplate.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/edittemplate.pm b/IkiWiki/Plugin/edittemplate.pm index 0bafc95d0..89d450725 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, content => 0); return sprintf(gettext("edittemplate %s registered for %s"), htmllink($params{page}, $params{destpage}, $link), $params{match}); -- cgit v1.2.3 From de6eba6ddde9f6d4577b49b204dcdd9f1a203ed4 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 4 Oct 2009 16:10:34 -0400 Subject: not a contentless dependency needs link info --- IkiWiki/Plugin/linkmap.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/linkmap.pm b/IkiWiki/Plugin/linkmap.pm index 941ed5f36..d0671ae0e 100644 --- a/IkiWiki/Plugin/linkmap.pm +++ b/IkiWiki/Plugin/linkmap.pm @@ -28,8 +28,8 @@ sub preprocess (@) { $params{pages}="*" unless defined $params{pages}; - # Needs to update whenever a page is added or removed, so - # register a dependency. + # Needs to update whenever a page is added, removed, or + # its links change, so register a dependency. add_depends($params{page}, $params{pages}); # Can't just return the linkmap here, since the htmlscrubber -- cgit v1.2.3 From 2af988b86fca6d2ca9476ae698cf1e840969af78 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 4 Oct 2009 16:11:10 -0400 Subject: listdirectives: contentless dependency Another one that probably doesn't matter, but for completness. --- IkiWiki/Plugin/listdirectives.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/listdirectives.pm b/IkiWiki/Plugin/listdirectives.pm index bd73f1a04..96150f986 100644 --- a/IkiWiki/Plugin/listdirectives.pm +++ b/IkiWiki/Plugin/listdirectives.pm @@ -84,7 +84,7 @@ sub preprocess (@) { foreach my $plugin (@pluginlist) { $result .= '
  • '; my $link=linkpage($config{directive_description_dir}."/".$plugin); - add_depends($params{page}, $link); + add_depends($params{page}, $link, content => 0); $result .= htmllink($params{page}, $params{destpage}, $link); $result .= '
  • '; } -- cgit v1.2.3 From 66852de77553a6131569436d4531c69a4515a4d3 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 4 Oct 2009 16:12:05 -0400 Subject: meta redir dependency is contentless --- IkiWiki/Plugin/meta.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm index 514b09369..eef3013a0 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, content => 0); $value=urlto($link, $page); $value.='#'.$redir_anchor if defined $redir_anchor; -- cgit v1.2.3 From 7982c3c1773feef0d7f248ff3efe09dd2cd94ad8 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 4 Oct 2009 16:16:50 -0400 Subject: postsparkline and progress: also contentless dependencies --- IkiWiki/Plugin/postsparkline.pm | 2 +- IkiWiki/Plugin/progress.pm | 4 ++-- debian/changelog | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/postsparkline.pm b/IkiWiki/Plugin/postsparkline.pm index d2e5c2378..694d39575 100644 --- a/IkiWiki/Plugin/postsparkline.pm +++ b/IkiWiki/Plugin/postsparkline.pm @@ -48,7 +48,7 @@ sub preprocess (@) { error gettext("unknown formula"); } - add_depends($params{page}, $params{pages}); + add_depends($params{page}, $params{pages}, content => 0); my @list=sort { $params{timehash}->{$b} <=> $params{timehash}->{$a} } pagespec_match_list( diff --git a/IkiWiki/Plugin/progress.pm b/IkiWiki/Plugin/progress.pm index 76d994acc..3b664f4cb 100644 --- a/IkiWiki/Plugin/progress.pm +++ b/IkiWiki/Plugin/progress.pm @@ -36,8 +36,8 @@ sub preprocess (@) { $fill.="%"; } elsif (defined $params{totalpages} and defined $params{donepages}) { - add_depends($params{page}, $params{totalpages}); - add_depends($params{page}, $params{donepages}); + add_depends($params{page}, $params{totalpages}, content => 0); + add_depends($params{page}, $params{donepages}, content => 0); my @pages=keys %pagesources; my $totalcount=0; diff --git a/debian/changelog b/debian/changelog index 1a76303b1..0e9bf512b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -13,9 +13,9 @@ ikiwiki (3.14159266) UNRELEASED; urgency=low * Added support framework for multiple types of dependencies. * Allow declaring that a dependency does not encompass the content of a page. (By passing content => 0 to add_depends.) - * pagecount, calendar: Use a contentless dependency, which makes these - directives much less expensive to use, since page edits will - no longer trigger an unnecessary update. + * pagecount, calendar, postsparkline, progress: Use a contentless dependency, + which makes these directives much less expensive to use, since page + edits will no longer trigger an unnecessary update. * map: Use a contentless dependency unless show= is specified. This makes simple maps efficient enough that they can be used on sidebars! * inline: Use a contentless dependency in quick mode. -- cgit v1.2.3 From be032a7b87d1080f1a54327346cb5b40432a056c Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 4 Oct 2009 20:30:21 -0400 Subject: rework dependency types code Simplify, change default content depends number to 1, change interface to make more sense. --- IkiWiki.pm | 35 +++++++++++++++-------------------- IkiWiki/Plugin/calendar.pm | 18 +++++++++--------- IkiWiki/Plugin/edittemplate.pm | 2 +- IkiWiki/Plugin/listdirectives.pm | 2 +- IkiWiki/Plugin/meta.pm | 2 +- IkiWiki/Plugin/pagecount.pm | 4 ++-- IkiWiki/Plugin/postsparkline.pm | 2 +- IkiWiki/Plugin/progress.pm | 4 ++-- IkiWiki/Render.pm | 28 +++++++++++++--------------- doc/plugins/write.mdwn | 15 +++++++++------ ikiwiki-transition | 2 +- 11 files changed, 55 insertions(+), 59 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki.pm b/IkiWiki.pm index 5e5dc739d..c1d07531e 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -29,8 +29,8 @@ our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE 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; @@ -1540,13 +1540,13 @@ sub loadindex () { 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}; @@ -1771,16 +1771,23 @@ sub add_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) { @@ -1976,18 +1983,6 @@ sub pagespec_valid ($) { 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; diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index a5cc20882..a1117992a 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -105,21 +105,21 @@ sub format_month (@) { 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=< 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; @@ -249,19 +249,19 @@ sub format_year (@) { "$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=<$monthabbr\n}; } - add_depends($params{page}, "$archivebase/$year/$mtag", content => 0); + add_depends($params{page}, "$archivebase/$year/$mtag", presence => 1); $calendar.=qq{\t\n} if ($month % $params{months_per_row} == 0); } diff --git a/IkiWiki/Plugin/edittemplate.pm b/IkiWiki/Plugin/edittemplate.pm index 89d450725..2dd1dbe68 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, 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}); diff --git a/IkiWiki/Plugin/listdirectives.pm b/IkiWiki/Plugin/listdirectives.pm index 96150f986..4023ed7d7 100644 --- a/IkiWiki/Plugin/listdirectives.pm +++ b/IkiWiki/Plugin/listdirectives.pm @@ -84,7 +84,7 @@ sub preprocess (@) { foreach my $plugin (@pluginlist) { $result .= '
  • '; 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 .= '
  • '; } diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm index eef3013a0..9b041a748 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, content => 0); + add_depends($page, $link, presence => 1); $value=urlto($link, $page); $value.='#'.$redir_anchor if defined $redir_anchor; diff --git a/IkiWiki/Plugin/pagecount.pm b/IkiWiki/Plugin/pagecount.pm index 17eda0618..80561350b 100644 --- a/IkiWiki/Plugin/pagecount.pm +++ b/IkiWiki/Plugin/pagecount.pm @@ -23,8 +23,8 @@ sub preprocess (@) { $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 "*") { diff --git a/IkiWiki/Plugin/postsparkline.pm b/IkiWiki/Plugin/postsparkline.pm index 694d39575..3205958d4 100644 --- a/IkiWiki/Plugin/postsparkline.pm +++ b/IkiWiki/Plugin/postsparkline.pm @@ -48,7 +48,7 @@ sub preprocess (@) { 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( diff --git a/IkiWiki/Plugin/progress.pm b/IkiWiki/Plugin/progress.pm index 3b664f4cb..26c537a84 100644 --- a/IkiWiki/Plugin/progress.pm +++ b/IkiWiki/Plugin/progress.pm @@ -36,8 +36,8 @@ sub preprocess (@) { $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; diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm index 3fc750925..cf0c3fe08 100644 --- a/IkiWiki/Render.pm +++ b/IkiWiki/Render.pm @@ -473,13 +473,11 @@ sub refresh () { 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; } @@ -492,22 +490,22 @@ sub refresh () { 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) { diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn index c244c1f2f..73db6f12a 100644 --- a/doc/plugins/write.mdwn +++ b/doc/plugins/write.mdwn @@ -613,12 +613,15 @@ generating a link to a page. 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($$;@)` diff --git a/ikiwiki-transition b/ikiwiki-transition index c50a748e8..1bebb1176 100755 --- a/ikiwiki-transition +++ b/ikiwiki-transition @@ -299,7 +299,7 @@ sub oldloadindex { $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; -- cgit v1.2.3 From e96992bbc8fc37040eda5119c475ff4174c43339 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 5 Oct 2009 14:33:42 -0400 Subject: fix add_depends to new api --- IkiWiki/Plugin/inline.pm | 4 ++-- IkiWiki/Plugin/map.pm | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm index 5133c4ba6..cebd9037c 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm @@ -197,7 +197,7 @@ sub preprocess_inline (@) { split ' ', $params{pagenames}; } else { - add_depends($params{page}, $params{pages}, content => ! $quick); + add_depends($params{page}, $params{pages}, presence => $quick); @list = pagespec_match_list( [ grep { $_ ne $params{page} } keys %pagesources ], @@ -250,7 +250,7 @@ sub preprocess_inline (@) { # Explicitly add all currently displayed pages as dependencies, so # that if they are removed, the inline will be sure to be updated. foreach my $p ($#list >= $#feedlist ? @list : @feedlist) { - add_depends($params{page}, $p, content => ! $quick); + add_depends($params{page}, $p, presence => $quick); } if ($feeds && exists $params{feedpages}) { diff --git a/IkiWiki/Plugin/map.pm b/IkiWiki/Plugin/map.pm index 682960777..625cfdfca 100644 --- a/IkiWiki/Plugin/map.pm +++ b/IkiWiki/Plugin/map.pm @@ -70,11 +70,11 @@ sub preprocess (@) { # Needs to update whenever a page is added or removed (or in some # cases, when its content changes, if show= is specified), so # register a dependency. - add_depends($params{page}, $params{pages}, content => exists $params{show}); + add_depends($params{page}, $params{pages}, presence => ! exists $params{show}); # Explicitly add all currently shown pages, to detect when pages # are removed. foreach my $item (keys %mapitems) { - add_depends($params{page}, $item, content => exists $params{show}); + add_depends($params{page}, $item, presence => ! exists $params{show}); } # Create the map. -- cgit v1.2.3 From f41caf57eabdaa2345eba1718450af686dca3971 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 5 Oct 2009 15:09:09 -0400 Subject: use links dependency --- IkiWiki/Plugin/brokenlinks.pm | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/brokenlinks.pm b/IkiWiki/Plugin/brokenlinks.pm index b8ed2b8de..9e65f52c6 100644 --- a/IkiWiki/Plugin/brokenlinks.pm +++ b/IkiWiki/Plugin/brokenlinks.pm @@ -23,9 +23,8 @@ sub preprocess (@) { my %params=@_; $params{pages}="*" unless defined $params{pages}; - # Needs to update whenever a page is changed, - # added or removed, in order to see the link changes. - add_depends($params{page}, $params{pages}); + # Needs to update whenever the links on a page change. + add_depends($params{page}, $params{pages}, links => 1); my @broken; foreach my $link (keys %IkiWiki::brokenlinks) { -- cgit v1.2.3 From 7123178732674268a1dce09277536dcdc68825f5 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 5 Oct 2009 15:14:18 -0400 Subject: oprhans: Use a combination of precense and link dependencies. This makes it more efficient. It also fixes a longstanding bug, where if only a small set of pages were considered by orphans, changes to links on other pages failed to cause an update. --- IkiWiki/Plugin/orphans.pm | 10 +++++++--- debian/changelog | 4 ++++ 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/orphans.pm b/IkiWiki/Plugin/orphans.pm index d981670e7..ae330b23b 100644 --- a/IkiWiki/Plugin/orphans.pm +++ b/IkiWiki/Plugin/orphans.pm @@ -23,9 +23,13 @@ sub preprocess (@) { my %params=@_; $params{pages}="*" unless defined $params{pages}; - # Needs to update whenever a page is changed, added, or removed, - # in order to see the link changes. - 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}, "*", links => 1); + # Also needs to update whenever potential orphans are added or + # removed. + add_depends($params{page}, $params{pages}, presence => 1); my @orphans; foreach my $page (pagespec_match_list( diff --git a/debian/changelog b/debian/changelog index 0255ac5d0..363bb9dbd 100644 --- a/debian/changelog +++ b/debian/changelog @@ -22,6 +22,10 @@ ikiwiki (3.14159266) UNRELEASED; urgency=low * inline: Use a presence dependency in quick mode. * brokenlinks: Use a link dependency. This makes it much more efficient, only updating when really necessary. + * oprhans: Use a combination of precense and link dependencies. + This makes it more efficient. It also fixes a longstanding bug, + where if only a small set of pages were considered by orphans, + changes to links on other pages failed to cause an update. * Transitive dependencies are now correctly supported. -- Joey Hess Sun, 27 Sep 2009 17:40:03 -0400 -- cgit v1.2.3 From c21f9e70936566daaf06fff21349f4584ee42906 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 5 Oct 2009 15:44:26 -0400 Subject: pagestats: Use a combination of precense and link dependencies. This makes it more efficient. It also fixes the same bug that I fixed in orphans recently, that only changes to the set of displayed pages were considered (or amoung), which missed changes to links on other pages to those. Probably this bug was never noticed because pagestats is most often put on a blog type page, which gets updated anyway when posts change, and thus the tag cloud was updated. --- IkiWiki/Plugin/pagestats.pm | 11 +++++++---- debian/changelog | 6 +++--- 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/pagestats.pm b/IkiWiki/Plugin/pagestats.pm index 874ead7e6..00b919325 100644 --- a/IkiWiki/Plugin/pagestats.pm +++ b/IkiWiki/Plugin/pagestats.pm @@ -35,10 +35,13 @@ 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}; + # Needs to update whenever a page is added or removed. + add_depends($params{page}, $params{pages}, exists => 1); + # Also needs to update when any page with links changes, + # in case the links point to our displayed pages. + # (Amoung limits this further.) + add_depends($params{page}, exists $params{among} ? $params{among} : "*", + links => 1); my %counts; my $max = 0; diff --git a/debian/changelog b/debian/changelog index abbd87abc..000203405 100644 --- a/debian/changelog +++ b/debian/changelog @@ -22,9 +22,9 @@ ikiwiki (3.14159266) UNRELEASED; urgency=low * inline: Use a presence dependency in quick mode. * brokenlinks: Use a link dependency. This makes it much more efficient, only updating when really necessary. - * orphans: Use a combination of precense and link dependencies. - This makes it more efficient. It also fixes a longstanding bug, - where if only a small set of pages were considered by orphans, + * orphans, pagestats: Use a combination of precense and link dependencies. + This makes them more efficient. It also fixes a longstanding bug, + where if only a small set of pages were considered by orphans/pagestats, changes to links on other pages failed to cause an update. * Transitive dependencies are now correctly supported. -- cgit v1.2.3 From 031d1bf5046ab77c796477a19967e7c0c512c417 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 5 Oct 2009 17:03:16 -0400 Subject: use among limit for correctness --- IkiWiki/Plugin/pagestats.pm | 2 +- doc/plugins.mdwn | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/pagestats.pm b/IkiWiki/Plugin/pagestats.pm index 00b919325..0765c1cfa 100644 --- a/IkiWiki/Plugin/pagestats.pm +++ b/IkiWiki/Plugin/pagestats.pm @@ -39,7 +39,7 @@ sub preprocess (@) { add_depends($params{page}, $params{pages}, exists => 1); # Also needs to update when any page with links changes, # in case the links point to our displayed pages. - # (Amoung limits this further.) + # (Among limits this further.) add_depends($params{page}, exists $params{among} ? $params{among} : "*", links => 1); diff --git a/doc/plugins.mdwn b/doc/plugins.mdwn index bd7ee538b..697b4a219 100644 --- a/doc/plugins.mdwn +++ b/doc/plugins.mdwn @@ -1,7 +1,7 @@ Most of ikiwiki's [[features]] are implemented as plugins. Many of these plugins are included with ikiwiki. -[[!pagestats pages="plugins/type/* and !plugins/type/slow"]] +[[!pagestats pages="plugins/type/* and !plugins/type/slow" among="plugins/*"]] There's documentation if you want to [[write]] your own plugins, or you can [[install]] plugins [[contributed|contrib]] by others. -- cgit v1.2.3 From af85f62d6fd7c3b437fa527bff3392616d3513dc Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 6 Oct 2009 17:47:10 -0400 Subject: linkmap: Use a combination of presence and link dependencies. This makes the map be regenerated much less frequently, so larger maps are more practical to use now. --- IkiWiki/Plugin/linkmap.pm | 6 +++--- debian/changelog | 3 +++ doc/ikiwiki/directive/linkmap.mdwn | 4 +--- 3 files changed, 7 insertions(+), 6 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/linkmap.pm b/IkiWiki/Plugin/linkmap.pm index d0671ae0e..d7ba68da9 100644 --- a/IkiWiki/Plugin/linkmap.pm +++ b/IkiWiki/Plugin/linkmap.pm @@ -28,9 +28,9 @@ sub preprocess (@) { $params{pages}="*" unless defined $params{pages}; - # Needs to update whenever a page is added, removed, or - # its links change, so register a dependency. - add_depends($params{page}, $params{pages}); + # Needs to update whenever a relevant page is added, or removed, or + # its links change. + add_depends($params{page}, $params{pages}, presence => 1, links => 1); # Can't just return the linkmap here, since the htmlscrubber # scrubs out all tags (with good reason!) diff --git a/debian/changelog b/debian/changelog index 89d377769..a006d3177 100644 --- a/debian/changelog +++ b/debian/changelog @@ -26,6 +26,9 @@ ikiwiki (3.14159266) UNRELEASED; urgency=low This makes them more efficient. It also fixes a longstanding bug, where if only a small set of pages were considered by orphans/pagestats, changes to links on other pages failed to cause an update. + * linkmap: Use a combination of presence and link dependencies. + This makes the map be regenerated much less frequently, so larger + maps are more practical to use now. * Transitive dependencies are now correctly supported. * Rebuild wikis on upgrade to this version to get improved dependency info. diff --git a/doc/ikiwiki/directive/linkmap.mdwn b/doc/ikiwiki/directive/linkmap.mdwn index db79a1491..38cf0fd11 100644 --- a/doc/ikiwiki/directive/linkmap.mdwn +++ b/doc/ikiwiki/directive/linkmap.mdwn @@ -9,9 +9,7 @@ Only links between mapped pages will be shown; links pointing to or from unmapped pages will be omitted. If the pages to include are not specified, the links between all pages (and other files) in the wiki are mapped. For best results, only a small set of pages should be mapped, since otherwise -the map can become very large, unwieldy, and complicated. Also, the map is -rebuilt whenever one of the mapped pages is changed, which can make the -wiki a bit slow. +the map can become very large, unwieldy, and complicated. Here are descriptions of all the supported parameters to the `linkmap` directive: -- cgit v1.2.3 From 15fd89d64deaeeee921a02b240d5036bbd896f89 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 6 Oct 2009 18:41:09 -0400 Subject: presence dependencies not needed Using just a link dependency is sufficient, since --- IkiWiki/Plugin/linkmap.pm | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/linkmap.pm b/IkiWiki/Plugin/linkmap.pm index d7ba68da9..b8b4cf40d 100644 --- a/IkiWiki/Plugin/linkmap.pm +++ b/IkiWiki/Plugin/linkmap.pm @@ -28,9 +28,8 @@ sub preprocess (@) { $params{pages}="*" unless defined $params{pages}; - # Needs to update whenever a relevant page is added, or removed, or - # its links change. - add_depends($params{page}, $params{pages}, presence => 1, links => 1); + # Needs to update whenever a relevant page's links change. + add_depends($params{page}, $params{pages}, links => 1); # Can't just return the linkmap here, since the htmlscrubber # scrubs out all tags (with good reason!) -- cgit v1.2.3 From a5d825f28632655b608564893428ef9142dddb04 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 6 Oct 2009 19:24:17 -0400 Subject: linkmap: does need presence deps Otherwise, removal of a page with no links will not be noticed, since no links will change. --- IkiWiki/Plugin/linkmap.pm | 5 +++-- debian/changelog | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/linkmap.pm b/IkiWiki/Plugin/linkmap.pm index b8b4cf40d..d7ba68da9 100644 --- a/IkiWiki/Plugin/linkmap.pm +++ b/IkiWiki/Plugin/linkmap.pm @@ -28,8 +28,9 @@ sub preprocess (@) { $params{pages}="*" unless defined $params{pages}; - # Needs to update whenever a relevant page's links change. - add_depends($params{page}, $params{pages}, links => 1); + # Needs to update whenever a relevant page is added, or removed, or + # its links change. + add_depends($params{page}, $params{pages}, presence => 1, links => 1); # Can't just return the linkmap here, since the htmlscrubber # scrubs out all tags (with good reason!) diff --git a/debian/changelog b/debian/changelog index a006d3177..dc6ee0a81 100644 --- a/debian/changelog +++ b/debian/changelog @@ -27,8 +27,8 @@ ikiwiki (3.14159266) UNRELEASED; urgency=low where if only a small set of pages were considered by orphans/pagestats, changes to links on other pages failed to cause an update. * linkmap: Use a combination of presence and link dependencies. - This makes the map be regenerated much less frequently, so larger - maps are more practical to use now. + This makes the map be regenerated much less frequently in many cases, + so larger maps are more practical to use now. * Transitive dependencies are now correctly supported. * Rebuild wikis on upgrade to this version to get improved dependency info. -- cgit v1.2.3 From 77598dfa9fccb668345198ea169cf7cf00b9845e Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 6 Oct 2009 19:29:28 -0400 Subject: linkmap, pagestats: avoid using %links to get a list of pages When a page is deleted, it is removed from %pagesources, but not from %links. So use the former. --- IkiWiki/Plugin/linkmap.pm | 2 +- IkiWiki/Plugin/pagestats.pm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/linkmap.pm b/IkiWiki/Plugin/linkmap.pm index d7ba68da9..3d20a6521 100644 --- a/IkiWiki/Plugin/linkmap.pm +++ b/IkiWiki/Plugin/linkmap.pm @@ -56,7 +56,7 @@ sub genmap ($) { # Get all the items to map. my %mapitems = (); - foreach my $item (keys %links) { + foreach my $item (keys %pagesources) { if (pagespec_match($item, $params{pages}, location => $params{page})) { $mapitems{$item}=urlto($item, $params{destpage}); } diff --git a/IkiWiki/Plugin/pagestats.pm b/IkiWiki/Plugin/pagestats.pm index 0765c1cfa..afe4eeaf2 100644 --- a/IkiWiki/Plugin/pagestats.pm +++ b/IkiWiki/Plugin/pagestats.pm @@ -45,7 +45,7 @@ sub preprocess (@) { my %counts; my $max = 0; - foreach my $page (pagespec_match_list([keys %links], + foreach my $page (pagespec_match_list([keys %pagesources], $params{pages}, location => $params{page})) { use IkiWiki::Render; -- cgit v1.2.3 From 4002d7c1a4657e769b036c6e76106991ec5c3897 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 7 Oct 2009 20:31:13 -0400 Subject: add influence info to match_* Also update docs, test suite. --- IkiWiki.pm | 24 ++++++++++++------------ IkiWiki/Plugin/meta.pm | 8 ++++---- debian/changelog | 2 ++ doc/plugins/write.mdwn | 7 +++++++ t/pagespec_match.t | 15 +++++++++++++-- 5 files changed, 38 insertions(+), 18 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki.pm b/IkiWiki.pm index 73d2a9763..9c386e154 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -2039,7 +2039,7 @@ use overload ( sub new { my $class = shift; my $value = shift; - return bless [$value, {@_}], $class; + return bless [$value, {map { $_ => 1 } @_}], $class; } sub influences { @@ -2099,23 +2099,23 @@ sub match_link ($$;@) { my $from=exists $params{location} ? $params{location} : ''; my $links = $IkiWiki::links{$page}; - return IkiWiki::FailReason->new("$page has no links") unless $links && @{$links}; + return IkiWiki::FailReason->new("$page has no links", $link) unless $links && @{$links}; my $bestlink = IkiWiki::bestlink($from, $link); foreach my $p (@{$links}) { if (length $bestlink) { - return IkiWiki::SuccessReason->new("$page links to $link") + return IkiWiki::SuccessReason->new("$page links to $link", $page) if $bestlink eq IkiWiki::bestlink($page, $p); } else { - return IkiWiki::SuccessReason->new("$page links to page $p matching $link") + return IkiWiki::SuccessReason->new("$page links to page $p matching $link", $page) if match_glob($p, $link, %params); my ($p_rel)=$p=~/^\/?(.*)/; $link=~s/^\///; - return IkiWiki::SuccessReason->new("$page links to page $p_rel matching $link") + return IkiWiki::SuccessReason->new("$page links to page $p_rel matching $link", $page) 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", $page); } sub match_backlink ($$;@) { @@ -2131,14 +2131,14 @@ sub match_created_before ($$;@) { if (exists $IkiWiki::pagectime{$testpage}) { if ($IkiWiki::pagectime{$page} < $IkiWiki::pagectime{$testpage}) { - return IkiWiki::SuccessReason->new("$page created before $testpage"); + return IkiWiki::SuccessReason->new("$page created before $testpage", $testpage); } else { - return IkiWiki::FailReason->new("$page not created before $testpage"); + return IkiWiki::FailReason->new("$page not created before $testpage", $testpage); } } else { - return IkiWiki::ErrorReason->new("$testpage does not exist"); + return IkiWiki::ErrorReason->new("$testpage does not exist", $testpage); } } @@ -2151,14 +2151,14 @@ sub match_created_after ($$;@) { if (exists $IkiWiki::pagectime{$testpage}) { if ($IkiWiki::pagectime{$page} > $IkiWiki::pagectime{$testpage}) { - return IkiWiki::SuccessReason->new("$page created after $testpage"); + return IkiWiki::SuccessReason->new("$page created after $testpage", $testpage); } else { - return IkiWiki::FailReason->new("$page not created after $testpage"); + return IkiWiki::FailReason->new("$page not created after $testpage", $testpage); } } else { - return IkiWiki::ErrorReason->new("$testpage does not exist"); + return IkiWiki::ErrorReason->new("$testpage does not exist", $testpage); } } diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm index 9b041a748..a8ee5bc85 100644 --- a/IkiWiki/Plugin/meta.pm +++ b/IkiWiki/Plugin/meta.pm @@ -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); } else { - return IkiWiki::FailReason->new("$re does not match $field of $page"); + return IkiWiki::FailReason->new("$re does not match $field of $page", $page); } } else { - return IkiWiki::FailReason->new("$page does not have a $field"); + return IkiWiki::FailReason->new("$page does not have a $field", $page); } } package IkiWiki::PageSpec; sub match_title ($$;@) { - IkiWiki::Plugin::meta::match("title", @_); + IkiWiki::Plugin::meta::match("title", @_); } sub match_author ($$;@) { diff --git a/debian/changelog b/debian/changelog index dc6ee0a81..565a0cffa 100644 --- a/debian/changelog +++ b/debian/changelog @@ -32,6 +32,8 @@ ikiwiki (3.14159266) UNRELEASED; urgency=low * Transitive dependencies are now correctly supported. * Rebuild wikis on upgrade to this version to get improved dependency info. + * Plugins providing PageSpec `match_*` functions should pass additional + influence information when creating result objects. -- Joey Hess Sun, 27 Sep 2009 17:40:03 -0400 diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn index 8e8c3311e..6b47033e5 100644 --- a/doc/plugins/write.mdwn +++ b/doc/plugins/write.mdwn @@ -982,6 +982,13 @@ an IkiWiki::FailReason object if the match fails. If the match cannot be attempted at all, for any page, it can instead return an IkiWiki::ErrorReason object explaining why. +When constructing these objects, you should also include a list of any +pages whose contents or other metadata influenced the result of the match. +For example, "backlink(foo)" is influenced by the contents of page foo; +"link(foo)" and "title(bar)" are influenced by the contents of any +page they match; "created_before(foo)" is influenced by the metadata of +foo; while "glob(*)" is not influenced by the contents of any page. + ### Setup plugins The ikiwiki setup file is loaded using a pluggable mechanism. If you look diff --git a/t/pagespec_match.t b/t/pagespec_match.t index a1fcba7c8..f73bfdfe1 100755 --- a/t/pagespec_match.t +++ b/t/pagespec_match.t @@ -1,7 +1,7 @@ #!/usr/bin/perl use warnings; use strict; -use Test::More tests => 56; +use Test::More tests => 61; BEGIN { use_ok("IkiWiki"); } @@ -89,6 +89,17 @@ my $ret=pagespec_match("foo", "(invalid"); ok(! $ret, "syntax error"); ok($ret =~ /syntax error/, "error message"); -my $ret=pagespec_match("foo", "bar or foo"); +$ret=pagespec_match("foo", "bar or foo"); ok($ret, "simple match"); is($ret, "foo matches foo", "stringified return"); + +$ret=pagespec_match("foo", "link(bar)"); +is(join(",", $ret->influences), 'foo', "link is influenced by the page with the link"); +$ret=pagespec_match("bar", "backlink(foo)"); +is(join(",", $ret->influences), 'foo', "backlink is influenced by the page with the link"); +$ret=pagespec_match("bar", "backlink(foo)"); +is(join(",", $ret->influences), 'foo', "backlink is influenced by the page with the link"); +$ret=pagespec_match("bar", "created_before(foo)"); +is(join(",", $ret->influences), 'foo', "created_before is influenced by the comparison page"); +$ret=pagespec_match("bar", "created_after(foo)"); +is(join(",", $ret->influences), 'foo', "created_after is influenced by the comparison page"); -- cgit v1.2.3 From 5f9860e65c65aa769f11e550e63cc164b1519710 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 7 Oct 2009 21:48:03 -0400 Subject: add type info to influence information --- IkiWiki.pm | 49 ++++++++++++++++++++++++++++++------------------- IkiWiki/Plugin/meta.pm | 6 +++--- doc/plugins/write.mdwn | 6 +++--- docwiki.setup | 2 +- t/add_depends.t | 14 +++++++------- t/pagespec_match.t | 32 ++++++++++++++++---------------- 6 files changed, 60 insertions(+), 49 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki.pm b/IkiWiki.pm index 7adc63139..39a43ddbe 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -1795,8 +1795,10 @@ sub add_depends ($$;@) { return if $@; foreach my $p (keys %pagesources) { my $r=$sub->($p, location => $page ); - map { $depends_simple{$page}{lc $_} |= $DEPEND_CONTENT } $r->influences - if $r; + my %i=$r->influences; + foreach my $i (keys %i) { + $depends_simple{$page}{lc $i} |= $i{$i}; + } } $depends{$page}{$pagespec} |= $deptype; @@ -1998,8 +2000,8 @@ use overload ( '""' => sub { $_[0][0] }, '0+' => sub { 0 }, '!' => sub { bless $_[0], 'IkiWiki::SuccessReason'}, - '&' => sub { $_[0][1]={%{$_[0][1]}, %{$_[1][1]}}; $_[0] }, - '|' => sub { $_[1][1]={%{$_[0][1]}, %{$_[1][1]}}; $_[1] }, + '&' => sub { $_[0]->merge_influences($_[1]); $_[0] }, + '|' => sub { $_[1]->merge_influences($_[0]); $_[1] }, fallback => 1, ); @@ -2011,19 +2013,27 @@ use overload ( '""' => sub { $_[0][0] }, '0+' => sub { 1 }, '!' => sub { bless $_[0], 'IkiWiki::FailReason'}, - '&' => sub { $_[1][1]={%{$_[0][1]}, %{$_[1][1]}}; $_[1] }, - '|' => sub { $_[0][1]={%{$_[0][1]}, %{$_[1][1]}}; $_[0] }, + '&' => sub { $_[1]->merge_influences($_[0]); $_[1] }, + '|' => sub { $_[0]->merge_influences($_[1]); $_[0] }, fallback => 1, ); sub new { my $class = shift; my $value = shift; - return bless [$value, {map { $_ => 1 } @_}], $class; + return bless [$value, {@_}], $class; } sub influences { - return keys %{$_[0][1]}; + return %{$_[0][1]}; +} + +sub merge_influences { + my $this=shift; + my $other=shift; + foreach my $influence (keys %{$other->[1]}) { + $this->[1]{$influence} |= $other->[1]{$influence}; + } } package IkiWiki::ErrorReason; @@ -2079,23 +2089,24 @@ sub match_link ($$;@) { my $from=exists $params{location} ? $params{location} : ''; my $links = $IkiWiki::links{$page}; - return IkiWiki::FailReason->new("$page has no links", $page) unless $links && @{$links}; + return IkiWiki::FailReason->new("$page has no links", $page => $IkiWiki::DEPEND_LINKS) + unless $links && @{$links}; my $bestlink = IkiWiki::bestlink($from, $link); foreach my $p (@{$links}) { if (length $bestlink) { - return IkiWiki::SuccessReason->new("$page links to $link", $page) + return IkiWiki::SuccessReason->new("$page links to $link", $page => $IkiWiki::DEPEND_LINKS) if $bestlink eq IkiWiki::bestlink($page, $p); } else { - return IkiWiki::SuccessReason->new("$page links to page $p matching $link", $page) + return IkiWiki::SuccessReason->new("$page links to page $p matching $link", $page => $IkiWiki::DEPEND_LINKS) if match_glob($p, $link, %params); my ($p_rel)=$p=~/^\/?(.*)/; $link=~s/^\///; - return IkiWiki::SuccessReason->new("$page links to page $p_rel matching $link", $page) + return IkiWiki::SuccessReason->new("$page links to page $p_rel matching $link", $page => $IkiWiki::DEPEND_LINKS) if match_glob($p_rel, $link, %params); } } - return IkiWiki::FailReason->new("$page does not link to $link", $page); + return IkiWiki::FailReason->new("$page does not link to $link", $page => $IkiWiki::DEPEND_LINKS); } sub match_backlink ($$;@) { @@ -2111,14 +2122,14 @@ sub match_created_before ($$;@) { if (exists $IkiWiki::pagectime{$testpage}) { if ($IkiWiki::pagectime{$page} < $IkiWiki::pagectime{$testpage}) { - return IkiWiki::SuccessReason->new("$page created before $testpage", $testpage); + return IkiWiki::SuccessReason->new("$page created before $testpage", $testpage => $IkiWiki::DEPEND_PRESENCE); } else { - return IkiWiki::FailReason->new("$page not created before $testpage", $testpage); + return IkiWiki::FailReason->new("$page not created before $testpage", $testpage => $IkiWiki::DEPEND_PRESENCE); } } else { - return IkiWiki::ErrorReason->new("$testpage does not exist", $testpage); + return IkiWiki::ErrorReason->new("$testpage does not exist", $testpage => $IkiWiki::DEPEND_PRESENCE); } } @@ -2131,14 +2142,14 @@ sub match_created_after ($$;@) { if (exists $IkiWiki::pagectime{$testpage}) { if ($IkiWiki::pagectime{$page} > $IkiWiki::pagectime{$testpage}) { - return IkiWiki::SuccessReason->new("$page created after $testpage", $testpage); + return IkiWiki::SuccessReason->new("$page created after $testpage", $testpage => $IkiWiki::DEPEND_PRESENCE); } else { - return IkiWiki::FailReason->new("$page not created after $testpage", $testpage); + return IkiWiki::FailReason->new("$page not created after $testpage", $testpage => $IkiWiki::DEPEND_PRESENCE); } } else { - return IkiWiki::ErrorReason->new("$testpage does not exist", $testpage); + return IkiWiki::ErrorReason->new("$testpage does not exist", $testpage => $IkiWiki::DEPEND_PRESENCE); } } diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm index a8ee5bc85..c160e7eba 100644 --- a/IkiWiki/Plugin/meta.pm +++ b/IkiWiki/Plugin/meta.pm @@ -291,14 +291,14 @@ sub match { if (defined $val) { if ($val=~/^$re$/i) { - return IkiWiki::SuccessReason->new("$re matches $field of $page", $page); + return IkiWiki::SuccessReason->new("$re matches $field of $page", $page => $IkiWiki::DEPEND_CONTENT); } else { - return IkiWiki::FailReason->new("$re does not match $field of $page", $page); + return IkiWiki::FailReason->new("$re does not match $field of $page", $page => $IkiWiki::DEPEND_CONTENT); } } else { - return IkiWiki::FailReason->new("$page does not have a $field", $page); + return IkiWiki::FailReason->new("$page does not have a $field", $page => $IkiWiki::DEPEND_CONTENT); } } diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn index 6b47033e5..232430079 100644 --- a/doc/plugins/write.mdwn +++ b/doc/plugins/write.mdwn @@ -982,9 +982,9 @@ an IkiWiki::FailReason object if the match fails. If the match cannot be attempted at all, for any page, it can instead return an IkiWiki::ErrorReason object explaining why. -When constructing these objects, you should also include a list of any -pages whose contents or other metadata influenced the result of the match. -For example, "backlink(foo)" is influenced by the contents of page foo; +When constructing these objects, you should also include information about +of any pages whose contents or other metadata influenced the result of the +match. For example, "backlink(foo)" is influenced by the contents of page foo; "link(foo)" and "title(bar)" are influenced by the contents of any page they match; "created_before(foo)" is influenced by the metadata of foo; while "glob(*)" is not influenced by the contents of any page. diff --git a/docwiki.setup b/docwiki.setup index 52421e501..41c07f024 100644 --- a/docwiki.setup +++ b/docwiki.setup @@ -16,5 +16,5 @@ use IkiWiki::Setup::Standard { userdir => "users", usedirs => 0, prefix_directives => 1, - add_plugins => [qw{goodstuff version haiku polygen fortune}], + add_plugins => [qw{linkmap goodstuff version haiku polygen fortune}], } diff --git a/t/add_depends.t b/t/add_depends.t index d49aa74ce..9f426187b 100755 --- a/t/add_depends.t +++ b/t/add_depends.t @@ -57,17 +57,17 @@ ok($IkiWiki::depends{foo0}{"*"} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_L ok(! ($IkiWiki::depends{foo0}{"*"} & $IkiWiki::DEPEND_PRESENCE)); # Adding a pagespec that requires page metadata should add the influence -# as an explicit content dependency. +# as an explicit dependency. In the case of a link, a links dependency. $links{foo0}=$links{foo9}=[qw{bar baz}]; foreach my $spec ("* and ! link(bar)", "* or link(bar)") { ok(add_depends("foo3", $spec, presence => 1)); ok($IkiWiki::depends{foo3}{$spec} & $IkiWiki::DEPEND_PRESENCE); ok(! ($IkiWiki::depends{foo3}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS))); - ok($IkiWiki::depends_simple{foo3}{foo3} == $IkiWiki::DEPEND_CONTENT); + ok($IkiWiki::depends_simple{foo3}{foo3} == $IkiWiki::DEPEND_LINKS); ok(add_depends("foo4", $spec, links => 1)); ok($IkiWiki::depends{foo4}{$spec} & $IkiWiki::DEPEND_LINKS); ok(! ($IkiWiki::depends{foo4}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_PRESENCE))); - ok($IkiWiki::depends_simple{foo4}{foo4} == $IkiWiki::DEPEND_CONTENT); + ok($IkiWiki::depends_simple{foo4}{foo4} == $IkiWiki::DEPEND_LINKS); } # a pagespec with backlinks() will add as an influence the page with the links @@ -76,20 +76,20 @@ foreach my $spec ("bugs or (backlink(foo0) and !*.png)", "backlink(foo)") { ok(add_depends("foo5", $spec, presence => 1)); ok($IkiWiki::depends{foo5}{$spec} & $IkiWiki::DEPEND_PRESENCE); ok(! ($IkiWiki::depends{foo5}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS))); - ok($IkiWiki::depends_simple{foo5}{foo0} == $IkiWiki::DEPEND_CONTENT); + ok($IkiWiki::depends_simple{foo5}{foo0} == $IkiWiki::DEPEND_LINKS); ok(add_depends("foo6", $spec, links => 1)); ok($IkiWiki::depends{foo6}{$spec} & $IkiWiki::DEPEND_LINKS); ok(! ($IkiWiki::depends{foo6}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_CONTENT))); - ok($IkiWiki::depends_simple{foo5}{foo0} == $IkiWiki::DEPEND_CONTENT); + ok($IkiWiki::depends_simple{foo5}{foo0} == $IkiWiki::DEPEND_LINKS); ok(add_depends("foo7", $spec, presence => 1, links => 1)); ok($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_PRESENCE); ok($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_LINKS); ok(! ($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_CONTENT)); - ok($IkiWiki::depends_simple{foo7}{foo0} == $IkiWiki::DEPEND_CONTENT); + ok($IkiWiki::depends_simple{foo7}{foo0} == $IkiWiki::DEPEND_LINKS); ok(add_depends("foo8", $spec)); ok($IkiWiki::depends{foo8}{$spec} & $IkiWiki::DEPEND_CONTENT); ok(! ($IkiWiki::depends{foo8}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS))); - ok($IkiWiki::depends_simple{foo8}{foo0} == $IkiWiki::DEPEND_CONTENT); + ok($IkiWiki::depends_simple{foo8}{foo0} == $IkiWiki::DEPEND_LINKS); } # content is the default if unknown types are entered diff --git a/t/pagespec_match.t b/t/pagespec_match.t index 1a0db1cef..36fa04370 100755 --- a/t/pagespec_match.t +++ b/t/pagespec_match.t @@ -93,19 +93,19 @@ $ret=pagespec_match("foo", "bar or foo"); ok($ret, "simple match"); is($ret, "foo matches foo", "stringified return"); -$ret=pagespec_match("foo", "link(bar)"); -is(join(",", $ret->influences), 'foo', "link is influenced by the page with the link"); -$ret=pagespec_match("bar", "backlink(foo)"); -is(join(",", $ret->influences), 'foo', "backlink is influenced by the page with the link"); -$ret=pagespec_match("bar", "backlink(foo)"); -is(join(",", $ret->influences), 'foo', "backlink is influenced by the page with the link"); -$ret=pagespec_match("bar", "created_before(foo)"); -is(join(",", $ret->influences), 'foo', "created_before is influenced by the comparison page"); -$ret=pagespec_match("bar", "created_after(foo)"); -is(join(",", $ret->influences), 'foo', "created_after is influenced by the comparison page"); -$ret=pagespec_match("bar", "link(quux) and created_after(foo)"); -is(join(",", sort $ret->influences), 'foo,quux', "influences add up over AND"); -$ret=pagespec_match("bar", "link(quux) and created_after(foo)"); -is(join(",", sort $ret->influences), 'foo,quux', "influences add up over OR"); -$ret=pagespec_match("bar", "!link(quux) and !created_after(foo)"); -is(join(",", sort $ret->influences), 'foo,quux', "influences unaffected by negation"); +my %i=pagespec_match("foo", "link(bar)")->influences; +is(join(",", keys %i), 'foo', "link is influenced by the page with the link"); +%i=pagespec_match("bar", "backlink(foo)")->influences; +is(join(",", keys %i), 'foo', "backlink is influenced by the page with the link"); +%i=pagespec_match("bar", "backlink(foo)")->influences; +is(join(",", keys %i), 'foo', "backlink is influenced by the page with the link"); +%i=pagespec_match("bar", "created_before(foo)")->influences; +is(join(",", keys %i), 'foo', "created_before is influenced by the comparison page"); +%i=pagespec_match("bar", "created_after(foo)")->influences; +is(join(",", keys %i), 'foo', "created_after is influenced by the comparison page"); +%i=pagespec_match("bar", "link(quux) and created_after(foo)")->influences; +is(join(",", sort keys %i), 'bar,foo', "influences add up over AND"); +%i=pagespec_match("bar", "link(quux) and created_after(foo)")->influences; +is(join(",", sort keys %i), 'bar,foo', "influences add up over OR"); +%i=pagespec_match("bar", "!link(quux) and !created_after(foo)")->influences; +is(join(",", sort keys %i), 'bar,foo', "influences unaffected by negation"); -- cgit v1.2.3 From 957ded9d64ca6abf0127c5c49e24177685bac5ae Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 7 Oct 2009 21:57:31 -0400 Subject: remove explicit addition of dependencies for displayed pages that hack is not needed, thanks to pagespec influences calculation --- IkiWiki/Plugin/calendar.pm | 5 ----- IkiWiki/Plugin/inline.pm | 6 ------ IkiWiki/Plugin/map.pm | 5 ----- 3 files changed, 16 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index a1117992a..ec8e232e1 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -213,11 +213,6 @@ EOF # Add dependencies to update the calendar whenever pages # matching the pagespec are added or removed. 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, presence => 1); - } return $calendar; } diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm index cebd9037c..fc4e00a83 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm @@ -247,12 +247,6 @@ sub preprocess_inline (@) { @list=@list[0..$params{show} - 1]; } - # Explicitly add all currently displayed pages as dependencies, so - # that if they are removed, the inline will be sure to be updated. - foreach my $p ($#list >= $#feedlist ? @list : @feedlist) { - add_depends($params{page}, $p, presence => $quick); - } - if ($feeds && exists $params{feedpages}) { @feedlist=pagespec_match_list(\@feedlist, $params{feedpages}, location => $params{page}); } diff --git a/IkiWiki/Plugin/map.pm b/IkiWiki/Plugin/map.pm index 625cfdfca..46f11dc89 100644 --- a/IkiWiki/Plugin/map.pm +++ b/IkiWiki/Plugin/map.pm @@ -71,11 +71,6 @@ sub preprocess (@) { # cases, when its content changes, if show= is specified), so # register a dependency. add_depends($params{page}, $params{pages}, presence => ! exists $params{show}); - # Explicitly add all currently shown pages, to detect when pages - # are removed. - foreach my $item (keys %mapitems) { - add_depends($params{page}, $item, presence => ! exists $params{show}); - } # Create the map. my $parent=""; -- cgit v1.2.3 From f2b3d1341447cbf29189ab490daae418fbe5d02d Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 8 Oct 2009 13:38:46 -0400 Subject: fix handling of influences of pagespecs that fail to match If a pagespec fails to match, I had been throwing the influences away, but that is not right. Consider `backlink(foo)`, where foo does not exist. It still needs to be added as an influence, because if it is created, it will influence the pagespec to match. But with that fix, `link(bar)` had as influences all pages, whether they link to bar or not. Which is not necessary, because modifiying a page to add a link to bar will directly cause the pagespec to match. So, in match_link (and all the match_* functions for page metadata), only return an influence if the match succeeds. match_backlink had been implemented as the inverse of match_link, but that is no longer completly true. While match_link does not return an influence on failure, match_backlink does. match_created_before/after also return the influence on failure, this way if created_after(foo) currently fails because foo does not exist, it will still update the page with the pagespec if foo is created. --- IkiWiki.pm | 21 ++++++++++++++------- IkiWiki/Plugin/meta.pm | 4 ++-- 2 files changed, 16 insertions(+), 9 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki.pm b/IkiWiki.pm index c250d50ad..2064c881a 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -1789,13 +1789,12 @@ sub add_depends ($$;@) { } # Analyse the pagespec, and match it against all pages - # to get a list of influences, and add explicit - # content dependencies for those. + # to get a list of influences, and add explicit dependencies + # for those. my $sub=pagespec_translate($pagespec); return if $@; foreach my $p (keys %pagesources) { my $r=$sub->($p, location => $page ); - next unless $r; my %i=$r->influences; foreach my $i (keys %i) { $depends_simple{$page}{lc $i} |= $i{$i}; @@ -2026,7 +2025,13 @@ sub new { } sub influences { - return %{$_[0][1]}; + my $this=shift; + if (! @_) { + return %{$this->[1]}; + } + else { + $this->[1]={@_}; + } } sub merge_influences { @@ -2090,7 +2095,7 @@ sub match_link ($$;@) { my $from=exists $params{location} ? $params{location} : ''; my $links = $IkiWiki::links{$page}; - return IkiWiki::FailReason->new("$page has no links", $page => $IkiWiki::DEPEND_LINKS) + return IkiWiki::FailReason->new("$page has no links") unless $links && @{$links}; my $bestlink = IkiWiki::bestlink($from, $link); foreach my $p (@{$links}) { @@ -2107,11 +2112,13 @@ sub match_link ($$;@) { if match_glob($p_rel, $link, %params); } } - return IkiWiki::FailReason->new("$page does not link to $link", $page => $IkiWiki::DEPEND_LINKS); + return IkiWiki::FailReason->new("$page does not link to $link"); } sub match_backlink ($$;@) { - return match_link($_[1], $_[0], @_); + my $ret=match_link($_[1], $_[0], @_); + $ret->influences($_[1] => $IkiWiki::DEPEND_LINKS); + return $ret; } sub match_created_before ($$;@) { diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm index c160e7eba..da3e62233 100644 --- a/IkiWiki/Plugin/meta.pm +++ b/IkiWiki/Plugin/meta.pm @@ -294,11 +294,11 @@ sub match { return IkiWiki::SuccessReason->new("$re matches $field of $page", $page => $IkiWiki::DEPEND_CONTENT); } else { - return IkiWiki::FailReason->new("$re does not match $field of $page", $page => $IkiWiki::DEPEND_CONTENT); + return IkiWiki::FailReason->new("$re does not match $field of $page"); } } else { - return IkiWiki::FailReason->new("$page does not have a $field", $page => $IkiWiki::DEPEND_CONTENT); + return IkiWiki::FailReason->new("$page does not have a $field"); } } -- cgit v1.2.3 From c57908b9d073500608d656adaf2bd3048c8cef67 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 8 Oct 2009 16:49:03 -0400 Subject: change how dependency types are specified to add_depends Also, this fixes 2 bugs in dependency info. --- IkiWiki/Plugin/brokenlinks.pm | 2 +- IkiWiki/Plugin/calendar.pm | 17 +++++++++-------- IkiWiki/Plugin/edittemplate.pm | 2 +- IkiWiki/Plugin/inline.pm | 7 ++++++- IkiWiki/Plugin/linkmap.pm | 2 +- IkiWiki/Plugin/listdirectives.pm | 2 +- IkiWiki/Plugin/map.pm | 3 ++- IkiWiki/Plugin/meta.pm | 2 +- IkiWiki/Plugin/orphans.pm | 4 ++-- IkiWiki/Plugin/pagecount.pm | 2 +- IkiWiki/Plugin/pagestats.pm | 4 ++-- IkiWiki/Plugin/postsparkline.pm | 2 +- IkiWiki/Plugin/progress.pm | 4 ++-- 13 files changed, 30 insertions(+), 23 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/brokenlinks.pm b/IkiWiki/Plugin/brokenlinks.pm index 9e65f52c6..62a0a42f4 100644 --- a/IkiWiki/Plugin/brokenlinks.pm +++ b/IkiWiki/Plugin/brokenlinks.pm @@ -24,7 +24,7 @@ sub preprocess (@) { $params{pages}="*" unless defined $params{pages}; # Needs to update whenever the links on a page change. - add_depends($params{page}, $params{pages}, links => 1); + add_depends($params{page}, $params{pages}, deptype("links")); my @broken; foreach my $link (keys %IkiWiki::brokenlinks) { diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index ec8e232e1..c99170f92 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -105,21 +105,21 @@ sub format_month (@) { linktext => " $monthname "); } add_depends($params{page}, "$archivebase/$year/".sprintf("%02d", $month), - presence => 1); + deptype("presence")); 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), - presence => 1); + deptype("presence")); 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), - presence => 1); + deptype("presence")); # Start producing the month calendar $calendar=< 1); + add_depends($params{page}, $params{pages}, deptype("presence")); return $calendar; } @@ -244,19 +244,19 @@ sub format_year (@) { "$archivebase/$year", linktext => "$year"); } - add_depends($params{page}, "$archivebase/$year", presence => 1); + add_depends($params{page}, "$archivebase/$year", deptype("presence"); if (exists $cache{$pagespec}{"$pyear"}) { $purl = htmllink($params{page}, $params{destpage}, "$archivebase/$pyear", linktext => "\←"); } - add_depends($params{page}, "$archivebase/$pyear", presence => 1); + add_depends($params{page}, "$archivebase/$pyear", deptype("presence")); if (exists $cache{$pagespec}{"$nyear"}) { $nurl = htmllink($params{page}, $params{destpage}, "$archivebase/$nyear", linktext => "\→"); } - add_depends($params{page}, "$archivebase/$nyear", presence => 1); + add_depends($params{page}, "$archivebase/$nyear", deptype("presence")); # Start producing the year calendar $calendar=<$monthabbr\n}; } - add_depends($params{page}, "$archivebase/$year/$mtag", presence => 1); + add_depends($params{page}, "$archivebase/$year/$mtag", + deptype("presence")); $calendar.=qq{\t\n} if ($month % $params{months_per_row} == 0); } diff --git a/IkiWiki/Plugin/edittemplate.pm b/IkiWiki/Plugin/edittemplate.pm index 2dd1dbe68..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, presence => 1); + 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/inline.pm b/IkiWiki/Plugin/inline.pm index fc4e00a83..be1781520 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm @@ -195,9 +195,14 @@ sub preprocess_inline (@) { @list = map { bestlink($params{page}, $_) } split ' ', $params{pagenames}; + + foreach my $p (@list) { + add_depends($params{page}, $p, deptype($quick ? "presence" : "content")); + } } else { - add_depends($params{page}, $params{pages}, presence => $quick); + add_depends($params{page}, $params{pages}, + deptype($quick ? "presence" : "content")); @list = pagespec_match_list( [ grep { $_ ne $params{page} } keys %pagesources ], diff --git a/IkiWiki/Plugin/linkmap.pm b/IkiWiki/Plugin/linkmap.pm index 3d20a6521..28e4cfa13 100644 --- a/IkiWiki/Plugin/linkmap.pm +++ b/IkiWiki/Plugin/linkmap.pm @@ -30,7 +30,7 @@ sub preprocess (@) { # Needs to update whenever a relevant page is added, or removed, or # its links change. - add_depends($params{page}, $params{pages}, presence => 1, links => 1); + add_depends($params{page}, $params{pages}, deptype("presence", "links")); # Can't just return the linkmap here, since the htmlscrubber # scrubs out all tags (with good reason!) diff --git a/IkiWiki/Plugin/listdirectives.pm b/IkiWiki/Plugin/listdirectives.pm index 4023ed7d7..09f08c567 100644 --- a/IkiWiki/Plugin/listdirectives.pm +++ b/IkiWiki/Plugin/listdirectives.pm @@ -84,7 +84,7 @@ sub preprocess (@) { foreach my $plugin (@pluginlist) { $result .= '
  • '; my $link=linkpage($config{directive_description_dir}."/".$plugin); - add_depends($params{page}, $link, presence => 1); + add_depends($params{page}, $link, deptype("presence")); $result .= htmllink($params{page}, $params{destpage}, $link); $result .= '
  • '; } diff --git a/IkiWiki/Plugin/map.pm b/IkiWiki/Plugin/map.pm index 46f11dc89..19872e51c 100644 --- a/IkiWiki/Plugin/map.pm +++ b/IkiWiki/Plugin/map.pm @@ -70,7 +70,8 @@ sub preprocess (@) { # Needs to update whenever a page is added or removed (or in some # cases, when its content changes, if show= is specified), so # register a dependency. - add_depends($params{page}, $params{pages}, presence => ! exists $params{show}); + add_depends($params{page}, $params{pages}, + deptype(exists $params{show} ? "content" : "presence"); # Create the map. my $parent=""; diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm index da3e62233..c675880b3 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, presence => 1); + add_depends($page, $link, deptype("presence")); $value=urlto($link, $page); $value.='#'.$redir_anchor if defined $redir_anchor; diff --git a/IkiWiki/Plugin/orphans.pm b/IkiWiki/Plugin/orphans.pm index ae330b23b..93b8ec440 100644 --- a/IkiWiki/Plugin/orphans.pm +++ b/IkiWiki/Plugin/orphans.pm @@ -26,10 +26,10 @@ sub preprocess (@) { # 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}, "*", links => 1); + add_depends($params{page}, "*", deptype("links")); # Also needs to update whenever potential orphans are added or # removed. - add_depends($params{page}, $params{pages}, presence => 1); + add_depends($params{page}, $params{pages}, deptype("presence")); my @orphans; foreach my $page (pagespec_match_list( diff --git a/IkiWiki/Plugin/pagecount.pm b/IkiWiki/Plugin/pagecount.pm index 80561350b..419f2d535 100644 --- a/IkiWiki/Plugin/pagecount.pm +++ b/IkiWiki/Plugin/pagecount.pm @@ -24,7 +24,7 @@ sub preprocess (@) { # Needs to update count whenever a page is added or removed, so # register a presence dependency. - add_depends($params{page}, $params{pages}, presence => 1); + add_depends($params{page}, $params{pages}, deptype("presence")); my @pages; if ($params{pages} eq "*") { diff --git a/IkiWiki/Plugin/pagestats.pm b/IkiWiki/Plugin/pagestats.pm index afe4eeaf2..cd0bdb085 100644 --- a/IkiWiki/Plugin/pagestats.pm +++ b/IkiWiki/Plugin/pagestats.pm @@ -36,12 +36,12 @@ sub preprocess (@) { my $style = ($params{style} or 'cloud'); # Needs to update whenever a page is added or removed. - add_depends($params{page}, $params{pages}, exists => 1); + add_depends($params{page}, $params{pages}, deptype("presence")); # Also needs to update when any page with links changes, # in case the links point to our displayed pages. # (Among limits this further.) add_depends($params{page}, exists $params{among} ? $params{among} : "*", - links => 1); + deptype("links")); my %counts; my $max = 0; diff --git a/IkiWiki/Plugin/postsparkline.pm b/IkiWiki/Plugin/postsparkline.pm index 3205958d4..ea73e9180 100644 --- a/IkiWiki/Plugin/postsparkline.pm +++ b/IkiWiki/Plugin/postsparkline.pm @@ -48,7 +48,7 @@ sub preprocess (@) { error gettext("unknown formula"); } - add_depends($params{page}, $params{pages}, presence => 1); + add_depends($params{page}, $params{pages}, deptype("presence")); my @list=sort { $params{timehash}->{$b} <=> $params{timehash}->{$a} } pagespec_match_list( diff --git a/IkiWiki/Plugin/progress.pm b/IkiWiki/Plugin/progress.pm index 26c537a84..6da3e4f71 100644 --- a/IkiWiki/Plugin/progress.pm +++ b/IkiWiki/Plugin/progress.pm @@ -36,8 +36,8 @@ sub preprocess (@) { $fill.="%"; } elsif (defined $params{totalpages} and defined $params{donepages}) { - add_depends($params{page}, $params{totalpages}, presence => 1); - add_depends($params{page}, $params{donepages}, presence => 1); + add_depends($params{page}, $params{totalpages}, deptype("presence")); + add_depends($params{page}, $params{donepages}, deptype("presence")); my @pages=keys %pagesources; my $totalcount=0; -- cgit v1.2.3 From de24c0df873a772a8b44098d1b4d2e1258640c9e Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 8 Oct 2009 17:52:20 -0400 Subject: map: switch to use_pagespec --- IkiWiki/Plugin/map.pm | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/map.pm b/IkiWiki/Plugin/map.pm index 19872e51c..634b0e4d6 100644 --- a/IkiWiki/Plugin/map.pm +++ b/IkiWiki/Plugin/map.pm @@ -28,12 +28,15 @@ 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 (use_pagespec($params{page}, $params{pages}, deptype => $deptype)) { if (exists $params{show} && exists $pagestate{$page} && exists $pagestate{$page}{meta}{$params{show}}) { @@ -67,12 +70,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= is specified), so - # register a dependency. - add_depends($params{page}, $params{pages}, - deptype(exists $params{show} ? "content" : "presence"); - # Create the map. my $parent=""; my $indent=0; @@ -80,12 +77,12 @@ sub preprocess (@) { my $addparent=""; my $map = "
    \n"; - # Return empty div if %mapitems is empty - if (!scalar(keys %mapitems)) { + if (! keys %mapitems) { + # return empty div for empty map $map .= "
    \n"; return $map; } - else { # continue populating $map + else { $map .= "
      \n"; } -- cgit v1.2.3 From 32cd5f0b798c41b2320a4165c5b6ecc18a4e6e3e Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 8 Oct 2009 18:26:36 -0400 Subject: inline: switch to use_pagespec Taking advantage of every single one of its features, of course. Even had to add one more.. --- IkiWiki/Plugin/inline.pm | 49 +++++++++++++++++++++--------------------------- doc/plugins/write.mdwn | 2 ++ 2 files changed, 23 insertions(+), 28 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm index be1781520..748e02df4 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm @@ -196,45 +196,37 @@ sub preprocess_inline (@) { @list = map { bestlink($params{page}, $_) } split ' ', $params{pagenames}; + if (yesno($params{reverse})) { + @list=reverse(@list); + } + foreach my $p (@list) { add_depends($params{page}, $p, deptype($quick ? "presence" : "content")); } } else { - add_depends($params{page}, $params{pages}, - deptype($quick ? "presence" : "content")); - - @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; + my $num=0; + if ($params{show}) { + $num=$params{show}; } - 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; + if ($params{feedshow} && $num < $params{feedshow}) { + $num=$params{feedshow}; } - elsif (exists $params{sort} && $params{sort} eq 'mtime') { - @list=sort { $pagemtime{$b} <=> $pagemtime{$a} } @list; + if ($params{skip}) { + $num+=$params{skip}; } - elsif (! exists $params{sort} || $params{sort} eq 'age') { - @list=sort { $pagectime{$b} <=> $pagectime{$a} } @list; - } - else { - error sprintf(gettext("unknown sort type %s"), $params{sort}); - } - } - if (yesno($params{reverse})) { - @list=reverse(@list); + @list = use_pagespec($params{page}, $params{pages}, + deptype => deptype($quick ? "presence" : "content"), + limit => sub { $_[0] ne $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; @@ -253,7 +245,8 @@ sub preprocess_inline (@) { } if ($feeds && exists $params{feedpages}) { - @feedlist=pagespec_match_list(\@feedlist, $params{feedpages}, location => $params{page}); + @feedlist = use_pagespec($params{page}, $params{feedpages}, + list => \@feedlist); } my ($feedbase, $feednum); diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn index 3d5650758..62bebbeed 100644 --- a/doc/plugins/write.mdwn +++ b/doc/plugins/write.mdwn @@ -647,6 +647,8 @@ Additional named parameters can be specified: * `reverse` if true, sorts in reverse. * `num` if nonzero, specifies the maximum number of matching pages that will be returned. +* `list` makes it only match amoung the specified list of pages. + Default is to match amoung all pages in the wiki. #### `add_depends($$;$)` -- cgit v1.2.3 From 1abbc6a4041e752fbec9b947a9d453b3b126c120 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 8 Oct 2009 18:41:08 -0400 Subject: pagecount: switched to use_pagespec --- IkiWiki/Plugin/pagecount.pm | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/pagecount.pm b/IkiWiki/Plugin/pagecount.pm index 419f2d535..40474b2a1 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 presence dependency. - add_depends($params{page}, $params{pages}, deptype("presence")); - - 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 use_pagespec($params{page}, $pages, + deptype => deptype("presence")); } 1 -- cgit v1.2.3 From bc4ef28f3ebc396096b7eccad04eea6febac8d38 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 8 Oct 2009 19:27:25 -0400 Subject: pagestate: switch to use_pagespec --- IkiWiki/Plugin/pagestats.pm | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/pagestats.pm b/IkiWiki/Plugin/pagestats.pm index cd0bdb085..e64f7d9c3 100644 --- a/IkiWiki/Plugin/pagestats.pm +++ b/IkiWiki/Plugin/pagestats.pm @@ -35,25 +35,27 @@ sub preprocess (@) { $params{pages}="*" unless defined $params{pages}; my $style = ($params{style} or 'cloud'); - # Needs to update whenever a page is added or removed. - add_depends($params{page}, $params{pages}, deptype("presence")); - # Also needs to update when any page with links changes, - # in case the links point to our displayed pages. - # (Among limits this further.) - add_depends($params{page}, exists $params{among} ? $params{among} : "*", - deptype("links")); - my %counts; my $max = 0; - foreach my $page (pagespec_match_list([keys %pagesources], - $params{pages}, location => $params{page})) { + foreach my $page (use_pagespec($params{page}, $params{pages}, + # update when a displayed page is added or 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 = use_pagespec($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); -- cgit v1.2.3 From 57d04ed892588cbb49bfa81e2453e88388e67441 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 8 Oct 2009 20:54:06 -0400 Subject: fix feedpages dependency This dependency was missing before switching to use_pagespec. It is correct to add it, but it needs to be combined with the regular "pages" dependency to ensure that it does not match extra pages. (Also fixed its dependency type.) --- IkiWiki/Plugin/inline.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm index 748e02df4..c02137aed 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm @@ -245,7 +245,8 @@ sub preprocess_inline (@) { } if ($feeds && exists $params{feedpages}) { - @feedlist = use_pagespec($params{page}, $params{feedpages}, + @feedlist = use_pagespec($params{page}, "($params{pages}) and ($params{feedpages})", + deptype => deptype($quick ? "presence" : "content"), list => \@feedlist); } -- cgit v1.2.3 From 3be7a02e7d0a4f19ffba3566d9aedee2885387d4 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 8 Oct 2009 22:56:12 -0400 Subject: orphans: switch to use_pagespec --- IkiWiki/Plugin/orphans.pm | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/orphans.pm b/IkiWiki/Plugin/orphans.pm index 93b8ec440..607239500 100644 --- a/IkiWiki/Plugin/orphans.pm +++ b/IkiWiki/Plugin/orphans.pm @@ -27,24 +27,30 @@ sub preprocess (@) { # since any page could link to one of the pages we're # considering as orphans. add_depends($params{page}, "*", deptype("links")); - # Also needs to update whenever potential orphans are added or - # removed. - add_depends($params{page}, $params{pages}, deptype("presence")); - 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=use_pagespec($params{page}, $params{pages}, + # update when orphans are added/removed + deptype => deptype("presence"), + limit => sub { + my $page=shift; + + # Filter out pages that other pages link to. + return 0 if IkiWiki::backlink_pages($page); + + # Toplevel index is assumed to never be orphaned. + return 0 if $page eq 'index'; + + # If the page has a link to some other page, it's + # indirectly linked via that page's backlinks. + return 0 if grep { + length $_ && + ($_ !~ /\/\Q$config{discussionpage}\E$/i || ! $config{discussion}) && + bestlink($page, $_) !~ /^(\Q$page\E|)$/ + } @{$links{$page}}; + + return 1; + }, + ); return gettext("All pages have other pages linking to them.") unless @orphans; return "
        \n". -- cgit v1.2.3 From 80ab1dbc121fa74fe2f021a5af2b941c743c332d Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 8 Oct 2009 22:56:36 -0400 Subject: postsparkline: switch to use_pagespec Also, fixed up the dependency type for time=mtime. That has to remain a content dependency, sadly. --- IkiWiki/Plugin/postsparkline.pm | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/postsparkline.pm b/IkiWiki/Plugin/postsparkline.pm index ea73e9180..f51e309c8 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}, deptype("presence")); - my @list=sort { $params{timehash}->{$b} <=> $params{timehash}->{$a} } - pagespec_match_list( - [ grep { $_ ne $params{page} } keys %pagesources], - $params{pages}, location => $params{page}); + use_pagespec($params{page}, $params{pages}, + deptype => $deptype, + limit => sub { $_[0] ne $params{page} }, + ); my @data=eval qq{IkiWiki::Plugin::postsparkline::formula::$formula(\\\%params, \@list)}; if ($@) { -- cgit v1.2.3 From 332821144b33f42b3674240d28159124ee1a5334 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 8 Oct 2009 23:24:03 -0400 Subject: calendar: rework so it can use use_pagespec This was tricky because of the caching, and because use_pagespec always adds a dependency. That would have made year calendars depend on the whole pagespec, which is overly broad. So I removed the caching, format_month, and in format_year just look at %pagesources to see if month pages are available. In format_month, I make it always call use_pagespec, so each month calendar gets the right dependency and any influcences added. This means a bit more work, but the added work is fairly minimal, and presence dependencies remove a *lot* of work it used to do. (100% untested!) --- IkiWiki/Plugin/calendar.pm | 65 ++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 37 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index c99170f92..a89175cfb 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 (use_pagespec($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,21 +114,21 @@ 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), deptype("presence")); - if (exists $cache{$pagespec}{"$pyear/$pmonth"}) { + 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), deptype("presence")); - if (exists $cache{$pagespec}{"$nyear/$nmonth"}) { + if (exists $pagesources{"$archivebase/$nyear/$nmonth"}) { $nurl = htmllink($params{page}, $params{destpage}, "$archivebase/$nyear/" . sprintf("%02d", $nmonth), linktext => " $nmonthname "); @@ -173,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'; } @@ -210,10 +225,6 @@ EOF EOF - # Add dependencies to update the calendar whenever pages - # matching the pagespec are added or removed. - add_depends($params{page}, $params{pages}, deptype("presence")); - return $calendar; } @@ -239,19 +250,19 @@ 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", deptype("presence"); - 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 => "\←"); } add_depends($params{page}, "$archivebase/$pyear", deptype("presence")); - if (exists $cache{$pagespec}{"$nyear"}) { + if (exists $pagesources{"$archivebase/$nyear"}) { $nurl = htmllink($params{page}, $params{destpage}, "$archivebase/$nyear", linktext => "\→"); @@ -280,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) { @@ -297,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"); @@ -366,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); -- cgit v1.2.3 From 5e7b2dea84a35163b599b88efc02cd7ef3e0ad46 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 8 Oct 2009 23:51:06 -0400 Subject: rename use_pagespec to pagespec_match_list To avoid breaking plugins, also support the old pagespec_match_list calling convention, with a deprecation warning. --- IkiWiki.pm | 183 ++++++++++++++++++---------------------- IkiWiki/Plugin/calendar.pm | 2 +- IkiWiki/Plugin/inline.pm | 8 +- IkiWiki/Plugin/map.pm | 3 +- IkiWiki/Plugin/orphans.pm | 2 +- IkiWiki/Plugin/pagecount.pm | 2 +- IkiWiki/Plugin/pagestats.pm | 9 +- IkiWiki/Plugin/postsparkline.pm | 2 +- debian/changelog | 6 +- doc/plugins/write.mdwn | 24 ++---- t/pagespec_match_list.t | 31 +++++++ t/use_pagespec.t | 31 ------- 12 files changed, 140 insertions(+), 163 deletions(-) create mode 100755 t/pagespec_match_list.t delete mode 100755 t/use_pagespec.t (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki.pm b/IkiWiki.pm index daa71059b..fd7e23524 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -17,7 +17,7 @@ use vars qw{%config %links %oldlinks %pagemtime %pagectime %pagecase %forcerebuild %loaded_plugins}; use Exporter q{import}; -our @EXPORT = qw(hook debug error template htmlpage deptype use_pagespec +our @EXPORT = qw(hook debug error template htmlpage deptype add_depends pagespec_match pagespec_match_list bestlink htmllink readfile writefile pagetype srcfile pagename displaytime will_render gettext urlto targetpage @@ -1798,91 +1798,6 @@ sub add_depends ($$;$) { return 1; } -sub use_pagespec ($$;@) { - my $page=shift; - my $pagespec=shift; - my %params=@_; - - my $sub=pagespec_translate($pagespec); - error "syntax error in pagespec \"$pagespec\"" - if $@ || ! defined $sub; - - my @candidates; - if (exists $params{limit}) { - @candidates=grep { $params{limit}->($_) } keys %pagesources; - } - else { - @candidates=keys %pagesources; - } - - if (defined $params{sort}) { - my $f; - if ($params{sort} eq 'title') { - $f=sub { pagetitle(basename($a)) cmp pagetitle(basename($b)) }; - } - elsif ($params{sort} eq 'title_natural') { - eval q{use Sort::Naturally}; - if ($@) { - error(gettext("Sort::Naturally needed for title_natural sort")); - } - $f=sub { Sort::Naturally::ncmp(pagetitle(basename($a)), pagetitle(basename($b))) }; - } - elsif ($params{sort} eq 'mtime') { - $f=sub { $pagemtime{$b} <=> $pagemtime{$a} }; - } - elsif ($params{sort} eq 'age') { - $f=sub { $pagectime{$b} <=> $pagectime{$a} }; - } - else { - error sprintf(gettext("unknown sort type %s"), $params{sort}); - } - @candidates = sort { &$f } @candidates; - } - - @candidates=reverse(@candidates) if $params{reverse}; - - my @matches; - my $firstfail; - my $count=0; - foreach my $p (@candidates) { - my $r=$sub->($p, location => $page); - if ($r) { - push @matches, [$p, $r]; - last if defined $params{num} && ++$count == $params{num}; - } - elsif (! defined $firstfail) { - $firstfail=$r; - } - } - - $depends{$page}{$pagespec} |= ($params{deptype} || $DEPEND_CONTENT); - - my @ret; - if (@matches) { - # Add all influences from successful matches. - foreach my $m (@matches) { - push @ret, $m->[0]; - my %i=$m->[1]->influences; - foreach my $i (keys %i) { - $depends_simple{$page}{lc $i} |= $i{$i}; - } - } - } - elsif (defined $firstfail) { - # Add influences from one failure. (Which one should not - # matter; all should have the same influences.) - my %i=$firstfail->influences; - foreach my $i (keys %i) { - $depends_simple{$page}{lc $i} |= $i{$i}; - } - - error(sprintf(gettext("cannot match pages: %s"), $firstfail)) - if $firstfail->isa("IkiWiki::ErrorReason"); - } - - return @ret; -} - sub deptype (@) { my $deptype=0; foreach my $type (@_) { @@ -2055,27 +1970,95 @@ sub pagespec_match ($$;@) { } sub pagespec_match_list ($$;@) { - my $pages=shift; - my $spec=shift; - my @params=@_; + my $page=shift; + my $pagespec=shift; + my %params=@_; - my $sub=pagespec_translate($spec); - error "syntax error in pagespec \"$spec\"" + # Backwards compatability with old calling convention. + if (ref $page) { + print STDERR "warning: a plugin (".caller().") is using pagespec_match_list in an obsolete way, and needs to be updated\n"; + $params{list}=$page; + $page=$params{location}; # ugh! + } + + my $sub=pagespec_translate($pagespec); + error "syntax error in pagespec \"$pagespec\"" if $@ || ! defined $sub; + + my @candidates; + if (exists $params{limit}) { + @candidates=grep { $params{limit}->($_) } keys %pagesources; + } + else { + @candidates=keys %pagesources; + } + + if (defined $params{sort}) { + my $f; + if ($params{sort} eq 'title') { + $f=sub { pagetitle(basename($a)) cmp pagetitle(basename($b)) }; + } + elsif ($params{sort} eq 'title_natural') { + eval q{use Sort::Naturally}; + if ($@) { + error(gettext("Sort::Naturally needed for title_natural sort")); + } + $f=sub { Sort::Naturally::ncmp(pagetitle(basename($a)), pagetitle(basename($b))) }; + } + elsif ($params{sort} eq 'mtime') { + $f=sub { $pagemtime{$b} <=> $pagemtime{$a} }; + } + elsif ($params{sort} eq 'age') { + $f=sub { $pagectime{$b} <=> $pagectime{$a} }; + } + else { + error sprintf(gettext("unknown sort type %s"), $params{sort}); + } + @candidates = sort { &$f } @candidates; + } + + @candidates=reverse(@candidates) if $params{reverse}; - my @ret; - my $r; - foreach my $page (@$pages) { - $r=$sub->($page, @params); - push @ret, $page if $r; + my @matches; + my $firstfail; + my $count=0; + foreach my $p (@candidates) { + my $r=$sub->($p, location => $page); + if ($r) { + push @matches, [$p, $r]; + last if defined $params{num} && ++$count == $params{num}; + } + elsif (! defined $firstfail) { + $firstfail=$r; + } } + + $depends{$page}{$pagespec} |= ($params{deptype} || $DEPEND_CONTENT); - if (! @ret && defined $r && $r->isa("IkiWiki::ErrorReason")) { - error(sprintf(gettext("cannot match pages: %s"), $r)); + my @ret; + if (@matches) { + # Add all influences from successful matches. + foreach my $m (@matches) { + push @ret, $m->[0]; + my %i=$m->[1]->influences; + foreach my $i (keys %i) { + $depends_simple{$page}{lc $i} |= $i{$i}; + } + } } - else { - return @ret; + elsif (defined $firstfail) { + # Add influences from one failure. (Which one should not + # matter; all should have the same influences.) + my %i=$firstfail->influences; + foreach my $i (keys %i) { + $depends_simple{$page}{lc $i} |= $i{$i}; + } + + error(sprintf(gettext("cannot match pages: %s"), $firstfail)) + if $firstfail->isa("IkiWiki::ErrorReason"); } + + return @ret; } sub pagespec_valid ($) { diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index a89175cfb..c50d038df 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -74,7 +74,7 @@ sub format_month (@) { my $nyear = $params{nyear}; my %linkcache; - foreach my $p (use_pagespec($params{page}, $params{pagespec}, + 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"))) { diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm index c02137aed..815a37838 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm @@ -216,7 +216,7 @@ sub preprocess_inline (@) { $num+=$params{skip}; } - @list = use_pagespec($params{page}, $params{pages}, + @list = pagespec_match_list($params{page}, $params{pages}, deptype => deptype($quick ? "presence" : "content"), limit => sub { $_[0] ne $params{page} }, sort => exists $params{sort} ? $params{sort} : "age", @@ -245,9 +245,11 @@ sub preprocess_inline (@) { } if ($feeds && exists $params{feedpages}) { - @feedlist = use_pagespec($params{page}, "($params{pages}) and ($params{feedpages})", + @feedlist = pagespec_match_list( + $params{page}, "($params{pages}) and ($params{feedpages})", deptype => deptype($quick ? "presence" : "content"), - list => \@feedlist); + list => \@feedlist, + ); } my ($feedbase, $feednum); diff --git a/IkiWiki/Plugin/map.pm b/IkiWiki/Plugin/map.pm index 634b0e4d6..788b96827 100644 --- a/IkiWiki/Plugin/map.pm +++ b/IkiWiki/Plugin/map.pm @@ -36,7 +36,8 @@ sub preprocess (@) { # Get all the items to map. my %mapitems; - foreach my $page (use_pagespec($params{page}, $params{pages}, deptype => $deptype)) { + 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}}) { diff --git a/IkiWiki/Plugin/orphans.pm b/IkiWiki/Plugin/orphans.pm index 607239500..b1ebd1b9d 100644 --- a/IkiWiki/Plugin/orphans.pm +++ b/IkiWiki/Plugin/orphans.pm @@ -28,7 +28,7 @@ sub preprocess (@) { # considering as orphans. add_depends($params{page}, "*", deptype("links")); - my @orphans=use_pagespec($params{page}, $params{pages}, + my @orphans=pagespec_match_list($params{page}, $params{pages}, # update when orphans are added/removed deptype => deptype("presence"), limit => sub { diff --git a/IkiWiki/Plugin/pagecount.pm b/IkiWiki/Plugin/pagecount.pm index 40474b2a1..8d36f057e 100644 --- a/IkiWiki/Plugin/pagecount.pm +++ b/IkiWiki/Plugin/pagecount.pm @@ -32,7 +32,7 @@ sub preprocess (@) { return scalar keys %pagesources; } - return scalar use_pagespec($params{page}, $pages, + return scalar pagespec_match_list($params{page}, $pages, deptype => deptype("presence")); } diff --git a/IkiWiki/Plugin/pagestats.pm b/IkiWiki/Plugin/pagestats.pm index e64f7d9c3..47638210a 100644 --- a/IkiWiki/Plugin/pagestats.pm +++ b/IkiWiki/Plugin/pagestats.pm @@ -37,16 +37,17 @@ sub preprocess (@) { my %counts; my $max = 0; - foreach my $page (use_pagespec($params{page}, $params{pages}, - # update when a displayed page is added or removed - deptype => deptype("presence"))) { + 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}) { # only consider backlinks from the amoung pages - @backlinks = use_pagespec($params{page}, $params{among}, + @backlinks = pagespec_match_list( + $params{page}, $params{among}, # update whenever links on those pages change deptype => deptype("links"), list => \@backlinks diff --git a/IkiWiki/Plugin/postsparkline.pm b/IkiWiki/Plugin/postsparkline.pm index f51e309c8..1d4532366 100644 --- a/IkiWiki/Plugin/postsparkline.pm +++ b/IkiWiki/Plugin/postsparkline.pm @@ -54,7 +54,7 @@ sub preprocess (@) { } my @list=sort { $params{timehash}->{$b} <=> $params{timehash}->{$a} } - use_pagespec($params{page}, $params{pages}, + pagespec_match_list($params{page}, $params{pages}, deptype => $deptype, limit => sub { $_[0] ne $params{page} }, ); diff --git a/debian/changelog b/debian/changelog index 3a6fdf77d..49809e6cf 100644 --- a/debian/changelog +++ b/debian/changelog @@ -33,9 +33,9 @@ ikiwiki (3.14159266) UNRELEASED; urgency=low info. * Plugins providing PageSpec `match_*` functions should pass additional influence information when creating result objects. - * Added `use_pagespec` function, that plugins can use to find a list - of matching pages and add dependencies and influences, all at once, - and efficiently. + * API change: `pagespec_match_list` has completly changed its interface. + The old interface will be removed soon, and a warning will be printed + if any plugins try to use it. * Optimize away most expensive file prune calls, when refreshing, by only checking new files. diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn index 62bebbeed..f6ea76c36 100644 --- a/doc/plugins/write.mdwn +++ b/doc/plugins/write.mdwn @@ -625,16 +625,16 @@ dependency type from one or more of these keywords: If multiple types are specified, they are combined. -#### `use_pagespec($$;@)` +#### `pagespec_match_list($$;@)` Passed a page name, and [[ikiwiki/PageSpec]], returns a list of pages in the wiki that match the [[ikiwiki/PageSpec]]. The page will automatically be made to depend on the specified [[ikiwiki/PageSpec]], so `add_depends` does not need to be called. This -is significantly more efficient than calling `add_depends` -followed by `pagespec_match_list`. You should use this anytime a plugin -needs to match a set of pages and generate something based on that list. +is significantly more efficient than calling `add_depends` and +`pagespec_match` in a loop. You should use this anytime a plugin +needs to match a set of pages and do something based on that list. Additional named parameters can be specified: @@ -650,6 +650,9 @@ Additional named parameters can be specified: * `list` makes it only match amoung the specified list of pages. Default is to match amoung all pages in the wiki. +Unlike pagespec_match, this may throw an error if there is an error in +the pagespec. + #### `add_depends($$;$)` Makes the specified page depend on the specified [[ikiwiki/PageSpec]]. @@ -672,19 +675,6 @@ The most often used is "location", which specifies the location the PageSpec should match against. If not passed, relative PageSpecs will match relative to the top of the wiki. -#### `pagespec_match_list($$;@)` - -Passed a reference to a list of page names, and [[ikiwiki/PageSpec]], -returns the set of pages that match the [[ikiwiki/PageSpec]]. - -Additional named parameters can be passed, to further limit the match. -The most often used is "location", which specifies the location the -PageSpec should match against. If not passed, relative PageSpecs will match -relative to the top of the wiki. - -Unlike pagespec_match, this may throw an error if there is an error in -the pagespec. - #### `bestlink($$)` Given a page and the text of a link on the page, determine which diff --git a/t/pagespec_match_list.t b/t/pagespec_match_list.t new file mode 100755 index 000000000..85a30b542 --- /dev/null +++ b/t/pagespec_match_list.t @@ -0,0 +1,31 @@ +#!/usr/bin/perl +use warnings; +use strict; +use Test::More tests => 10; + +BEGIN { use_ok("IkiWiki"); } + +%pagesources=( + foo => "foo.mdwn", + bar => "bar.mdwn", + "post/1" => "post/1.mdwn", + "post/2" => "post/2.mdwn", + "post/3" => "post/3.mdwn", +); + +is_deeply([pagespec_match_list("foo", "bar")], ["bar"]); +is_deeply([sort(pagespec_match_list("foo", "post/*"))], ["post/1", "post/2", "post/3"]); +is_deeply([pagespec_match_list("foo", "post/*", sort => "title", reverse => 1)], + ["post/3", "post/2", "post/1"]); +is_deeply([pagespec_match_list("foo", "post/*", sort => "title", num => 2)], + ["post/1", "post/2"]); +is_deeply([pagespec_match_list("foo", "post/*", sort => "title", num => 50)], + ["post/1", "post/2", "post/3"]); +is_deeply([pagespec_match_list("foo", "post/*", sort => "title", + limit => sub { $_[0] !~ /3/}) ], + ["post/1", "post/2"]); +my $r=eval { pagespec_match_list("foo", "beep") }; +ok(eval { pagespec_match_list("foo", "beep") } == 0); +ok(! $@, "does not fail with error when unable to match anything"); +eval { pagespec_match_list("foo", "this is not a legal pagespec!") }; +ok($@, "fails with error when pagespec bad"); diff --git a/t/use_pagespec.t b/t/use_pagespec.t deleted file mode 100755 index 92d7977cf..000000000 --- a/t/use_pagespec.t +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/perl -use warnings; -use strict; -use Test::More tests => 10; - -BEGIN { use_ok("IkiWiki"); } - -%pagesources=( - foo => "foo.mdwn", - bar => "bar.mdwn", - "post/1" => "post/1.mdwn", - "post/2" => "post/2.mdwn", - "post/3" => "post/3.mdwn", -); - -is_deeply([use_pagespec("foo", "bar")], ["bar"]); -is_deeply([sort(use_pagespec("foo", "post/*"))], ["post/1", "post/2", "post/3"]); -is_deeply([use_pagespec("foo", "post/*", sort => "title", reverse => 1)], - ["post/3", "post/2", "post/1"]); -is_deeply([use_pagespec("foo", "post/*", sort => "title", num => 2)], - ["post/1", "post/2"]); -is_deeply([use_pagespec("foo", "post/*", sort => "title", num => 50)], - ["post/1", "post/2", "post/3"]); -is_deeply([use_pagespec("foo", "post/*", sort => "title", - limit => sub { $_[0] !~ /3/}) ], - ["post/1", "post/2"]); -my $r=eval { use_pagespec("foo", "beep") }; -ok(eval { use_pagespec("foo", "beep") } == 0); -ok(! $@, "does not fail with error when unable to match anything"); -eval { use_pagespec("foo", "this is not a legal pagespec!") }; -ok($@, "fails with error when pagespec bad"); -- cgit v1.2.3 From c791f84fb54c723e3bb488a5099e435a64d1c8b0 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 9 Oct 2009 12:35:41 -0400 Subject: linkmap: Use new pagespec_match_list --- IkiWiki/Plugin/linkmap.pm | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/linkmap.pm b/IkiWiki/Plugin/linkmap.pm index 28e4cfa13..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 relevant page is added, or removed, or - # its links change. - add_depends($params{page}, $params{pages}, deptype("presence", "links")); - # Can't just return the linkmap here, since the htmlscrubber # scrubs out all 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 %pagesources) { - 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"; -- cgit v1.2.3 From 96682e3084993428f4de384f5087cffdc29f1710 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 9 Oct 2009 12:48:16 -0400 Subject: progress: switch to new pagespec_match_list --- IkiWiki/Plugin/progress.pm | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/progress.pm b/IkiWiki/Plugin/progress.pm index 6da3e4f71..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}, deptype("presence")); - add_depends($params{page}, $params{donepages}, deptype("presence")); - - 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%"; -- cgit v1.2.3 From b7351daacd0d4a041a51b43d99b7bf589de54f53 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 9 Oct 2009 12:54:13 -0400 Subject: conditional: use yesno --- IkiWiki.pm | 2 +- IkiWiki/Plugin/conditional.pm | 2 +- t/yesno.t | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki.pm b/IkiWiki.pm index fd7e23524..475e278c3 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -1792,7 +1792,7 @@ sub add_depends ($$;$) { # $depends_simple{$page}{lc $i} |= $i{$i}; # } #} - print STDERR "warning: use of add_depends; influences not tracked\n"; + print STDERR "warning: use of add_depends by ".caller()."; influences not tracked\n"; $depends{$page}{$pagespec} |= $deptype; return 1; diff --git a/IkiWiki/Plugin/conditional.pm b/IkiWiki/Plugin/conditional.pm index 7445dbdad..7ead701f2 100644 --- a/IkiWiki/Plugin/conditional.pm +++ b/IkiWiki/Plugin/conditional.pm @@ -29,7 +29,7 @@ sub preprocess_if (@) { } my $result=0; - if ((exists $params{all} && lc $params{all} eq "no") || + if (! IkiWiki::yesno($params{all}) || # An optimisation to avoid needless looping over every page # and adding of dependencies for simple uses of some of the # tests. diff --git a/t/yesno.t b/t/yesno.t index 60a8c071d..8770390a1 100755 --- a/t/yesno.t +++ b/t/yesno.t @@ -1,7 +1,7 @@ #!/usr/bin/perl use warnings; use strict; -use Test::More tests => 10; +use Test::More tests => 11; BEGIN { use_ok("IkiWiki"); } @@ -19,3 +19,5 @@ ok(IkiWiki::yesno("NO") == 0); ok(IkiWiki::yesno("1") == 1); ok(IkiWiki::yesno("0") == 0); ok(IkiWiki::yesno("mooooooooooo") == 0); + +ok(IkiWiki::yesno(undef) == 0); -- cgit v1.2.3 From c7da9911580e9311981758922d354aea03b8074c Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 9 Oct 2009 13:02:03 -0400 Subject: indentation --- IkiWiki/Plugin/conditional.pm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/conditional.pm b/IkiWiki/Plugin/conditional.pm index 7ead701f2..bc7b8974d 100644 --- a/IkiWiki/Plugin/conditional.pm +++ b/IkiWiki/Plugin/conditional.pm @@ -30,10 +30,10 @@ sub preprocess_if (@) { my $result=0; if (! IkiWiki::yesno($params{all}) || - # 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\!()]*)+$/) { + # 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\!()]*)+$/) { add_depends($params{page}, "($params{test}) and $params{page}"); $result=pagespec_match($params{page}, $params{test}, location => $params{page}, -- cgit v1.2.3 From f9f7a6e9f34b120504bb1dc238a3a627e9a8e3dc Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 9 Oct 2009 13:07:50 -0400 Subject: conditional: use pagespec_match_list --- IkiWiki/Plugin/conditional.pm | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/conditional.pm b/IkiWiki/Plugin/conditional.pm index bc7b8974d..aad617812 100644 --- a/IkiWiki/Plugin/conditional.pm +++ b/IkiWiki/Plugin/conditional.pm @@ -31,8 +31,7 @@ sub preprocess_if (@) { my $result=0; if (! IkiWiki::yesno($params{all}) || # An optimisation to avoid needless looping over every page - # and adding of dependencies for simple uses of some of the - # tests. + # 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}, @@ -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; -- cgit v1.2.3 From 6f2cc5ac8cc7e76b3faf20cd7516f82bcb3de7ed Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 9 Oct 2009 13:20:41 -0400 Subject: pagespec_match_list: change limit to filter --- IkiWiki.pm | 6 +++--- IkiWiki/Plugin/inline.pm | 2 +- IkiWiki/Plugin/orphans.pm | 10 +++++----- IkiWiki/Plugin/postsparkline.pm | 2 +- doc/plugins/write.mdwn | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki.pm b/IkiWiki.pm index f959d868b..49c76c4d4 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -1986,8 +1986,8 @@ sub pagespec_match_list ($$;@) { if $@ || ! defined $sub; my @candidates; - if (exists $params{limit}) { - @candidates=grep { $params{limit}->($_) } keys %pagesources; + if (exists $params{filter}) { + @candidates=grep { ! $params{filter}->($_) } keys %pagesources; } else { @candidates=keys %pagesources; @@ -2023,7 +2023,7 @@ sub pagespec_match_list ($$;@) { # clear params, remainder is passed to pagespec my $num=$params{num}; - delete @params{qw{num deptype reverse sort limit}}; + delete @params{qw{num deptype reverse sort filter}}; my @matches; my $firstfail; diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm index 815a37838..0fe0bd2e1 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm @@ -218,7 +218,7 @@ sub preprocess_inline (@) { @list = pagespec_match_list($params{page}, $params{pages}, deptype => deptype($quick ? "presence" : "content"), - limit => sub { $_[0] ne $params{page} }, + filter => sub { $_[0] eq $params{page} }, sort => exists $params{sort} ? $params{sort} : "age", reverse => yesno($params{reverse}), num => $num, diff --git a/IkiWiki/Plugin/orphans.pm b/IkiWiki/Plugin/orphans.pm index b1ebd1b9d..702943f87 100644 --- a/IkiWiki/Plugin/orphans.pm +++ b/IkiWiki/Plugin/orphans.pm @@ -31,24 +31,24 @@ sub preprocess (@) { my @orphans=pagespec_match_list($params{page}, $params{pages}, # update when orphans are added/removed deptype => deptype("presence"), - limit => sub { + filter => sub { my $page=shift; # Filter out pages that other pages link to. - return 0 if IkiWiki::backlink_pages($page); + return 1 if IkiWiki::backlink_pages($page); # Toplevel index is assumed to never be orphaned. - return 0 if $page eq 'index'; + 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 0 if grep { + return 1 if grep { length $_ && ($_ !~ /\/\Q$config{discussionpage}\E$/i || ! $config{discussion}) && bestlink($page, $_) !~ /^(\Q$page\E|)$/ } @{$links{$page}}; - return 1; + return 0; }, ); diff --git a/IkiWiki/Plugin/postsparkline.pm b/IkiWiki/Plugin/postsparkline.pm index 1d4532366..0d5a12e33 100644 --- a/IkiWiki/Plugin/postsparkline.pm +++ b/IkiWiki/Plugin/postsparkline.pm @@ -56,7 +56,7 @@ sub preprocess (@) { my @list=sort { $params{timehash}->{$b} <=> $params{timehash}->{$a} } pagespec_match_list($params{page}, $params{pages}, deptype => $deptype, - limit => sub { $_[0] ne $params{page} }, + filter => sub { $_[0] eq $params{page} }, ); my @data=eval qq{IkiWiki::Plugin::postsparkline::formula::$formula(\\\%params, \@list)}; diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn index 9661bf4de..2254d7025 100644 --- a/doc/plugins/write.mdwn +++ b/doc/plugins/write.mdwn @@ -643,8 +643,8 @@ Additional named parameters can be specified: * `deptype` optionally specifies the type of dependency to add. Use the `deptype` function to generate a dependency type. -* `limit` is a reference to a function, that is called and passed a page, - and must return true for the page to be included. +* `filter` is a reference to a function, that is called and passed a page, + and returns true if the page should be filtered out of the list. * `sort` specifies a sort order for the list. See [[ikiwiki/PageSpec/sorting]] for the avilable sort methods. * `reverse` if true, sorts in reverse. -- cgit v1.2.3 From 1b6b1ee2d8f2e148bca301b177713ca35d2b8691 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 9 Oct 2009 13:35:11 -0400 Subject: brokenlinks: use pagespec_match_list --- IkiWiki/Plugin/brokenlinks.pm | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/brokenlinks.pm b/IkiWiki/Plugin/brokenlinks.pm index 62a0a42f4..8ee734bf9 100644 --- a/IkiWiki/Plugin/brokenlinks.pm +++ b/IkiWiki/Plugin/brokenlinks.pm @@ -23,18 +23,15 @@ sub preprocess (@) { my %params=@_; $params{pages}="*" unless defined $params{pages}; - # Needs to update whenever the links on a page change. - add_depends($params{page}, $params{pages}, deptype("links")); - 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]; -- cgit v1.2.3 From c5e237c0135e28f3399830abcbdae844d3006a84 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 9 Oct 2009 13:37:06 -0400 Subject: img: use presence dependency when linking to a page --- IkiWiki/Plugin/img.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'IkiWiki/Plugin') 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); -- cgit v1.2.3 From 74409f940d24f51a08becb626e266c91d40d69bd Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 9 Oct 2009 17:15:40 -0400 Subject: add_depends: optimise influence calculation I made match_* functions whose influences can vary depending on the page matched set a special "" influence to indicate this. Then add_depends can try just one page, and if static influences are found, stop there. --- IkiWiki.pm | 52 +++++++++++++++++++++++++------------------------- IkiWiki/Plugin/meta.pm | 6 +++--- doc/plugins/write.mdwn | 2 +- 3 files changed, 30 insertions(+), 30 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki.pm b/IkiWiki.pm index c67a1e138..cd93fe969 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -1780,19 +1780,17 @@ sub add_depends ($$;$) { return 1; } - # Analyse the pagespec, and match it against all pages - # to get a list of influences, and add explicit dependencies - # for those. - #my $sub=pagespec_translate($pagespec); - #return if $@; - #foreach my $p (keys %pagesources) { - # my $r=$sub->($p, location => $page ); - # my %i=$r->influences; - # foreach my $i (keys %i) { - # $depends_simple{$page}{lc $i} |= $i{$i}; - # } - #} - print STDERR "warning: use of add_depends by ".caller()."; influences not tracked\n"; + # Add explicit dependencies for influences. + my $sub=pagespec_translate($pagespec); + return if $@; + foreach my $p (keys %pagesources) { + my $r=$sub->($p, location => $page); + my $i=$r->influences; + foreach my $k (keys %$i) { + $depends_simple{$page}{lc $k} |= $i->{$k}; + } + last if $r->influences_static; + } $depends{$page}{$pagespec} |= $deptype; return 1; @@ -2045,9 +2043,9 @@ sub pagespec_match_list ($$;@) { } # Add simple dependencies for accumulated influences. - my %i=$accum->influences; - foreach my $i (keys %i) { - $depends_simple{$page}{lc $i} |= $i{$i}; + my $i=$accum->influences; + foreach my $k (keys %$i) { + $depends_simple{$page}{lc $k} |= $i->{$k}; } return @matches; @@ -2099,12 +2097,14 @@ sub new { sub influences { my $this=shift; - if (! @_) { - return %{$this->[1]}; - } - else { - $this->[1]={@_}; - } + $this->[1]={@_} if @_; + my %i=%{$this->[1]}; + delete $i{""}; + return \%i; +} + +sub influences_static { + return ! $_[0][1]->{""}; } sub merge_influences { @@ -2173,19 +2173,19 @@ sub match_link ($$;@) { my $bestlink = IkiWiki::bestlink($from, $link); foreach my $p (@{$links}) { if (length $bestlink) { - return IkiWiki::SuccessReason->new("$page links to $link", $page => $IkiWiki::DEPEND_LINKS) + return IkiWiki::SuccessReason->new("$page links to $link", $page => $IkiWiki::DEPEND_LINKS, "" => 1) if $bestlink eq IkiWiki::bestlink($page, $p); } else { - return IkiWiki::SuccessReason->new("$page links to page $p matching $link", $page => $IkiWiki::DEPEND_LINKS) + return IkiWiki::SuccessReason->new("$page links to page $p matching $link", $page => $IkiWiki::DEPEND_LINKS, "" => 1) if match_glob($p, $link, %params); my ($p_rel)=$p=~/^\/?(.*)/; $link=~s/^\///; - return IkiWiki::SuccessReason->new("$page links to page $p_rel matching $link", $page => $IkiWiki::DEPEND_LINKS) + return IkiWiki::SuccessReason->new("$page links to page $p_rel matching $link", $page => $IkiWiki::DEPEND_LINKS, "" => 1) 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", "" => 1); } sub match_backlink ($$;@) { diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm index c675880b3..8dcd73a1a 100644 --- a/IkiWiki/Plugin/meta.pm +++ b/IkiWiki/Plugin/meta.pm @@ -291,14 +291,14 @@ sub match { if (defined $val) { if ($val=~/^$re$/i) { - return IkiWiki::SuccessReason->new("$re matches $field of $page", $page => $IkiWiki::DEPEND_CONTENT); + 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); } } diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn index 2254d7025..c72418c3c 100644 --- a/doc/plugins/write.mdwn +++ b/doc/plugins/write.mdwn @@ -632,7 +632,7 @@ in the wiki that match the [[ikiwiki/PageSpec]]. The page will automatically be made to depend on the specified [[ikiwiki/PageSpec]], so `add_depends` does not need to be called. This -is significantly more efficient than calling `add_depends` and +is often significantly more efficient than calling `add_depends` and `pagespec_match` in a loop. You should use this anytime a plugin needs to match a set of pages and do something based on that list. -- cgit v1.2.3 From 71e266b939d72871f7efbc9c498dc9b472bdf9eb Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 11 Oct 2009 20:15:54 -0400 Subject: avoid temporary variables and fix a bug in pagespec variable name --- IkiWiki/Plugin/calendar.pm | 118 ++++++++++++++++++--------------------------- 1 file changed, 48 insertions(+), 70 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index c50d038df..fe7ee0361 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -65,16 +65,8 @@ sub month_days { sub format_month (@) { my %params=@_; - my $pagespec = $params{pages}; - my $year = $params{year}; - my $month = $params{month}; - my $pmonth = $params{pmonth}; - my $nmonth = $params{nmonth}; - my $pyear = $params{pyear}; - my $nyear = $params{nyear}; - my %linkcache; - foreach my $p (pagespec_match_list($params{page}, $params{pagespec}, + foreach my $p (pagespec_match_list($params{page}, $params{pages}, # add presence dependencies to update # month calendar when pages are added/removed deptype => deptype("presence"))) { @@ -94,19 +86,19 @@ sub format_month (@) { my $calendar="\n"; # When did this month start? - my @monthstart = localtime(timelocal(0,0,0,1,$month-1,$year-1900)); + my @monthstart = localtime(timelocal(0,0,0,1,$params{month}-1,$params{year}-1900)); my $future_dom = 0; my $today = 0; - if ($year == $now[5]+1900 && $month == $now[4]+1) { + if ($params{year} == $now[5]+1900 && $params{month} == $now[4]+1) { $future_dom = $now[3]+1; $today = $now[3]; } # Find out month names for this, next, and previous months my $monthname=POSIX::strftime("%B", @monthstart); - my $pmonthname=POSIX::strftime("%B", localtime(timelocal(0,0,0,1,$pmonth-1,$pyear-1900))); - my $nmonthname=POSIX::strftime("%B", localtime(timelocal(0,0,0,1,$nmonth-1,$nyear-1900))); + my $pmonthname=POSIX::strftime("%B", localtime(timelocal(0,0,0,1,$params{pmonth}-1,$params{pyear}-1900))); + my $nmonthname=POSIX::strftime("%B", localtime(timelocal(0,0,0,1,$params{nmonth}-1,$params{nyear}-1900))); my $archivebase = 'archives'; $archivebase = $config{archivebase} if defined $config{archivebase}; @@ -114,26 +106,26 @@ sub format_month (@) { # Calculate URL's for monthly archives. my ($url, $purl, $nurl)=("$monthname",'',''); - if (exists $pagesources{"$archivebase/$year/$month"}) { + if (exists $pagesources{"$archivebase/$params{year}/$params{month}"}) { $url = htmllink($params{page}, $params{destpage}, - "$archivebase/$year/".sprintf("%02d", $month), + "$archivebase/$params{year}/".sprintf("%02d", $params{month}), linktext => " $monthname "); } - add_depends($params{page}, "$archivebase/$year/".sprintf("%02d", $month), + add_depends($params{page}, "$archivebase/$params{year}/".sprintf("%02d", $params{month}), deptype("presence")); - if (exists $pagesources{"$archivebase/$pyear/$pmonth"}) { + if (exists $pagesources{"$archivebase/$params{pyear}/$params{pmonth}"}) { $purl = htmllink($params{page}, $params{destpage}, - "$archivebase/$pyear/" . sprintf("%02d", $pmonth), + "$archivebase/$params{pyear}/" . sprintf("%02d", $params{pmonth}), linktext => " $pmonthname "); } - add_depends($params{page}, "$archivebase/$pyear/".sprintf("%02d", $pmonth), + add_depends($params{page}, "$archivebase/$params{pyear}/".sprintf("%02d", $params{pmonth}), deptype("presence")); - if (exists $pagesources{"$archivebase/$nyear/$nmonth"}) { + if (exists $pagesources{"$archivebase/$params{nyear}/$params{nmonth}"}) { $nurl = htmllink($params{page}, $params{destpage}, - "$archivebase/$nyear/" . sprintf("%02d", $nmonth), + "$archivebase/$params{nyear}/" . sprintf("%02d", $params{nmonth}), linktext => " $nmonthname "); } - add_depends($params{page}, "$archivebase/$nyear/".sprintf("%02d", $nmonth), + add_depends($params{page}, "$archivebase/$params{nyear}/".sprintf("%02d", $params{nmonth}), deptype("presence")); # Start producing the month calendar @@ -155,7 +147,7 @@ EOF my %downame; my %dowabbr; for my $dow ($week_start_day..$week_start_day+6) { - my @day=localtime(timelocal(0,0,0,$start_day++,$month-1,$year-1900)); + my @day=localtime(timelocal(0,0,0,$start_day++,$params{month}-1,$params{year}-1900)); my $downame = POSIX::strftime("%A", @day); my $dowabbr = POSIX::strftime("%a", @day); $downame{$dow % 7}=$downame; @@ -176,7 +168,7 @@ EOF # At this point, either the first is a week_start_day, in which case # nothing has been printed, or else we are in the middle of a row. - for (my $day = 1; $day <= month_days(year => $year, month => $month); + for (my $day = 1; $day <= month_days(year => $params{year}, month => $params{month}); $day++, $wday++, $wday %= 7) { # At tihs point, on a week_start_day, we close out a row, # and start a new one -- unless it is week_start_day on the @@ -187,8 +179,8 @@ EOF } my $tag; - my $mtag = sprintf("%02d", $month); - if (defined $pagesources{"$archivebase/$year/$mtag/$day"}) { + my $mtag = sprintf("%02d", $params{month}); + if (defined $pagesources{"$archivebase/$params{year}/$mtag/$day"}) { if ($day == $today) { $tag='month-calendar-day-this-day'; } @@ -197,9 +189,9 @@ EOF } $calendar.=qq{\t\t}; $calendar.=htmllink($params{page}, $params{destpage}, - pagename($linkcache{"$year/$mtag/$day"}), + pagename($linkcache{"$params{year}/$mtag/$day"}), "linktext" => "$day"); - push @list, pagename($linkcache{"$year/$mtag/$day"}); + push @list, pagename($linkcache{"$params{year}/$mtag/$day"}); $calendar.=qq{\n}; } else { @@ -231,43 +223,35 @@ EOF sub format_year (@) { my %params=@_; - my $pagespec = $params{pages}; - my $year = $params{year}; - my $month = $params{month}; - my $pmonth = $params{pmonth}; - my $nmonth = $params{nmonth}; - my $pyear = $params{pyear}; - my $nyear = $params{nyear}; - my $calendar="\n"; my $future_month = 0; - $future_month = $now[4]+1 if ($year == $now[5]+1900); + $future_month = $now[4]+1 if ($params{year} == $now[5]+1900); my $archivebase = 'archives'; $archivebase = $config{archivebase} if defined $config{archivebase}; $archivebase = $params{archivebase} if defined $params{archivebase}; # calculate URL's for previous and next years - my ($url, $purl, $nurl)=("$year",'',''); - if (exists $pagesources{"$archivebase/$year"}) { + my ($url, $purl, $nurl)=("$params{year}",'',''); + if (exists $pagesources{"$archivebase/$params{year}"}) { $url = htmllink($params{page}, $params{destpage}, - "$archivebase/$year", - linktext => "$year"); + "$archivebase/$params{year}", + linktext => "$params{year}"); } - add_depends($params{page}, "$archivebase/$year", deptype("presence")); - if (exists $pagesources{"$archivebase/$pyear"}) { + add_depends($params{page}, "$archivebase/$params{year}", deptype("presence")); + if (exists $pagesources{"$archivebase/$params{pyear}"}) { $purl = htmllink($params{page}, $params{destpage}, - "$archivebase/$pyear", + "$archivebase/$params{pyear}", linktext => "\←"); } - add_depends($params{page}, "$archivebase/$pyear", deptype("presence")); - if (exists $pagesources{"$archivebase/$nyear"}) { + add_depends($params{page}, "$archivebase/$params{pyear}", deptype("presence")); + if (exists $pagesources{"$archivebase/$params{nyear}"}) { $nurl = htmllink($params{page}, $params{destpage}, - "$archivebase/$nyear", + "$archivebase/$params{nyear}", linktext => "\→"); } - add_depends($params{page}, "$archivebase/$nyear", deptype("presence")); + add_depends($params{page}, "$archivebase/$params{nyear}", deptype("presence")); # Start producing the year calendar $calendar=< EOF - for ($month = 1; $month <= 12; $month++) { - my @day=localtime(timelocal(0,0,0,15,$month-1,$year-1900)); + for (my $month = 1; $month <= 12; $month++) { + my @day=localtime(timelocal(0,0,0,15,$month-1,$params{year}-1900)); my $murl; my $monthname = POSIX::strftime("%B", @day); my $monthabbr = POSIX::strftime("%b", @day); @@ -291,14 +275,14 @@ EOF my $tag; my $mtag=sprintf("%02d", $month); if ($month == $params{month}) { - if ($pagesources{"$archivebase/$year/$mtag"}) { + if ($pagesources{"$archivebase/$params{year}/$mtag"}) { $tag = 'this_month_link'; } else { $tag = 'this_month_nolink'; } } - elsif ($pagesources{"$archivebase/$year/$mtag"}) { + elsif ($pagesources{"$archivebase/$params{year}/$mtag"}) { $tag = 'month_link'; } elsif ($future_month && $month >= $future_month) { @@ -308,9 +292,9 @@ EOF $tag = 'month_nolink'; } - if ($pagesources{"$archivebase/$year/$mtag"}) { + if ($pagesources{"$archivebase/$params{year}/$mtag"}) { $murl = htmllink($params{page}, $params{destpage}, - "$archivebase/$year/$mtag", + "$archivebase/$params{year}/$mtag", linktext => "$monthabbr"); $calendar.=qq{\t}; $calendar.=$murl; @@ -319,7 +303,7 @@ EOF else { $calendar.=qq{\t$monthabbr\n}; } - add_depends($params{page}, "$archivebase/$year/$mtag", + add_depends($params{page}, "$archivebase/$params{year}/$mtag", deptype("presence")); $calendar.=qq{\t\n} if ($month % $params{months_per_row} == 0); @@ -356,28 +340,22 @@ sub preprocess (@) { } # Calculate month names for next month, and previous months - my $pmonth = $params{month} - 1; - my $nmonth = $params{month} + 1; - my $pyear = $params{year} - 1; - my $nyear = $params{year} + 1; + $params{pmonth} = $params{month} - 1; + $params{nmonth} = $params{month} + 1; + $params{pyear} = $params{year} - 1; + $params{nyear} = $params{year} + 1; # Adjust for January and December if ($params{month} == 1) { - $pmonth = 12; - $pyear--; + $params{pmonth} = 12; + $params{pyear}--; } if ($params{month} == 12) { - $nmonth = 1; - $nyear++; + $params{nmonth} = 1; + $params{nyear}++; } - $params{pmonth}=$pmonth; - $params{nmonth}=$nmonth; - $params{pyear} =$pyear; - $params{nyear} =$nyear; - - my $calendar="\n"; - + my $calendar=""; if ($params{type} =~ /month/i) { $calendar=format_month(%params); } -- cgit v1.2.3 From dd80be66ee7d9a28e788efcc1b3eb62bbe8611dd Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 11 Oct 2009 21:06:10 -0400 Subject: calendar: Fix midnight rebuild trigger of calendars with explicit month/year. It was just broken for calendars with an explicit month or year, not triggering at all. Now it will update those at appropriate times. --- IkiWiki/Plugin/calendar.pm | 42 +++++++++++++++++++++++++++++++++--------- debian/changelog | 2 ++ 2 files changed, 35 insertions(+), 9 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index fe7ee0361..9cbfd769d 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -318,24 +318,48 @@ EOF sub preprocess (@) { my %params=@_; + + my $thisyear=1900 + $now[5]; + my $thismonth=1 + $now[4]; + $params{pages} = "*" unless defined $params{pages}; $params{type} = "month" unless defined $params{type}; - $params{month} = sprintf("%02d", $params{month}) if defined $params{month}; $params{week_start_day} = 0 unless defined $params{week_start_day}; $params{months_per_row} = 3 unless defined $params{months_per_row}; - - if (! defined $params{year} || ! defined $params{month}) { - # Record that the calendar next changes at midnight. + $params{year} = $thisyear unless defined $params{year}; + $params{month} = $thismonth unless defined $params{month}; + + $params{month} = sprintf("%02d", $params{month}); + + if ($params{type} eq 'month' && $params{year} == $thisyear + && $params{month} == $thismonth) { + # calendar for current month, updates next midnight $pagestate{$params{destpage}}{calendar}{nextchange}=($time + (60 - $now[0]) # seconds + (59 - $now[1]) * 60 # minutes + (23 - $now[2]) * 60 * 60 # hours ); - - $params{year} = 1900 + $now[5] unless defined $params{year}; - $params{month} = 1 + $now[4] unless defined $params{month}; + } + elsif ($params{type} eq 'month' && + (($params{year} == $thisyear && $params{month} > $thismonth) || + $params{year} > $thisyear)) { + # calendar for upcoming month, updates 1st of that month + $pagestate{$params{destpage}}{calendar}{nextchange}= + timelocal(0, 0, 0, 1, $params{month}-1, $params{year}); + } + elsif ($params{type} eq 'year' && $params{year} == $thisyear) { + # calendar for current year, updates 1st of next month + $pagestate{$params{destpage}}{calendar}{nextchange}= + timelocal(0, 0, 0, 1, $thismonth+1-1, $params{year}); + } + elsif ($params{type} eq 'year' && $params{year} > $thisyear) { + # calendar for upcoming year, updates 1st of that year + $pagestate{$params{destpage}}{calendar}{nextchange}= + timelocal(0, 0, 0, 1, 1-1, $params{year}); } else { + # calendar for past month or year, does not need + # to update any more delete $pagestate{$params{destpage}}{calendar}; } @@ -356,10 +380,10 @@ sub preprocess (@) { } my $calendar=""; - if ($params{type} =~ /month/i) { + if ($params{type} eq 'month') { $calendar=format_month(%params); } - elsif ($params{type} =~ /year/i) { + elsif ($params{type} eq 'year') { $calendar=format_year(%params); } diff --git a/debian/changelog b/debian/changelog index 0e288dd08..c64758a77 100644 --- a/debian/changelog +++ b/debian/changelog @@ -28,6 +28,8 @@ ikiwiki (3.2009XXXX) UNRELEASED; urgency=low * Transitive dependencies are now correctly supported. * ikiwiki-calendar: New command automates creation of archive pages using the calendar plugin. + * calendar: Fix midnight rebuild trigger of calendars with explicit + month/year. -- Joey Hess Fri, 09 Oct 2009 19:53:50 -0400 -- cgit v1.2.3 From f3342773d3a6c9da11c248c4cc385dca284add06 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 11 Oct 2009 21:42:59 -0400 Subject: calendar: Fix bug in next/previous year/month links, which sometimes linked to an archive page from the wrong year. --- IkiWiki/Plugin/calendar.pm | 63 ++++++++++++++++++++++++---------------------- debian/changelog | 2 ++ 2 files changed, 35 insertions(+), 30 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index 9cbfd769d..5b4bfac89 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -81,6 +81,21 @@ sub format_month (@) { # Only one posting per day is being linked to. $linkcache{"$year/$mtag/$mday"} = "$src"; } + + my $pmonth = $params{month} - 1; + my $nmonth = $params{month} + 1; + my $pyear = $params{year}; + my $nyear = $params{year}; + + # Adjust for January and December + if ($params{month} == 1) { + $pmonth = 12; + $pyear--; + } + if ($params{month} == 12) { + $nmonth = 1; + $nyear++; + } my @list; my $calendar="\n"; @@ -97,8 +112,8 @@ sub format_month (@) { # Find out month names for this, next, and previous months my $monthname=POSIX::strftime("%B", @monthstart); - my $pmonthname=POSIX::strftime("%B", localtime(timelocal(0,0,0,1,$params{pmonth}-1,$params{pyear}-1900))); - my $nmonthname=POSIX::strftime("%B", localtime(timelocal(0,0,0,1,$params{nmonth}-1,$params{nyear}-1900))); + my $pmonthname=POSIX::strftime("%B", localtime(timelocal(0,0,0,1,$pmonth-1,$pyear-1900))); + my $nmonthname=POSIX::strftime("%B", localtime(timelocal(0,0,0,1,$nmonth-1,$nyear-1900))); my $archivebase = 'archives'; $archivebase = $config{archivebase} if defined $config{archivebase}; @@ -113,19 +128,19 @@ sub format_month (@) { } add_depends($params{page}, "$archivebase/$params{year}/".sprintf("%02d", $params{month}), deptype("presence")); - if (exists $pagesources{"$archivebase/$params{pyear}/$params{pmonth}"}) { + if (exists $pagesources{"$archivebase/$pyear/$pmonth"}) { $purl = htmllink($params{page}, $params{destpage}, - "$archivebase/$params{pyear}/" . sprintf("%02d", $params{pmonth}), + "$archivebase/$pyear/" . sprintf("%02d", $pmonth), linktext => " $pmonthname "); } - add_depends($params{page}, "$archivebase/$params{pyear}/".sprintf("%02d", $params{pmonth}), + add_depends($params{page}, "$archivebase/$pyear/".sprintf("%02d", $pmonth), deptype("presence")); - if (exists $pagesources{"$archivebase/$params{nyear}/$params{nmonth}"}) { + if (exists $pagesources{"$archivebase/$nyear/$nmonth"}) { $nurl = htmllink($params{page}, $params{destpage}, - "$archivebase/$params{nyear}/" . sprintf("%02d", $params{nmonth}), + "$archivebase/$nyear/" . sprintf("%02d", $nmonth), linktext => " $nmonthname "); } - add_depends($params{page}, "$archivebase/$params{nyear}/".sprintf("%02d", $params{nmonth}), + add_depends($params{page}, "$archivebase/$nyear/".sprintf("%02d", $nmonth), deptype("presence")); # Start producing the month calendar @@ -222,8 +237,11 @@ EOF sub format_year (@) { my %params=@_; - + my $calendar="\n"; + + my $pyear = $params{year} - 1; + my $nyear = $params{year} + 1; my $future_month = 0; $future_month = $now[4]+1 if ($params{year} == $now[5]+1900); @@ -240,18 +258,18 @@ sub format_year (@) { linktext => "$params{year}"); } add_depends($params{page}, "$archivebase/$params{year}", deptype("presence")); - if (exists $pagesources{"$archivebase/$params{pyear}"}) { + if (exists $pagesources{"$archivebase/$pyear"}) { $purl = htmllink($params{page}, $params{destpage}, - "$archivebase/$params{pyear}", + "$archivebase/$pyear", linktext => "\←"); } - add_depends($params{page}, "$archivebase/$params{pyear}", deptype("presence")); - if (exists $pagesources{"$archivebase/$params{nyear}"}) { + add_depends($params{page}, "$archivebase/$pyear", deptype("presence")); + if (exists $pagesources{"$archivebase/$nyear"}) { $nurl = htmllink($params{page}, $params{destpage}, - "$archivebase/$params{nyear}", + "$archivebase/$nyear", linktext => "\→"); } - add_depends($params{page}, "$archivebase/$params{nyear}", deptype("presence")); + add_depends($params{page}, "$archivebase/$nyear", deptype("presence")); # Start producing the year calendar $calendar=< Fri, 09 Oct 2009 19:53:50 -0400 -- cgit v1.2.3 From 8a37be35acb2c2c37d272489d2f2678e47c61834 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 11 Oct 2009 21:43:16 -0400 Subject: fix day links I broke this recently. --- IkiWiki/Plugin/calendar.pm | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index 5b4bfac89..0266612ae 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -71,7 +71,6 @@ sub format_month (@) { # 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; @@ -79,7 +78,7 @@ sub format_month (@) { my $mtag = sprintf("%02d", $month); # Only one posting per day is being linked to. - $linkcache{"$year/$mtag/$mday"} = "$src"; + $linkcache{"$year/$mtag/$mday"} = $p; } my $pmonth = $params{month} - 1; @@ -97,7 +96,6 @@ sub format_month (@) { $nyear++; } - my @list; my $calendar="\n"; # When did this month start? @@ -195,7 +193,7 @@ EOF my $tag; my $mtag = sprintf("%02d", $params{month}); - if (defined $pagesources{"$archivebase/$params{year}/$mtag/$day"}) { + if (defined $linkcache{"$params{year}/$mtag/$day"}) { if ($day == $today) { $tag='month-calendar-day-this-day'; } @@ -204,9 +202,8 @@ EOF } $calendar.=qq{\t\t}; $calendar.=htmllink($params{page}, $params{destpage}, - pagename($linkcache{"$params{year}/$mtag/$day"}), + $linkcache{"$params{year}/$mtag/$day"}, "linktext" => "$day"); - push @list, pagename($linkcache{"$params{year}/$mtag/$day"}); $calendar.=qq{\n}; } else { -- cgit v1.2.3 From 23a21850faf1cbb4bd8547b11563c5806617cf7e Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 11 Oct 2009 21:52:50 -0400 Subject: fix next/prev month padding bug --- IkiWiki/Plugin/calendar.pm | 21 ++++++++++++--------- debian/changelog | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index 0266612ae..cf133e8dc 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -96,6 +96,10 @@ sub format_month (@) { $nyear++; } + # Add padding. + $pmonth=sprintf("%02d", $pmonth); + $nmonth=sprintf("%02d", $nmonth); + my $calendar="\n"; # When did this month start? @@ -121,24 +125,24 @@ sub format_month (@) { my ($url, $purl, $nurl)=("$monthname",'',''); if (exists $pagesources{"$archivebase/$params{year}/$params{month}"}) { $url = htmllink($params{page}, $params{destpage}, - "$archivebase/$params{year}/".sprintf("%02d", $params{month}), + "$archivebase/$params{year}/".$params{month}, linktext => " $monthname "); } - add_depends($params{page}, "$archivebase/$params{year}/".sprintf("%02d", $params{month}), + add_depends($params{page}, "$archivebase/$params{year}/$params{month}", deptype("presence")); if (exists $pagesources{"$archivebase/$pyear/$pmonth"}) { $purl = htmllink($params{page}, $params{destpage}, - "$archivebase/$pyear/" . sprintf("%02d", $pmonth), + "$archivebase/$pyear/$pmonth", linktext => " $pmonthname "); } - add_depends($params{page}, "$archivebase/$pyear/".sprintf("%02d", $pmonth), + add_depends($params{page}, "$archivebase/$pyear/$pmonth", deptype("presence")); if (exists $pagesources{"$archivebase/$nyear/$nmonth"}) { $nurl = htmllink($params{page}, $params{destpage}, - "$archivebase/$nyear/" . sprintf("%02d", $nmonth), + "$archivebase/$nyear/$nmonth", linktext => " $nmonthname "); } - add_depends($params{page}, "$archivebase/$nyear/".sprintf("%02d", $nmonth), + add_depends($params{page}, "$archivebase/$nyear/$nmonth", deptype("presence")); # Start producing the month calendar @@ -192,8 +196,7 @@ EOF } my $tag; - my $mtag = sprintf("%02d", $params{month}); - if (defined $linkcache{"$params{year}/$mtag/$day"}) { + if (defined $linkcache{"$params{year}/$params{month}/$day"}) { if ($day == $today) { $tag='month-calendar-day-this-day'; } @@ -202,7 +205,7 @@ EOF } $calendar.=qq{\t\t}; $calendar.=htmllink($params{page}, $params{destpage}, - $linkcache{"$params{year}/$mtag/$day"}, + $linkcache{"$params{year}/$params{month}/$day"}, "linktext" => "$day"); $calendar.=qq{\n}; } diff --git a/debian/changelog b/debian/changelog index 8881c48aa..5c47b2524 100644 --- a/debian/changelog +++ b/debian/changelog @@ -31,7 +31,7 @@ ikiwiki (3.2009XXXX) UNRELEASED; urgency=low * calendar: Fix midnight rebuild trigger of calendars with explicit month/year. * calendar: Fix bug in next/previous year/month links, which sometimes - linked to an archive page from the wrong year. + linked to an archive page from the wrong year, or were missing. -- Joey Hess Fri, 09 Oct 2009 19:53:50 -0400 -- cgit v1.2.3 From cf74cf7a37a1fa4e02dffc6f3ac580626d183433 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 11 Oct 2009 21:55:06 -0400 Subject: calendar: use left and right arrows for next/prev months This is consistent with the year display, and I think it is less visually confusing than using the full month names. --- IkiWiki/Plugin/calendar.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index cf133e8dc..dcf2b6d64 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -133,14 +133,14 @@ sub format_month (@) { if (exists $pagesources{"$archivebase/$pyear/$pmonth"}) { $purl = htmllink($params{page}, $params{destpage}, "$archivebase/$pyear/$pmonth", - linktext => " $pmonthname "); + linktext => " \&larr "); } add_depends($params{page}, "$archivebase/$pyear/$pmonth", deptype("presence")); if (exists $pagesources{"$archivebase/$nyear/$nmonth"}) { $nurl = htmllink($params{page}, $params{destpage}, "$archivebase/$nyear/$nmonth", - linktext => " $nmonthname "); + linktext => " \&rarr "); } add_depends($params{page}, "$archivebase/$nyear/$nmonth", deptype("presence")); -- cgit v1.2.3 From e4c765c64fc31ab13c911b716e80b07b4d1a0037 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 11 Oct 2009 22:11:11 -0400 Subject: calendar: avoid inline images in links --- IkiWiki/Plugin/calendar.pm | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index dcf2b6d64..e3c5e2f2d 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -126,6 +126,7 @@ sub format_month (@) { if (exists $pagesources{"$archivebase/$params{year}/$params{month}"}) { $url = htmllink($params{page}, $params{destpage}, "$archivebase/$params{year}/".$params{month}, + noimageinline => 1, linktext => " $monthname "); } add_depends($params{page}, "$archivebase/$params{year}/$params{month}", @@ -133,6 +134,7 @@ sub format_month (@) { if (exists $pagesources{"$archivebase/$pyear/$pmonth"}) { $purl = htmllink($params{page}, $params{destpage}, "$archivebase/$pyear/$pmonth", + noimageinline => 1, linktext => " \&larr "); } add_depends($params{page}, "$archivebase/$pyear/$pmonth", @@ -140,6 +142,7 @@ sub format_month (@) { if (exists $pagesources{"$archivebase/$nyear/$nmonth"}) { $nurl = htmllink($params{page}, $params{destpage}, "$archivebase/$nyear/$nmonth", + noimageinline => 1, linktext => " \&rarr "); } add_depends($params{page}, "$archivebase/$nyear/$nmonth", @@ -205,8 +208,9 @@ EOF } $calendar.=qq{\t\t}; $calendar.=htmllink($params{page}, $params{destpage}, - $linkcache{"$params{year}/$params{month}/$day"}, - "linktext" => "$day"); + $linkcache{"$params{year}/$params{month}/$day"}, + noimageinline => 1, + "linktext" => "$day"); $calendar.=qq{\n}; } else { @@ -255,18 +259,21 @@ sub format_year (@) { if (exists $pagesources{"$archivebase/$params{year}"}) { $url = htmllink($params{page}, $params{destpage}, "$archivebase/$params{year}", + noimageinline => 1, linktext => "$params{year}"); } add_depends($params{page}, "$archivebase/$params{year}", deptype("presence")); if (exists $pagesources{"$archivebase/$pyear"}) { $purl = htmllink($params{page}, $params{destpage}, "$archivebase/$pyear", + noimageinline => 1, linktext => "\←"); } add_depends($params{page}, "$archivebase/$pyear", deptype("presence")); if (exists $pagesources{"$archivebase/$nyear"}) { $nurl = htmllink($params{page}, $params{destpage}, "$archivebase/$nyear", + noimageinline => 1, linktext => "\→"); } add_depends($params{page}, "$archivebase/$nyear", deptype("presence")); @@ -313,6 +320,7 @@ EOF if ($pagesources{"$archivebase/$params{year}/$mtag"}) { $murl = htmllink($params{page}, $params{destpage}, "$archivebase/$params{year}/$mtag", + noimageinline => 1, linktext => "$monthabbr"); $calendar.=qq{\t}; $calendar.=$murl; -- cgit v1.2.3 From bf577d34c79ebe48efdf06ed826f9109e196cc6d Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 11 Oct 2009 23:07:31 -0400 Subject: can't use --reverse with git log --follow Meh, git. --- IkiWiki/Plugin/git.pm | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/git.pm b/IkiWiki/Plugin/git.pm index e10283f59..9ecda4ffb 100644 --- a/IkiWiki/Plugin/git.pm +++ b/IkiWiki/Plugin/git.pm @@ -613,11 +613,14 @@ sub rcs_getctime ($) { # Remove srcdir prefix $file =~ s/^\Q$config{srcdir}\E\/?//; - my @raw_lines = run_or_die('git', 'log', '--reverse', '--follow', + my @raw_lines = run_or_die('git', 'log', '--follow', '--pretty=raw', '--raw', '--abbrev=40', '--always', '-c', '-r', '--', $file); - my $first = parse_diff_tree("", \@raw_lines); - my $ctime = $first->{'author_epoch'}; + my @ci; + while (my $parsed = parse_diff_tree("", \@raw_lines)) { + push @ci, $parsed; + } + my $ctime = $ci[$#ci]->{'author_epoch'}; debug("ctime for '$file': ". localtime($ctime)); return $ctime; -- cgit v1.2.3 From e82b43bf950e1ff11683ae96abdd29879f92488a Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 12 Oct 2009 00:50:48 -0400 Subject: skip merges git log --follow seems to sometimes show merges from before the file was ever created. So, skip them, a file shouldn't be first created during a merge anyway. --- IkiWiki/Plugin/git.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/git.pm b/IkiWiki/Plugin/git.pm index 9ecda4ffb..c5c83a3a7 100644 --- a/IkiWiki/Plugin/git.pm +++ b/IkiWiki/Plugin/git.pm @@ -613,7 +613,8 @@ sub rcs_getctime ($) { # Remove srcdir prefix $file =~ s/^\Q$config{srcdir}\E\/?//; - my @raw_lines = run_or_die('git', 'log', '--follow', + my @raw_lines = run_or_die('git', 'log', + '--follow', '--no-merges', '--pretty=raw', '--raw', '--abbrev=40', '--always', '-c', '-r', '--', $file); my @ci; -- cgit v1.2.3 From 11e6d650eae4377485cb83f61a0ce9519ceb4c57 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 12 Oct 2009 12:19:42 -0400 Subject: calendar: Fix CSS for year calendar to match the plugin documentation. The names in the documentation were completly different, but also seemed better chosen than the names in the code. --- IkiWiki/Plugin/calendar.pm | 13 ++++--------- debian/changelog | 1 + 2 files changed, 5 insertions(+), 9 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index e3c5e2f2d..71c671d67 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -300,21 +300,16 @@ EOF my $tag; my $mtag=sprintf("%02d", $month); if ($month == $params{month}) { - if ($pagesources{"$archivebase/$params{year}/$mtag"}) { - $tag = 'this_month_link'; - } - else { - $tag = 'this_month_nolink'; - } + $tag = 'year-calendar-this-month'; } elsif ($pagesources{"$archivebase/$params{year}/$mtag"}) { - $tag = 'month_link'; + $tag = 'year-calendar-month-link'; } elsif ($future_month && $month >= $future_month) { - $tag = 'month_future'; + $tag = 'year-calendar-month-future'; } else { - $tag = 'month_nolink'; + $tag = 'year-calendar-month-nolink'; } if ($pagesources{"$archivebase/$params{year}/$mtag"}) { diff --git a/debian/changelog b/debian/changelog index e9f09a8c6..b9d1923cd 100644 --- a/debian/changelog +++ b/debian/changelog @@ -34,6 +34,7 @@ ikiwiki (3.2009XXXX) UNRELEASED; urgency=low linked to an archive page from the wrong year, or were missing. * git: --getctime will now follow renames back to the original creation of a file. + * calendar: Fix CSS for year calendar to match the plugin documentation. -- Joey Hess Fri, 09 Oct 2009 19:53:50 -0400 -- cgit v1.2.3 From 227540fd875bfaa6b810c0d7caa346f32d5bd7ce Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 12 Oct 2009 12:30:10 -0400 Subject: calendar: Add creation time limits to user's pagespec This avoids all calendars rebuilding when a new page is added that will only show in one of them. --- IkiWiki/Plugin/calendar.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index 71c671d67..5aac95884 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -66,7 +66,8 @@ sub format_month (@) { my %params=@_; my %linkcache; - foreach my $p (pagespec_match_list($params{page}, $params{pages}, + foreach my $p (pagespec_match_list($params{page}, + "creation_year($params{year}) and creation_month($params{month}) and ($params{pages})", # add presence dependencies to update # month calendar when pages are added/removed deptype => deptype("presence"))) { -- cgit v1.2.3 From 22737e53f1b0367bc9bfb8d7bcbfc4dcc08a81ae Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 12 Oct 2009 14:05:56 -0400 Subject: remove whitespace from within arrow links --- IkiWiki/Plugin/calendar.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index 5aac95884..d5a80795a 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -136,7 +136,7 @@ sub format_month (@) { $purl = htmllink($params{page}, $params{destpage}, "$archivebase/$pyear/$pmonth", noimageinline => 1, - linktext => " \&larr "); + linktext => "\&larr"); } add_depends($params{page}, "$archivebase/$pyear/$pmonth", deptype("presence")); @@ -144,7 +144,7 @@ sub format_month (@) { $nurl = htmllink($params{page}, $params{destpage}, "$archivebase/$nyear/$nmonth", noimageinline => 1, - linktext => " \&rarr "); + linktext => "\&rarr"); } add_depends($params{page}, "$archivebase/$nyear/$nmonth", deptype("presence")); -- cgit v1.2.3 From 5c78192435210cdb7792ed56b04c2ef24a2d2127 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 12 Oct 2009 14:19:04 -0400 Subject: year calendar: only link to months that have posts This does mean the year calendars depend on existence of all posts made in the year and have to be updated. --- IkiWiki/Plugin/calendar.pm | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index d5a80795a..ddcd1a823 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -242,6 +242,20 @@ EOF sub format_year (@) { my %params=@_; + + my @post_months; + foreach my $p (pagespec_match_list($params{page}, + "creation_year($params{year}) and ($params{pages})", + # add presence dependencies to update + # year calendar's links to months when + # pages are added/removed + deptype => deptype("presence"))) { + my $mtime = $IkiWiki::pagectime{$p}; + my @date = localtime($mtime); + my $month = $date[4] + 1; + + $post_months[$month]++; + } my $calendar="\n"; @@ -313,7 +327,8 @@ EOF $tag = 'year-calendar-month-nolink'; } - if ($pagesources{"$archivebase/$params{year}/$mtag"}) { + if ($pagesources{"$archivebase/$params{year}/$mtag"} && + $post_months[$mtag]) { $murl = htmllink($params{page}, $params{destpage}, "$archivebase/$params{year}/$mtag", noimageinline => 1, -- cgit v1.2.3 From 28c4caea59543b6d8fd0c62ff5a60aff67a9bba7 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 12 Oct 2009 14:22:48 -0400 Subject: year calendar: Avoid highlighting the current month in a different year --- IkiWiki/Plugin/calendar.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index ddcd1a823..c9bdf4a17 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -262,8 +262,9 @@ sub format_year (@) { my $pyear = $params{year} - 1; my $nyear = $params{year} + 1; + my $thisyear = $now[5]+1900; my $future_month = 0; - $future_month = $now[4]+1 if ($params{year} == $now[5]+1900); + $future_month = $now[4]+1 if $params{year} == $thisyear; my $archivebase = 'archives'; $archivebase = $config{archivebase} if defined $config{archivebase}; @@ -314,7 +315,7 @@ EOF $calendar.=qq{\t\n} if ($month % $params{months_per_row} == 1); my $tag; my $mtag=sprintf("%02d", $month); - if ($month == $params{month}) { + if ($month == $params{month} && $thisyear == $params{year}) { $tag = 'year-calendar-this-month'; } elsif ($pagesources{"$archivebase/$params{year}/$mtag"}) { -- cgit v1.2.3