1 I like the idea of [[tips/integrated_issue_tracking_with_ikiwiki]], and I do so on several wikis. However, as far as I can tell, ikiwiki has no functionality which can represent dependencies between bugs and allow pagespecs to select based on dependencies. For instance, I can't write a pagespec which selects all bugs with no dependencies on bugs not marked as done. --[[JoshTriplett]]
3 > I started having a think about this. I'm going to start with the idea that expanding
4 > the pagespec syntax is the way to attack this. It seems that any pagespec that is going
5 > to represent "all bugs with no dependencies on bugs not marked as done" is going to
6 > need some way to represent "bugs not marked as done" as a collection of pages, and
7 > then represent "bugs which do not link to pages in the previous collection".
9 > One way to do this would be to introduce variables into the pagespec, along with
10 > universal and/or existential [[!wikipedia Quantification]]. That looks quite complex.
12 > Another option would be go with a more functional syntax. The concept here would
13 > be to allow a pagespec to appear in a 'pagespec function' anywhere a page can. e.g.
14 > I could pass a pagespec to `link()` and that would return true if there is a link to any
15 > page matching the pagespec. This makes the variables and existential quantification
16 > implicit. It would allow the example requested above:
18 >> `bugs/* and !*/Discussion and !link(bugs/* and !*/Discussion and !link(done))`
20 > Unfortunately, this is also going to make the pagespec parsing more complex because
21 > we now need to parse nested sets of parentheses to know when the nested pagespec
22 > ends, and that isn't a regular language (we can't use regular expression matching for
25 > One simplification of that would be to introduce some pagespec [[shortcuts]]. We could
26 > then allow pagespec functions to take either pages, or named pagespec shortcuts. The
27 > pagespec shortcuts would just be listed on a special page, like current [[shortcuts]].
28 > (It would probably be a good idea to require that shortcuts on that page can only refer
29 > to named pagespecs higher up that page than themselves. That would stop some
30 > looping issues...) These shortcuts would be used as follows: when trying to match
31 > a page (without globs) you look to see if the page exists. If it does then you have a
32 > match. If it doesn't, then you look to see if a similarly named pagespec shortcut
33 > exists. If it does, then you check that pagespec recursively to see if you have a match.
34 > The ordering requirement on named pagespecs stops infinite recursion.
36 > Does that seem like a reasonable first approach?
40 > One quick further thought. All the above discussion assumes that 'dependency' is the
41 > same as 'links to', which is not really true. For example, you'd like to be able to say
42 > "This bug does not depend upon [ [ link to other bug ] ]" and not have a dependency.
43 > Without having different types of links, I don't see how this would be possible.
47 Okie - I've had a quick attempt at this. Initial patch attached. This one doesn't quite work.
48 And there is still a lot of debugging stuff in there.
50 At the moment I've added a new preprocessor plugin, `definepagespec`, which is like
51 shortcut for pagespecs. To reference a named pagespec, use `~` like this:
53 [ [!definepagespec name="bugs" spec="bugs/* and !*/Discussion"]]
54 [ [!definepagespec name="openbugs" spec="~bugs and !link(done)"]]
55 [ [!definepagespec name="readybugs" spec="~openbugs and !link(~openbugs)"]]
57 At the moment the problem is in `match_link()` when we're trying to find a sub-page that
58 matches the appropriate page spec. There is no good list of pages available to iterate over.
60 foreach my $nextpage (keys %IkiWiki::pagesources)
62 does not give me a good list of pages. I found the same thing when I was working on
63 this todo [[todo/Add_a_plugin_to_list_available_pre-processor_commands]].
65 Immediately below is a patch for IkiWiki.pm. Below that is a new plugin `definepagespec `
66 which behaves like `shortcut` for pagespecs.
70 diff --git a/IkiWiki.pm b/IkiWiki.pm
71 index e476521..1d2d48c 100644
74 @@ -14,7 +14,7 @@ use open qw{:utf8 :std};
75 use vars qw{%config %links %oldlinks %pagemtime %pagectime %pagecase
76 %pagestate %renderedfiles %oldrenderedfiles %pagesources
77 %destsources %depends %hooks %forcerebuild $gettext_obj
79 + %loaded_plugins %named_pagespec};
81 use Exporter q{import};
82 our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
83 @@ -22,7 +22,7 @@ our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
84 displaytime will_render gettext urlto targetpage
86 %config %links %pagestate %renderedfiles
87 - %pagesources %destsources);
88 + %pagesources %destsources %named_pagespec);
89 our $VERSION = 2.00; # plugin interface version, next is ikiwiki version
90 our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE
91 my $installdir=''; # INSTALLDIR_AUTOREPLACE done by Makefile, DNE
92 @@ -1271,7 +1271,7 @@ sub loadindex () { #{{{
93 %oldrenderedfiles=%pagectime=();
94 if (! $config{rebuild}) {
95 %pagesources=%pagemtime=%oldlinks=%links=%depends=
96 - %destsources=%renderedfiles=%pagecase=%pagestate=();
97 + %destsources=%renderedfiles=%pagecase=%pagestate=%named_pagespec=();
100 if (! open ($in, "<", "$config{wikistatedir}/indexdb")) {
101 @@ -1729,6 +1729,8 @@ sub match_glob ($$;@) { #{{{
103 my $from=exists $params{location} ? $params{location} : '';
105 + print "Matching glob $glob \n";
108 if ($glob =~ m!^\./!) {
110 @@ -1736,6 +1738,18 @@ sub match_glob ($$;@) { #{{{
111 $glob="$from/$glob" if length $from;
114 + if (substr($glob, 0, 1) eq '~') {
115 + my $specname = substr($glob, 1);
116 + print "Checking for pagespec named $specname \n";
117 + if (exists $IkiWiki::named_pagespec{$specname}) {
118 + my $spec = $IkiWiki::named_pagespec{$specname};
119 + return IkiWiki::pagespec_match($page, $spec, %params);
121 + print "Couldn't find pagespec\n";
122 + return IkiWiki::FailReason->new("Page spec $specname referenced on page $page does not exist");
126 my $regexp=IkiWiki::glob2re($glob);
127 if ($page=~/^$regexp$/i) {
128 if (! IkiWiki::isinternal($page) || $params{internal}) {
129 @@ -1756,11 +1770,36 @@ sub match_internal ($$;@) { #{{{
131 sub match_link ($$;@) { #{{{
133 - my $link=lc(shift);
134 + my $fulllink=shift;
135 + my $link=lc($fulllink);
138 + print "Matching link $fulllink \n";
140 my $from=exists $params{location} ? $params{location} : '';
142 + if (substr($fulllink, 0, 1) eq '~') {
143 + my $specname = substr($fulllink, 1);
144 + print "Checking link pagespec $specname \n";
145 + if (exists $IkiWiki::named_pagespec{$specname}) {
146 + my $spec = $IkiWiki::named_pagespec{$specname};
148 + print "Checking all pages against $spec\n";
150 + foreach my $nextpage (keys %IkiWiki::pagesources) {
151 + print "Checking $nextpage against $spec\n";
152 + if (pagespec_match($nextpage, $spec, %params) && IkiWiki::PageSpec::match_link($page, $nextpage, %params)) {
153 + return IkiWiki::SuccessReason->new("$page links to page $nextpage matching $link")
157 + return IkiWiki::FailReason->new("$page has no links to any pages that match $spec");
159 + print "Pagespec $specname not found\n";
160 + return IkiWiki::FailReason->new("$page cannot link to nonexistent spec name $specname");
165 if ($link =~ m!^\.! && defined $from) {
171 package IkiWiki::Plugin::definepagespec;
178 hook(type => "getsetup", id => "definepagespec", call => \&getsetup);
179 hook(type => "refresh", id => "definepagespec", call => \&refresh);
180 hook(type => "preprocess", id => "definepagespec", call => \&preprocess);
183 sub getsetup () { #{{{
191 sub refresh () { #{{{
192 # Preprocess the shortcuts page to get all the available shortcuts
193 # defined before other pages are rendered.
194 my $srcfile=srcfile("pagespecs.mdwn", 1);
195 if (! defined $srcfile) {
196 error(gettext("definepagespec plugin will not work without a pagespecs.mdwn"));
198 IkiWiki::preprocess("pagespecs", "pagespecs", readfile($srcfile));
201 sub preprocess (@) { #{{{
204 if (! defined $params{name} || ! defined $params{spec}) {
205 error gettext("missing name or spec parameter");
208 $IkiWiki::named_pagespec{$params{name}} = $params{spec};
210 #translators: This is used to display what shortcuts are defined.
211 #translators: First parameter is the name of the shortcut, the second
212 #translators: is an URL.
213 return sprintf(gettext("pagespec %s refers to <i>%s</i>"), $params{name}, $params{spec});