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 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'IkiWiki/Plugin/inline.pm') 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}) { -- 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/inline.pm') 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 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/inline.pm') 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 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/inline.pm') 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 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/inline.pm') 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 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/inline.pm') 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 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/inline.pm') 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 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/inline.pm') 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