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 >> I thought about this briefly, and got about that far.. glad you got
13 >> further. :-) --[[Joey]]
15 > Another option would be go with a more functional syntax. The concept here would
16 > be to allow a pagespec to appear in a 'pagespec function' anywhere a page can. e.g.
17 > I could pass a pagespec to `link()` and that would return true if there is a link to any
18 > page matching the pagespec. This makes the variables and existential quantification
19 > implicit. It would allow the example requested above:
21 >> `bugs/* and !*/Discussion and !link(bugs/* and !*/Discussion and !link(done))`
23 > Unfortunately, this is also going to make the pagespec parsing more complex because
24 > we now need to parse nested sets of parentheses to know when the nested pagespec
25 > ends, and that isn't a regular language (we can't use regular expression matching for
28 >> Also, it may cause ambiguities with page names that contain parens
29 >> (though some such ambigutities already exist with the pagespec syntax).
31 > One simplification of that would be to introduce some pagespec [[shortcuts]]. We could
32 > then allow pagespec functions to take either pages, or named pagespec shortcuts. The
33 > pagespec shortcuts would just be listed on a special page, like current [[shortcuts]].
34 > (It would probably be a good idea to require that shortcuts on that page can only refer
35 > to named pagespecs higher up that page than themselves. That would stop some
36 > looping issues...) These shortcuts would be used as follows: when trying to match
37 > a page (without globs) you look to see if the page exists. If it does then you have a
38 > match. If it doesn't, then you look to see if a similarly named pagespec shortcut
39 > exists. If it does, then you check that pagespec recursively to see if you have a match.
40 > The ordering requirement on named pagespecs stops infinite recursion.
42 > Does that seem like a reasonable first approach?
46 >> Having a separate page for the shortcuts feels unwieldly.. perhaps
47 >> instead the shortcut could be defined earlier in the scope of the same
48 >> pagespec that uses it?
50 >> Example: `define(~bugs, bugs/* and !*/Discussion) and define(~openbugs, ~bugs and !link(done)) and ~openbugs and !link(~openbugs)`
52 >>> That could work. parens are only ever nested 1 deep in that grammar so it is regular and the current parsing would be ok.
54 >> Note that I made the "~" explicit, not implicit, so it could be left out. In the case of ambiguity between
55 >> a definition and a page name, the definition would win.
57 >>> That was my initial thought too :), but when implementing it I decided that requiring the ~ made things easier. I'll probably require the ~ for the first pass at least.
59 >> So, equivilant example: `define(bugs, bugs/* and !*/Discussion) and define(openbugs, bugs and !link(done)) and openbugs and !link(openbugs)`
61 >> Re recursion, it is avoided.. but building a pagespec that is O(N^X) where N is the
62 >> number of pages in the wiki is not avoided. Probably need to add DOS prevention.
65 >>> If you memoize the outcomes of the named pagespecs you can make in O(N.X), no?
68 > One quick further thought. All the above discussion assumes that 'dependency' is the
69 > same as 'links to', which is not really true. For example, you'd like to be able to say
70 > "This bug does not depend upon [ [ link to other bug ] ]" and not have a dependency.
71 > Without having different types of links, I don't see how this would be possible.
75 Okie - I've had a quick attempt at this. Initial patch attached. This one doesn't quite work.
76 And there is still a lot of debugging stuff in there.
78 At the moment I've added a new preprocessor plugin, `definepagespec`, which is like
79 shortcut for pagespecs. To reference a named pagespec, use `~` like this:
81 [ [!definepagespec name="bugs" spec="bugs/* and !*/Discussion"]]
82 [ [!definepagespec name="openbugs" spec="~bugs and !link(done)"]]
83 [ [!definepagespec name="readybugs" spec="~openbugs and !link(~openbugs)"]]
85 At the moment the problem is in `match_link()` when we're trying to find a sub-page that
86 matches the appropriate page spec. There is no good list of pages available to iterate over.
88 foreach my $nextpage (keys %IkiWiki::pagesources)
90 does not give me a good list of pages. I found the same thing when I was working on
91 this todo [[todo/Add_a_plugin_to_list_available_pre-processor_commands]].
93 > I'm not sure why iterating over `%pagesources` wouldn't work here, it's the same method
94 > used by anything that needs to match a pagespec against all pages..? --[[Joey]]
96 >> My uchecked hypothesis is that %pagesources is created after the refresh hook.
97 >> I've also been concerned about how globally defined pagespec shortcuts would interact with
98 >> the page dependancy system. Your idea of internally defined shortcuts should fix that. -- [[Will]]
100 Immediately below is a patch for IkiWiki.pm. Below that is a new plugin `definepagespec `
101 which behaves like `shortcut` for pagespecs.
105 diff --git a/IkiWiki.pm b/IkiWiki.pm
106 index e476521..1d2d48c 100644
109 @@ -14,7 +14,7 @@ use open qw{:utf8 :std};
110 use vars qw{%config %links %oldlinks %pagemtime %pagectime %pagecase
111 %pagestate %renderedfiles %oldrenderedfiles %pagesources
112 %destsources %depends %hooks %forcerebuild $gettext_obj
114 + %loaded_plugins %named_pagespec};
116 use Exporter q{import};
117 our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
118 @@ -22,7 +22,7 @@ our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
119 displaytime will_render gettext urlto targetpage
121 %config %links %pagestate %renderedfiles
122 - %pagesources %destsources);
123 + %pagesources %destsources %named_pagespec);
124 our $VERSION = 2.00; # plugin interface version, next is ikiwiki version
125 our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE
126 my $installdir=''; # INSTALLDIR_AUTOREPLACE done by Makefile, DNE
127 @@ -1271,7 +1271,7 @@ sub loadindex () { #{{{
128 %oldrenderedfiles=%pagectime=();
129 if (! $config{rebuild}) {
130 %pagesources=%pagemtime=%oldlinks=%links=%depends=
131 - %destsources=%renderedfiles=%pagecase=%pagestate=();
132 + %destsources=%renderedfiles=%pagecase=%pagestate=%named_pagespec=();
135 if (! open ($in, "<", "$config{wikistatedir}/indexdb")) {
136 @@ -1729,6 +1729,8 @@ sub match_glob ($$;@) { #{{{
138 my $from=exists $params{location} ? $params{location} : '';
140 + print "Matching glob $glob \n";
143 if ($glob =~ m!^\./!) {
145 @@ -1736,6 +1738,18 @@ sub match_glob ($$;@) { #{{{
146 $glob="$from/$glob" if length $from;
149 + if (substr($glob, 0, 1) eq '~') {
150 + my $specname = substr($glob, 1);
151 + print "Checking for pagespec named $specname \n";
152 + if (exists $IkiWiki::named_pagespec{$specname}) {
153 + my $spec = $IkiWiki::named_pagespec{$specname};
154 + return IkiWiki::pagespec_match($page, $spec, %params);
156 + print "Couldn't find pagespec\n";
157 + return IkiWiki::FailReason->new("Page spec $specname referenced on page $page does not exist");
161 my $regexp=IkiWiki::glob2re($glob);
162 if ($page=~/^$regexp$/i) {
163 if (! IkiWiki::isinternal($page) || $params{internal}) {
164 @@ -1756,11 +1770,36 @@ sub match_internal ($$;@) { #{{{
166 sub match_link ($$;@) { #{{{
168 - my $link=lc(shift);
169 + my $fulllink=shift;
170 + my $link=lc($fulllink);
173 + print "Matching link $fulllink \n";
175 my $from=exists $params{location} ? $params{location} : '';
177 + if (substr($fulllink, 0, 1) eq '~') {
178 + my $specname = substr($fulllink, 1);
179 + print "Checking link pagespec $specname \n";
180 + if (exists $IkiWiki::named_pagespec{$specname}) {
181 + my $spec = $IkiWiki::named_pagespec{$specname};
183 + print "Checking all pages against $spec\n";
185 + foreach my $nextpage (keys %IkiWiki::pagesources) {
186 + print "Checking $nextpage against $spec\n";
187 + if (pagespec_match($nextpage, $spec, %params) && IkiWiki::PageSpec::match_link($page, $nextpage, %params)) {
188 + return IkiWiki::SuccessReason->new("$page links to page $nextpage matching $link")
192 + return IkiWiki::FailReason->new("$page has no links to any pages that match $spec");
194 + print "Pagespec $specname not found\n";
195 + return IkiWiki::FailReason->new("$page cannot link to nonexistent spec name $specname");
200 if ($link =~ m!^\.! && defined $from) {
206 package IkiWiki::Plugin::definepagespec;
213 hook(type => "getsetup", id => "definepagespec", call => \&getsetup);
214 hook(type => "refresh", id => "definepagespec", call => \&refresh);
215 hook(type => "preprocess", id => "definepagespec", call => \&preprocess);
218 sub getsetup () { #{{{
226 sub refresh () { #{{{
227 # Preprocess the shortcuts page to get all the available shortcuts
228 # defined before other pages are rendered.
229 my $srcfile=srcfile("pagespecs.mdwn", 1);
230 if (! defined $srcfile) {
231 error(gettext("definepagespec plugin will not work without a pagespecs.mdwn"));
233 IkiWiki::preprocess("pagespecs", "pagespecs", readfile($srcfile));
236 sub preprocess (@) { #{{{
239 if (! defined $params{name} || ! defined $params{spec}) {
240 error gettext("missing name or spec parameter");
243 $IkiWiki::named_pagespec{$params{name}} = $params{spec};
245 #translators: This is used to display what shortcuts are defined.
246 #translators: First parameter is the name of the shortcut, the second
247 #translators: is an URL.
248 return sprintf(gettext("pagespec %s refers to <i>%s</i>"), $params{name}, $params{spec});