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 >>>> Yeah, guess that'd work. :-)
70 > One quick further thought. All the above discussion assumes that 'dependency' is the
71 > same as 'links to', which is not really true. For example, you'd like to be able to say
72 > "This bug does not depend upon [ [ link to other bug ] ]" and not have a dependency.
73 > Without having different types of links, I don't see how this would be possible.
77 Okie - I've had a quick attempt at this. Initial patch attached. This one doesn't quite work.
78 And there is still a lot of debugging stuff in there.
80 At the moment I've added a new preprocessor plugin, `definepagespec`, which is like
81 shortcut for pagespecs. To reference a named pagespec, use `~` like this:
83 [ [!definepagespec name="bugs" spec="bugs/* and !*/Discussion"]]
84 [ [!definepagespec name="openbugs" spec="~bugs and !link(done)"]]
85 [ [!definepagespec name="readybugs" spec="~openbugs and !link(~openbugs)"]]
87 At the moment the problem is in `match_link()` when we're trying to find a sub-page that
88 matches the appropriate page spec. There is no good list of pages available to iterate over.
90 foreach my $nextpage (keys %IkiWiki::pagesources)
92 does not give me a good list of pages. I found the same thing when I was working on
93 this todo [[todo/Add_a_plugin_to_list_available_pre-processor_commands]].
95 > I'm not sure why iterating over `%pagesources` wouldn't work here, it's the same method
96 > used by anything that needs to match a pagespec against all pages..? --[[Joey]]
98 >> My uchecked hypothesis is that %pagesources is created after the refresh hook.
99 >> I've also been concerned about how globally defined pagespec shortcuts would interact with
100 >> the page dependancy system. Your idea of internally defined shortcuts should fix that. -- [[Will]]
102 >>> You're correct, the refresh hook is run very early, before pagesources
103 >>> is populated. (It will be partially populated on a refresh, but will
104 >>> not be updated to reflect new pages.) Agree that internally defined
105 >>> seems the way to go. --[[Joey]]
107 Immediately below is a patch for IkiWiki.pm. Below that is a new plugin `definepagespec `
108 which behaves like `shortcut` for pagespecs.
112 diff --git a/IkiWiki.pm b/IkiWiki.pm
113 index e476521..1d2d48c 100644
116 @@ -14,7 +14,7 @@ use open qw{:utf8 :std};
117 use vars qw{%config %links %oldlinks %pagemtime %pagectime %pagecase
118 %pagestate %renderedfiles %oldrenderedfiles %pagesources
119 %destsources %depends %hooks %forcerebuild $gettext_obj
121 + %loaded_plugins %named_pagespec};
123 use Exporter q{import};
124 our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
125 @@ -22,7 +22,7 @@ our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
126 displaytime will_render gettext urlto targetpage
128 %config %links %pagestate %renderedfiles
129 - %pagesources %destsources);
130 + %pagesources %destsources %named_pagespec);
131 our $VERSION = 2.00; # plugin interface version, next is ikiwiki version
132 our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE
133 my $installdir=''; # INSTALLDIR_AUTOREPLACE done by Makefile, DNE
134 @@ -1271,7 +1271,7 @@ sub loadindex () { #{{{
135 %oldrenderedfiles=%pagectime=();
136 if (! $config{rebuild}) {
137 %pagesources=%pagemtime=%oldlinks=%links=%depends=
138 - %destsources=%renderedfiles=%pagecase=%pagestate=();
139 + %destsources=%renderedfiles=%pagecase=%pagestate=%named_pagespec=();
142 if (! open ($in, "<", "$config{wikistatedir}/indexdb")) {
143 @@ -1729,6 +1729,8 @@ sub match_glob ($$;@) { #{{{
145 my $from=exists $params{location} ? $params{location} : '';
147 + print "Matching glob $glob \n";
150 if ($glob =~ m!^\./!) {
152 @@ -1736,6 +1738,18 @@ sub match_glob ($$;@) { #{{{
153 $glob="$from/$glob" if length $from;
156 + if (substr($glob, 0, 1) eq '~') {
157 + my $specname = substr($glob, 1);
158 + print "Checking for pagespec named $specname \n";
159 + if (exists $IkiWiki::named_pagespec{$specname}) {
160 + my $spec = $IkiWiki::named_pagespec{$specname};
161 + return IkiWiki::pagespec_match($page, $spec, %params);
163 + print "Couldn't find pagespec\n";
164 + return IkiWiki::FailReason->new("Page spec $specname referenced on page $page does not exist");
168 my $regexp=IkiWiki::glob2re($glob);
169 if ($page=~/^$regexp$/i) {
170 if (! IkiWiki::isinternal($page) || $params{internal}) {
171 @@ -1756,11 +1770,36 @@ sub match_internal ($$;@) { #{{{
173 sub match_link ($$;@) { #{{{
175 - my $link=lc(shift);
176 + my $fulllink=shift;
177 + my $link=lc($fulllink);
180 + print "Matching link $fulllink \n";
182 my $from=exists $params{location} ? $params{location} : '';
184 + if (substr($fulllink, 0, 1) eq '~') {
185 + my $specname = substr($fulllink, 1);
186 + print "Checking link pagespec $specname \n";
187 + if (exists $IkiWiki::named_pagespec{$specname}) {
188 + my $spec = $IkiWiki::named_pagespec{$specname};
190 + print "Checking all pages against $spec\n";
192 + foreach my $nextpage (keys %IkiWiki::pagesources) {
193 + print "Checking $nextpage against $spec\n";
194 + if (pagespec_match($nextpage, $spec, %params) && IkiWiki::PageSpec::match_link($page, $nextpage, %params)) {
195 + return IkiWiki::SuccessReason->new("$page links to page $nextpage matching $link")
199 + return IkiWiki::FailReason->new("$page has no links to any pages that match $spec");
201 + print "Pagespec $specname not found\n";
202 + return IkiWiki::FailReason->new("$page cannot link to nonexistent spec name $specname");
207 if ($link =~ m!^\.! && defined $from) {
213 package IkiWiki::Plugin::definepagespec;
220 hook(type => "getsetup", id => "definepagespec", call => \&getsetup);
221 hook(type => "refresh", id => "definepagespec", call => \&refresh);
222 hook(type => "preprocess", id => "definepagespec", call => \&preprocess);
225 sub getsetup () { #{{{
233 sub refresh () { #{{{
234 # Preprocess the shortcuts page to get all the available shortcuts
235 # defined before other pages are rendered.
236 my $srcfile=srcfile("pagespecs.mdwn", 1);
237 if (! defined $srcfile) {
238 error(gettext("definepagespec plugin will not work without a pagespecs.mdwn"));
240 IkiWiki::preprocess("pagespecs", "pagespecs", readfile($srcfile));
243 sub preprocess (@) { #{{{
246 if (! defined $params{name} || ! defined $params{spec}) {
247 error gettext("missing name or spec parameter");
250 $IkiWiki::named_pagespec{$params{name}} = $params{spec};
252 #translators: This is used to display what shortcuts are defined.
253 #translators: First parameter is the name of the shortcut, the second
254 #translators: is an URL.
255 return sprintf(gettext("pagespec %s refers to <i>%s</i>"), $params{name}, $params{spec});