pagespec_match_list added and used in most appropriate places
* pagespec_match_list: New API function, matches pages in a list and throws an error if the pagespec is bad. * inline, brokenlinks, calendar, linkmap, map, orphans, pagecount, pagestate, postsparkline: Display a handy error message if the pagespec is erronious.master
parent
527d178c12
commit
aa306957ba
32
IkiWiki.pm
32
IkiWiki.pm
|
@ -18,10 +18,10 @@ use vars qw{%config %links %oldlinks %pagemtime %pagectime %pagecase
|
||||||
|
|
||||||
use Exporter q{import};
|
use Exporter q{import};
|
||||||
our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
|
our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
|
||||||
bestlink htmllink readfile writefile pagetype srcfile pagename
|
pagespec_match_list bestlink htmllink readfile writefile
|
||||||
displaytime will_render gettext urlto targetpage
|
pagetype srcfile pagename displaytime will_render gettext urlto
|
||||||
add_underlay pagetitle titlepage linkpage newpagefile
|
targetpage add_underlay pagetitle titlepage linkpage
|
||||||
inject
|
newpagefile inject
|
||||||
%config %links %pagestate %wikistate %renderedfiles
|
%config %links %pagestate %wikistate %renderedfiles
|
||||||
%pagesources %destsources);
|
%pagesources %destsources);
|
||||||
our $VERSION = 3.00; # plugin interface version, next is ikiwiki version
|
our $VERSION = 3.00; # plugin interface version, next is ikiwiki version
|
||||||
|
@ -1832,6 +1832,30 @@ sub pagespec_match ($$;@) {
|
||||||
return $sub->($page, @params);
|
return $sub->($page, @params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub pagespec_match_list ($$;@) {
|
||||||
|
my $pages=shift;
|
||||||
|
my $spec=shift;
|
||||||
|
my @params=@_;
|
||||||
|
|
||||||
|
my $sub=pagespec_translate($spec);
|
||||||
|
error "syntax error in pagespec \"$spec\""
|
||||||
|
if $@ || ! defined $sub;
|
||||||
|
|
||||||
|
my @ret;
|
||||||
|
my $r;
|
||||||
|
foreach my $page (@$pages) {
|
||||||
|
$r=$sub->($page, @params);
|
||||||
|
push @ret, $page if $r;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! @ret && defined $r && $r->isa("IkiWiki::ErrorReason")) {
|
||||||
|
error(sprintf(gettext("cannot match pages: %s"), $r));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return @ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sub pagespec_valid ($) {
|
sub pagespec_valid ($) {
|
||||||
my $spec=shift;
|
my $spec=shift;
|
||||||
|
|
||||||
|
|
|
@ -28,8 +28,8 @@ sub preprocess (@) {
|
||||||
add_depends($params{page}, $params{pages});
|
add_depends($params{page}, $params{pages});
|
||||||
|
|
||||||
my %broken;
|
my %broken;
|
||||||
foreach my $page (keys %links) {
|
foreach my $page (pagespec_match_list([keys %links],
|
||||||
if (pagespec_match($page, $params{pages}, location => $params{page})) {
|
$params{pages}, location => $params{page})) {
|
||||||
my $discussion=gettext("discussion");
|
my $discussion=gettext("discussion");
|
||||||
my %seen;
|
my %seen;
|
||||||
foreach my $link (@{$links{$page}}) {
|
foreach my $link (@{$links{$page}}) {
|
||||||
|
@ -41,7 +41,6 @@ sub preprocess (@) {
|
||||||
push @{$broken{$link}}, $page;
|
push @{$broken{$link}}, $page;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
my @broken;
|
my @broken;
|
||||||
foreach my $link (keys %broken) {
|
foreach my $link (keys %broken) {
|
||||||
|
|
|
@ -369,8 +369,7 @@ sub preprocess (@) {
|
||||||
my $page =$params{page};
|
my $page =$params{page};
|
||||||
|
|
||||||
if (! defined $cache{$pagespec}) {
|
if (! defined $cache{$pagespec}) {
|
||||||
foreach my $p (keys %pagesources) {
|
foreach my $p (pagespec_match_list([keys %pagesources], $pagespec)) {
|
||||||
next unless pagespec_match($p, $pagespec);
|
|
||||||
my $mtime = $IkiWiki::pagectime{$p};
|
my $mtime = $IkiWiki::pagectime{$p};
|
||||||
my $src = $pagesources{$p};
|
my $src = $pagesources{$p};
|
||||||
my @date = localtime($mtime);
|
my @date = localtime($mtime);
|
||||||
|
|
|
@ -230,10 +230,17 @@ sub hook ($@) {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub pagespec_match ($@) {
|
sub pagespec_match ($@) {
|
||||||
# convert pagespec_match's return object into a XML RPC boolean
|
# convert return object into a XML RPC boolean
|
||||||
my $plugin=shift;
|
my $plugin=shift;
|
||||||
|
|
||||||
return RPC::XML::boolean->new(0 + IkiWiki::pagespec_march(@_));
|
return RPC::XML::boolean->new(0 + IkiWiki::pagespec_march(@_));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub pagespec_match_list ($@) {
|
||||||
|
# convert return object into a XML RPC boolean
|
||||||
|
my $plugin=shift;
|
||||||
|
|
||||||
|
return RPC::XML::boolean->new(0 + IkiWiki::pagespec_march_list(@_));
|
||||||
|
}
|
||||||
|
|
||||||
1
|
1
|
||||||
|
|
|
@ -183,20 +183,9 @@ sub preprocess_inline (@) {
|
||||||
$params{template} = $archive ? "archivepage" : "inlinepage";
|
$params{template} = $archive ? "archivepage" : "inlinepage";
|
||||||
}
|
}
|
||||||
|
|
||||||
my @list;
|
my @list=pagespec_match_list(
|
||||||
my $lastmatch;
|
[ grep { $_ ne $params{page}} keys %pagesources ],
|
||||||
foreach my $page (keys %pagesources) {
|
$params{pages}, location => $params{page});
|
||||||
next if $page eq $params{page};
|
|
||||||
$lastmatch=pagespec_match($page, $params{pages}, location => $params{page});
|
|
||||||
if ($lastmatch) {
|
|
||||||
push @list, $page;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! @list && defined $lastmatch &&
|
|
||||||
$lastmatch->isa("IkiWiki::ErrorReason")) {
|
|
||||||
error(sprintf(gettext("cannot match pages: %s"), $lastmatch));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (exists $params{sort} && $params{sort} eq 'title') {
|
if (exists $params{sort} && $params{sort} eq 'title') {
|
||||||
@list=sort { pagetitle(basename($a)) cmp pagetitle(basename($b)) } @list;
|
@list=sort { pagetitle(basename($a)) cmp pagetitle(basename($b)) } @list;
|
||||||
|
|
|
@ -56,11 +56,10 @@ sub genmap ($) {
|
||||||
|
|
||||||
# Get all the items to map.
|
# Get all the items to map.
|
||||||
my %mapitems = ();
|
my %mapitems = ();
|
||||||
foreach my $item (keys %links) {
|
foreach my $item (pagespec_match_list([keys %links],
|
||||||
if (pagespec_match($item, $params{pages}, location => $params{page})) {
|
$params{pages}, location => $params{page})) {
|
||||||
$mapitems{$item}=urlto($item, $params{destpage});
|
$mapitems{$item}=urlto($item, $params{destpage});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
my $dest=$params{page}."/linkmap.png";
|
my $dest=$params{page}."/linkmap.png";
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,8 @@ sub preprocess (@) {
|
||||||
|
|
||||||
# Get all the items to map.
|
# Get all the items to map.
|
||||||
my %mapitems;
|
my %mapitems;
|
||||||
foreach my $page (keys %pagesources) {
|
foreach my $page (pagespec_match_list([keys %pagesources],
|
||||||
if (pagespec_match($page, $params{pages}, location => $params{page})) {
|
$params{pages}, location => $params{page})) {
|
||||||
if (exists $params{show} &&
|
if (exists $params{show} &&
|
||||||
exists $pagestate{$page} &&
|
exists $pagestate{$page} &&
|
||||||
exists $pagestate{$page}{meta}{$params{show}}) {
|
exists $pagestate{$page}{meta}{$params{show}}) {
|
||||||
|
@ -60,7 +60,6 @@ sub preprocess (@) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
# Common prefix should not be a page in the map.
|
# Common prefix should not be a page in the map.
|
||||||
while (defined $common_prefix && length $common_prefix &&
|
while (defined $common_prefix && length $common_prefix &&
|
||||||
|
|
|
@ -35,9 +35,10 @@ sub preprocess (@) {
|
||||||
|
|
||||||
my @orphans;
|
my @orphans;
|
||||||
my $discussion=gettext("discussion");
|
my $discussion=gettext("discussion");
|
||||||
foreach my $page (keys %pagesources) {
|
foreach my $page (pagespec_match_list(
|
||||||
next if $linkedto{$page} || $page eq 'index';
|
[ grep { ! $linkedto{$_} && $_ ne 'index' }
|
||||||
next unless pagespec_match($page, $params{pages}, location => $params{page});
|
keys %pagesources ],
|
||||||
|
$params{pages}, location => $params{page})) {
|
||||||
# If the page has a link to some other page, it's
|
# If the page has a link to some other page, it's
|
||||||
# indirectly linked to a page via that page's backlinks.
|
# indirectly linked to a page via that page's backlinks.
|
||||||
next if grep {
|
next if grep {
|
||||||
|
|
|
@ -27,12 +27,9 @@ sub preprocess (@) {
|
||||||
add_depends($params{page}, $params{pages});
|
add_depends($params{page}, $params{pages});
|
||||||
|
|
||||||
my @pages=keys %pagesources;
|
my @pages=keys %pagesources;
|
||||||
return $#pages+1 if $params{pages} eq "*"; # optimisation
|
@pages=pagespec_match_list(\@pages, $params{pages}, location => $params{page})
|
||||||
my $count=0;
|
if $params{pages} ne "*"; # optimisation;
|
||||||
foreach my $page (@pages) {
|
return $#pages+1;
|
||||||
$count++ if pagespec_match($page, $params{pages}, location => $params{page});
|
|
||||||
}
|
|
||||||
return $count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
1
|
1
|
||||||
|
|
|
@ -41,13 +41,12 @@ sub preprocess (@) {
|
||||||
|
|
||||||
my %counts;
|
my %counts;
|
||||||
my $max = 0;
|
my $max = 0;
|
||||||
foreach my $page (keys %links) {
|
foreach my $page (pagespec_match_list([keys %links],
|
||||||
if (pagespec_match($page, $params{pages}, location => $params{page})) {
|
$params{pages}, location => $params{page})) {
|
||||||
use IkiWiki::Render;
|
use IkiWiki::Render;
|
||||||
$counts{$page} = scalar(IkiWiki::backlinks($page));
|
$counts{$page} = scalar(IkiWiki::backlinks($page));
|
||||||
$max = $counts{$page} if $counts{$page} > $max;
|
$max = $counts{$page} if $counts{$page} > $max;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ($style eq 'table') {
|
if ($style eq 'table') {
|
||||||
return "<table class='pageStats'>\n".
|
return "<table class='pageStats'>\n".
|
||||||
|
|
|
@ -50,13 +50,9 @@ sub preprocess (@) {
|
||||||
|
|
||||||
add_depends($params{page}, $params{pages});
|
add_depends($params{page}, $params{pages});
|
||||||
|
|
||||||
my @list;
|
my @list=pagespec_match_list(
|
||||||
foreach my $page (keys %pagesources) {
|
[ grep { $_ ne $params{page} } keys %pagesources],
|
||||||
next if $page eq $params{page};
|
$params{pages}, location => $params{page});
|
||||||
if (pagespec_match($page, $params{pages}, location => $params{page})) {
|
|
||||||
push @list, $page;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@list = sort { $params{timehash}->{$b} <=> $params{timehash}->{$a} } @list;
|
@list = sort { $params{timehash}->{$b} <=> $params{timehash}->{$a} } @list;
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,11 @@ ikiwiki (3.11) UNRELEASED; urgency=low
|
||||||
* Add IkiWiki::ErrorReason objects, and modify pagespecs to return
|
* Add IkiWiki::ErrorReason objects, and modify pagespecs to return
|
||||||
them in cases where they fail to match due to a configuration or syntax
|
them in cases where they fail to match due to a configuration or syntax
|
||||||
error.
|
error.
|
||||||
* inline: Display a handy error message if the inline cannot display any
|
* pagespec_match_list: New API function, matches pages in a list
|
||||||
pages due to such an error.
|
and throws an error if the pagespec is bad.
|
||||||
|
* inline, brokenlinks, calendar, linkmap, map, orphans, pagecount,
|
||||||
|
pagestate, postsparkline: Display a handy error message if the pagespec
|
||||||
|
is erronious.
|
||||||
* comments: Add link to comment post form to allow user to sign in
|
* comments: Add link to comment post form to allow user to sign in
|
||||||
if they wish to, if the configuration makes signin optional
|
if they wish to, if the configuration makes signin optional
|
||||||
for commenting.
|
for commenting.
|
||||||
|
|
|
@ -572,6 +572,19 @@ The most often used is "location", which specifies the location the
|
||||||
PageSpec should match against. If not passed, relative PageSpecs will match
|
PageSpec should match against. If not passed, relative PageSpecs will match
|
||||||
relative to the top of the wiki.
|
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($$)`
|
#### `bestlink($$)`
|
||||||
|
|
||||||
Given a page and the text of a link on the page, determine which
|
Given a page and the text of a link on the page, determine which
|
||||||
|
|
Loading…
Reference in New Issue