answer about autofiles for tags
[ikiwiki] / doc / todo / matching_different_kinds_of_links.mdwn
1 [[!tag wishlist]]
2
3 As noted in [[todo/tag_pagespec_function]], there is a "misbehavior" of a `tagged()` pagespec: it matches even pages which have plain links to the tag page.
4
5 And in general, it would be quite useful to be able to distinguish different kinds of links: one more kind, in addition to "tag", is "bug dependency" noted in [[todo/structured_page_data#another_kind_of_links]] and [[todo/tracking_bugs_with_dependencies#another_kind_of_links]].
6
7 It could distinguish the links by the `rel=` attribute. ([[Tags already receive a special rel-class|todo/rel_attribute_for_links]].) This means there is a general need for a syntax to specify user-defined rel-classes on wikilink (then bug deps would simply use their special rel-class, either directly, or through a special directive like `\[[!depends ]]`), and to refer to them in pagespecs (in forward and backward direction).
8
9 Besides pagespecs, the `rel=` attribute could be used for styles. --Ivan Z.
10
11 > FWIW, the `add_link` function introduced in a recent
12 > release adds an abstraction that could be used to get
13 > part of the way there to storing data about different types of
14 > links. That function could easily be extended to take an optional
15 > third parameter specifying the link type.
16
17 > Then there's the question of how to store and access the data. `%links`
18 > does not offer a good way to add additional information about links.
19 > Now, we could toss `%links` entirely and switch to an accessor function,
20 > but let's think about not doing that..
21
22 > The data that seems to be needed is basically a deep hash, so
23 > one could check `$linktype{$page}{tag}{$link}` to see if
24 > the page contains a link of the given type. (Note that pages could
25 > contain links that were duplicates except for their types.)
26
27 > There would be some data duplication, unfortuantly, but if `%linktype`
28 > is not populated for regular wikilinks, it would at least be limited to
29 > tags and other unusual link types, so not too bad.
30
31 > `%linktype` could be stored in `%pagestate`.. if so
32 > the actual use might look like `$pagestate{$page}{linktype}{tag}{$link}`.
33 > That could be implemented by the tag plugin right now
34 > with no core changes. (BTW, then I originally wrote tag, pagestate
35 > was not available, which is why I didn't make it differentiate from
36 > normal links.) Might be better to go ahead and add the variable to
37 > core though. --[[Joey]] 
38
39 >> I've implemented this with the data structure you suggested, except that
40 >> I called it `%typedlinks` instead of `%linktype` (it seemed to make more
41 >> sense that way). I also ported `tag` to it, and added a `tagged_is_strict`
42 >> config option. See below! --[[smcv]]
43
44 I saw somewhere else here some suggestions for the wiki-syntax for specifying the relation name of a link. One more suggestion---[the syntax used in Semantic MediaWiki](http://en.wikipedia.org/wiki/Semantic_MediaWiki#Basic_usage), like this:
45
46 <pre>
47 ... the capital city is \[[Has capital::Berlin]] ...
48 </pre>
49
50 So a part of the effect of [[`\[[!taglink TAG\]\]`|plugins/tag]] could be represented as something like `\[[tag::TAG]]` or (more understandable relation name in what concerns the direction) `\[[tagged::TAG]]`.
51
52 I don't have any opinion on this syntax (whether it's good or not)...--Ivan Z.
53
54 -------
55
56 >> [[!template id=gitbranch author="[[Simon_McVittie|smcv]]" branch=smcv/link-types]]
57 >> [[!tag patch]]
58
59 ## Documentation for smcv's branch
60
61 ### added to [[ikiwiki/pagespec]]
62
63 * "`typedlink(type glob)`" - matches pages that link to a given page (or glob)
64   with a given link type. Plugins can create links with a specific type:
65   for instance, the tag plugin creates links of type `tag`.
66
67 ### added to [[plugins/tag]]
68
69 If the `tagged_is_strict` config option is set, `tagged()` will only match
70 tags explicitly set with [[ikiwiki/directive/tag]] or
71 [[ikiwiki/directive/taglink]]; if not (the default), it will also match
72 any other [[WikiLinks|ikiwiki/WikiLink]] to the tag page.
73
74 ### added to [[plugins/write]]
75
76 #### `%typedlinks`
77
78 The `%typedlinks` hash records links of specific types. Do not modify this
79 hash directly; call `add_link()`. The keys are page names, and the values
80 are hash references. In each page's hash reference, the keys are link types
81 defined by plugins, and the values are hash references with link targets
82 as keys, and 1 as a dummy value, something like this:
83
84         $typedlinks{"foo"} = {
85                 tag => { short_word => 1, metasyntactic_variable => 1 },
86                 next_page => { bar => 1 },
87         };
88
89 Ordinary [[WikiLinks|ikiwiki/WikiLink]] appear in `%links`, but not in
90 `%typedlinks`.
91
92 #### `add_link($$;$)`
93  
94  This adds a link to `%links`, ensuring that duplicate links are not
95  added. Pass it the page that contains the link, and the link text.
96  
97 An optional third parameter sets the link type (`undef` produces an ordinary
98 [[ikiwiki/WikiLink]]).
99
100 ## Review
101
102 Some code refers to `oldtypedlinks`, and other to `oldlinktypes`. --[[Joey]]
103
104 > Oops, I'll fix that. That must mean missing test coverage, too :-(
105 > --s
106
107 >> A test suite for the dependency resolver *would* be nice. --[[Joey]]
108
109 I'm curious what your reasoning was for adding a new variable
110 rather than using `pagestate`. Was it only because you needed
111 the `old` version to detect change, or was there other complexity?
112 --J
113
114 > You seemed to be more in favour of adding it to the core in
115 > your proposal above, so I assumed that'd be more likely to be
116 > accepted :-) I don't mind one way or the other - `%typedlinks`
117 > costs one core variable, but saves one level of hash nesting. If
118 > you're not sure either, then I think the decision should come down
119 > to which one is easier to document clearly - I'm still unhappy with
120 > my docs for `%typedlinks`, so I'll try to write docs for it as
121 > `pagestate` and see if they work any better. --s
122
123 I have not convinced myself this is a real problem, but..
124 If a page has a typed link, there seems to be no way to tell
125 if it also has a separate, regular link. `add_link` will add
126 to `@links` when adding a typed, or untyped link. If only untyped
127 links were recorded there, one could tell the difference. But then
128 typed links would not show up at all in eg, a linkmap,
129 unless it was changed to check for typed links too.
130 (Or, regular links could be recorded in typedlinks too,
131 with a empty type. (Bloaty.)) --J
132
133 > I think I like the semantics as-is - I can't think of any
134 > reason why you'd want to ask the question "does A link to B,
135 > not counting tags and other typed links?". A typed link is
136 > still a link, in my mind at least. --s
137
138 >> Me neither, let's not worry about it. --[[Joey]] 
139
140 I suspect we could get away without having `tagged_is_strict`
141 without too much transitional trouble. --[[Joey]]
142
143 > If you think so, I can delete about 5 LoC. I don't particularly
144 > care either way; [[Jon]] expressed concern about people relying
145 > on the current semantics, on one of the pages requesting this
146 > change. --s
147
148 I might have been wrong to introduce `typedlink(tag foo)`. It's not
149 very user-friendly, and is more useful as a backend for other plugins
150 that as a feature in its own right - any plugin introducing a link
151 type will probably also want to have its own preprocessor directive
152 to set that link type, and its own pagespec function to match it.
153 I wonder whether to make a `typedlink` plugin that has the typedlink
154 pagespec match function and a new `\[[!typedlink to="foo" type="bar"]]`
155 though... --[[smcv]]
156
157 > I agree, per-type matchers are more friendly and I'm not enamored of the
158 > multi-parameter pagespec syntax. --[[Joey]]