1 [[!meta title="Option disp for pagestats directive"]]
3 [[!toggle id=old text="Old, outdated, monologue"]]
5 [[!toggleable id=old text="""
7 here is a proposal to add a new option to [[ikiwiki/directive]]
8 [[ikiwiki/directive/pagestats]] (from plugin [[plugins/pagestats]]).
10 This adds global option `pagestats_linktext` (and directive option `linktext`) to specify whether directive `pagestats` should use the page name or the [[title|ikiwiki/directive/meta]] of tags.
12 Here is a [[patch]], for both code and documentation.
14 diff --git a/IkiWiki/Plugin/pagestats.pm b/IkiWiki/Plugin/pagestats.pm
15 index 17b26f7..a65fd7a 100644
16 --- a/IkiWiki/Plugin/pagestats.pm
17 +++ b/IkiWiki/Plugin/pagestats.pm
18 @@ -29,11 +29,31 @@ sub getsetup () {
22 + pagestats_linktext => {
25 + description => "Set link text to be whether page title (page) or meta title (title).",
32 + # Return the text of the link to a tag, depending on option linktext.
35 + my $linktype = $_[1];
36 + if (($linktype eq "title") and (exists $pagestate{$page}{meta}{title})) {
37 + return $pagestate{$page}{meta}{title};
45 $params{pages}="*" unless defined $params{pages};
46 + $params{linktext} = $config{pagestats_linktext} unless defined $params{linktext};
47 my $style = ($params{style} or 'cloud');
50 @@ -78,7 +98,7 @@ sub preprocess (@) {
51 return "<table class='".(exists $params{class} ? $params{class} : "pageStats")."'>\n".
54 - htmllink($params{page}, $params{destpage}, $_, noimageinline => 1).
55 + htmllink($params{page}, $params{destpage}, $_, noimageinline => 1, linktext => linktext($_, $params{linktext})).
56 "</td><td>".$counts{$_}."</td></tr>"
58 sort { $counts{$b} <=> $counts{$a} } keys %counts).
59 @@ -101,8 +121,8 @@ sub preprocess (@) {
61 $res.="<li>" if $style eq 'list';
62 $res .= "<span class=\"$class\">".
63 - htmllink($params{page}, $params{destpage}, $page).
65 + htmllink($params{page}, $params{destpage}, $page, linktext => linktext($page, $params{linktext})).
67 $res.="</li>" if $style eq 'list';
70 diff --git a/doc/ikiwiki/directive/pagestats.mdwn b/doc/ikiwiki/directive/pagestats.mdwn
71 index 8d904f5..56970e6 100644
72 --- a/doc/ikiwiki/directive/pagestats.mdwn
73 +++ b/doc/ikiwiki/directive/pagestats.mdwn
74 @@ -37,4 +37,6 @@ links:
75 The optional `class` parameter can be used to control the class
76 of the generated tag cloud `div` or page stats `table`.
78 +The optional `linktext` parameter can be used to control the text that is displayed for each tag. It can be `page` (the name of the page is used) or `title` (the title, according to the [[ikiwiki/directive/meta]] [[ikiwiki/directive]], is used). This option can be set globally in the setup using option `pagestats_linktext`; default is `page`.
80 [[!meta robots="noindex, follow"]]
81 diff --git a/doc/plugins/pagestats.mdwn b/doc/plugins/pagestats.mdwn
82 index 347e39a..6a72a9a 100644
83 --- a/doc/plugins/pagestats.mdwn
84 +++ b/doc/plugins/pagestats.mdwn
86 This plugin provides the [[ikiwiki/directive/pagestats]]
87 [[ikiwiki/directive]], which can generate stats about how pages link to
88 each other, or display a tag cloud.
90 +Their is one global option for the setup file:
92 +* `pagestats_linktext` controls the text that is displayed for each tag. If `page` (the default), the name of the page is used; if `title`, its title (according to the [[ikiwiki/directive/meta]] [[ikiwiki/directive]]) is used.
97 > do not accept my patch: it is an ugly hack that works for me, but its too narrow to be merged in IkiWiki:
99 > - it assumes the [[ikiwiki/directive/pagestats]] directive only deals with tags, which is wrong;
100 > - such a feature (allowing displaying tags using their title), if enabled, should be enabled for the [[plugins/tag]] plugin (and maybe other plugins [[I have in mind|users/spalax]]) as well.
102 > I cannot manage to find a solution to my problem that suits me.
106 > On two sites I maintain using IkiWiki, I have tags that:
108 > - have special characters in it (like [[ยท|http://en.wikipedia.org/wiki/Interpunct]]) that generate ugly URLs;
109 > - have subtags (e.g. `math/calculus`, `math/algebra`, `physics/mechanic` etc.).
111 > That is, having [[ikiwiki/directive/taglink]] or [[ikiwiki/directive/pagestats]] displaying tags using the pagename (that is something derived from the basename of the URL) is not sufficient for me. I would like to be able to display them using their title, their full name (from the `tagbase` parameter), or both.
115 > A solution would be to provide a `tagtext` config option, set to one of `page` (use pagename), `title` (use [[ikiwiki/directive/meta]] title), `path` (use path, since the tagbase), `pathtitle` (use path, and use title for each of the subtags); or a boolean `display_tagtitle` and `display_tagpath`, which would handle the way tags are displayed.
117 > I see at least two drawbacks to this solution:
119 > - I do not know what would be the default of these options, not to break backward compatibility: [[ikiwiki/directive/taglink]] would suggest `page`, whereas the footer would suggest `path`.
120 > - The [[ikiwiki/directive/pagestats]] directive would need an optional boolean parameter `tag`, to specify whether to use these options or not.
124 > I actually wonder if someone else also have this problem: as far as I can see on other sites using IkiWiki and tags, I would not be surprised if others are satisfyed with the current way tags are displayed: I do not remember having seen subtags, or tags in non-English language with weird characters in them.
126 > So, I wonder whether this discussion would benefit IkiWiki, or if I should just go on with my hack (or maybe a plugin, but I think it would be quite difficult to do, given that the very same function is used to display tags and to uniquely identify them).
128 > -- [[Louis|spalax]]
131 I eventually managed to get something that suits me, for the problem described above (I want [[ikiwiki/directive/pagestats]] directive to display [[title|ikiwiki/directive/meta]] rather than page name).
133 Here is a [[patch]] that adds an option `disp` for the [[ikiwiki/directive/pagestats]], acting exactly the same as option `show` for the [[ikiwiki/directive/map]] directive (but parameter `show` was already used for something else). That is, if one wants its tags displayed using their [[title|ikiwiki/directive/meta]] rather than their page name, she can use param `disp`, is in:
135 \[[!pagestats pages="tags/*" disp=title]]
137 [[!toggle id=patch text="Patch"]]
138 [[!toggleable id=patch text="""
139 diff --git a/IkiWiki/Plugin/pagestats.pm b/IkiWiki/Plugin/pagestats.pm
140 index 17b26f7..8a5e100 100644
141 --- a/IkiWiki/Plugin/pagestats.pm
142 +++ b/IkiWiki/Plugin/pagestats.pm
143 @@ -31,6 +31,19 @@ sub getsetup () {
148 + # Return the text of the link to a tag, depending on option linktext.
149 + my ($page, %params) = @_;
150 + if (exists $params{disp} &&
151 + exists $pagestate{$page} &&
152 + exists $pagestate{$page}{meta}{$params{disp}}) {
153 + return $pagestate{$page}{meta}{$params{disp}};
162 $params{pages}="*" unless defined $params{pages};
163 @@ -78,7 +91,7 @@ sub preprocess (@) {
164 return "<table class='".(exists $params{class} ? $params{class} : "pageStats")."'>\n".
167 - htmllink($params{page}, $params{destpage}, $_, noimageinline => 1).
168 + htmllink($params{page}, $params{destpage}, $_, noimageinline => 1, linktext => linktext($_, %params)).
169 "</td><td>".$counts{$_}."</td></tr>"
171 sort { $counts{$b} <=> $counts{$a} } keys %counts).
172 @@ -101,7 +114,7 @@ sub preprocess (@) {
174 $res.="<li>" if $style eq 'list';
175 $res .= "<span class=\"$class\">".
176 - htmllink($params{page}, $params{destpage}, $page).
177 + htmllink($params{page}, $params{destpage}, $page, linktext => linktext($page, %params)).
179 $res.="</li>" if $style eq 'list';
186 > Saved to my git repository as `contrib/spalax/pagestats-disp`.
187 > I'd rather find a better name than `disp` for the parameter.
188 > I think `display` would be an improvement, but that doesn't solve the
189 > problem of "it's a synonym for show, and non-obvious which is which".
192 > It's unfortunate that `map` and `pagestats` have different meanings for
193 > the `show` parameter. I'm tempted to propose a patch that adds something
194 > like `limit` (by analogy with SQL) or `max` as the canonical name for the
195 > "number of things to match" parameter, at which point a non-numeric
196 > `show` could mean this thing. --[[smcv]]
198 >> [[!template id=gitbranch branch=smcv/pagestats-show
199 author="[[Louis|spalax]], [[smcv]]"
200 browse=http://git.pseudorandom.co.uk/smcv/ikiwiki.git/shortlog/refs/heads/pagestats-show]]
201 >> Here's a branch. It depends on my `ready/limit` branch
202 >> from [[todo/pick a new canonical name for equivalent of SQL limit]].
205 >>> [[Merged|done]] --[[smcv]]