1 [[!template id=plugin name=comments author="[[Simon_McVittie|smcv]]"]]
4 This plugin adds "blog-style" comments. The intention is that on a non-wiki site
5 (like a blog) you can lock all pages for admin-only access, then allow otherwise
6 unprivileged (or perhaps even anonymous) users to comment on posts.
8 Comments are saved as internal pages, so they can never be edited through the CGI,
9 only by direct committers. Currently, comments are always in [[ikiwiki/markdown]].
11 > So, why do it this way, instead of using regular wiki pages in a
12 > namespace, such as `$page/comments/*`? Then you could use [[plugins/lockedit]] to
13 > limit editing of comments in more powerful ways. --[[Joey]]
15 >> Er... I suppose so. I'd assumed that these pages ought to only exist as inlines
16 >> rather than as individual pages (same reasoning as aggregated posts), though.
18 >> lockedit is actually somewhat insufficient, since `check_canedit()`
19 >> doesn't distinguish between creation and editing; I'd have to continue to use
20 >> some sort of odd hack to allow creation but not editing.
22 >> I also can't think of any circumstance where you'd want a user other than
23 >> admins (~= git committers) and possibly the commenter (who we can't check for
24 >> at the moment anyway, I don't think?) to be able to edit comments - I think
25 >> user expectations for something that looks like ordinary blog comments are
26 >> likely to include "others can't put words into my mouth".
28 >> My other objection to using a namespace is that I'm not particularly happy about
29 >> plugins consuming arbitrary pieces of the wiki namespace - /discussion is bad
30 >> enough already. Indeed, this very page would accidentally get matched by rules
31 >> aiming to control comment-posting... :-) --[[smcv]]
33 >> Thinking about it, perhaps one way to address this would be to have the suffix
34 >> (e.g. whether commenting on Sandbox creates sandbox/comment1 or sandbox/c1 or
35 >> what) be configurable by the wiki admin, in the same way that recentchanges has
36 >> recentchangespage => 'recentchanges'? I'd like to see fewer hard-coded page
37 >> names in general, really - it seems odd to me that shortcuts and smileys
38 >> hard-code the name of the page to look at. Perhaps I could add
39 >> discussionpage => 'discussion' too? --[[smcv]]
41 >> (I've now implemented this in my branch. --[[smcv]])
43 >> The best reason to keep the pages internal seems to me to be that you
44 >> don't want the overhead of every comment spawning its own wiki page.
45 >> The worst problem with it though is that you have to assume the pages
46 >> are mdwn (or `default_pageext`) and not support other formats. --[[Joey]]
48 >> Well, you could always have `comment1._mdwn`, `comment2._creole` etc. and
49 >> alter the htmlize logic so that the `mdwn` hook is called for both `mdwn`
50 >> and `_mdwn` (assuming this is not already the case). I'm not convinced
51 >> that multi-format comments are a killer feature, though - part of the point
52 >> of this plugin, in my mind, is that it's less flexible than the full power
53 >> of ikiwiki and gives users fewer options. This could be construed
54 >> to be a feature, for people who don't care how flexible the technology is
55 >> and just want a simple way to leave a comment. The FormattingHelp page
56 >> assumes you're writing 100% Markdown in any case...
58 >> Internal pages do too many things, perhaps: they suppress generation of
59 >> HTML pages, they disable editing over the web, and they have a different
60 >> namespace of htmlize hooks. I think the first two of those are useful
61 >> for this plugin, and the last is harmless; you seem to think the first
62 >> is useful, and the other two are harmful. --[[smcv]]
64 >> By the way, I think that who can post comments should be controllable by
65 >> the existing plugins opendiscussion, anonok, signinedit, and lockedit. Allowing
66 >> posting comments w/o any login, while a nice capability, can lead to
67 >> spam problems. So, use `check_canedit` as at least a first-level check?
70 >> This plugin already uses `check_canedit`, but that function doesn't have a concept
71 >> of different actions. The hack I use is that when a user comments on, say, sandbox,
72 >> I call `check_canedit` for the pseudo-page "sandbox[postcomment]". The
73 >> special `postcomment(glob)` [[ikiwiki/pagespec]] returns true if the page ends with
74 >> "[postcomment]" and the part before (e.g. sandbox) matches the glob. So, you can
75 >> have postcomment(blog/*) or something. (Perhaps instead of taking a glob, postcomment
76 >> should take a pagespec, so you can have postcomment(link(tags/commentable))?)
78 >> This is why `anonok_pages => 'postcomment(*)'` and `locked_pages => '!postcomment(*)'`
79 >> are necessary to allow anonymous and logged-in editing (respectively).
81 >> This is ugly - one alternative would be to add `check_permission()` that takes a
82 >> page and a verb (create, edit, rename, remove and maybe comment are the ones I
83 >> can think of so far), use that, and port the plugins you mentioned to use that
84 >> API too. This plugin could either call `check_can("$page/comment1", 'create')` or
85 >> call `check_can($page, 'comment')`.
87 >> One odd effect of the code structure I've used is that we check for the ability to
88 >> create the page before we actually know what page name we're going to use - when
89 >> posting the comment I just increment a number until I reach an unused one - so
90 >> either the code needs restructuring, or the permission check for 'create' would
91 >> always be for 'comment1' and never 'comment123'. --[[smcv]]
93 >> Another possibility is to just check for permission to edit (e.g.) `sandbox/comment1`.
94 >> However, this makes the "comments can only be created, not edited" feature completely
95 >> reliant on the fact that internal pages can't be edited. Perhaps there should be a
96 >> `editable_pages` pagespec, defaulting to `'*'`?
98 When using this plugin, you should also enable [[htmlscrubber]] and either [[htmltidy]]
99 or [[htmlbalance]]. Directives are filtered out by default, to avoid commenters slowing
100 down the wiki by causing time-consuming processing. As long as the recommended plugins
101 are enabled, comment authorship should hopefully be unforgeable by CGI users.
103 > I'm not sure that raw html should be a problem, as long as the
104 > htmlsanitizer and htmlbalanced plugins are enabled. I can see filtering
105 > out directives, as a special case. --[[Joey]]
107 >> Right, if I sanitize each post individually, with htmlscrubber and either htmltidy
108 >> or htmlbalance turned on, then there should be no way the user can forge a comment;
109 >> I was initially wary of allowing meta directives, but I think those are OK, as long
110 >> as the comment template puts the \[[!meta author]] at the *end*. Disallowing
111 >> directives is more a way to avoid commenters causing expensive processing than
112 >> anything else, at this point.
114 >> I've rebased the plugin on master, made it sanitize individual posts' content
115 >> and removed the option to disallow raw HTML. Sanitizing individual posts before
116 >> they've been htmlized required me to preserve whitespace in the htmlbalance
117 >> plugin, so I did that. Alternatively, we could htmlize immediately and always
118 >> save out raw HTML? --[[smcv]]
120 >> There might be some use cases for other directives, such as img, in
123 >> I don't know if meta is "safe" (ie, guaranteed to be inexpensive and not
124 >> allow users to do annoying things) or if it will continue to be in the
125 >> future. Hard to predict really, all that can be said with certainty is
126 >> all directives will contine to be inexpensive and safe enough that it's
127 >> sensible to allow users to (ab)use them on open wikis.
130 When comments have been enabled generally, you still need to mark which pages
131 can have comments, by including the `\[[!comments]]` directive in them. By default,
132 this directive expands to a "post a comment" link plus an `\[[!inline]]` with
133 the comments. [This requirement has now been removed --[[smcv]]]
135 > I don't like this, because it's hard to explain to someone why they have
136 > to insert this into every post to their blog. Seems that the model used
137 > for discussion pages could work -- if comments are enabled, automatically
138 > add the comment posting form and comments to the end of each page.
141 >> I don't think I'd want comments on *every* page (particularly, not the
142 >> front page). Perhaps a pagespec in the setup file, where the default is "*"?
143 >> Then control freaks like me could use "link(tags/comments)" and tag pages
144 >> as allowing comments.
146 >>> Yes, I think a pagespec is the way to go. --[[Joey]]
148 >>> Implemented --[[smcv]]
151 >> The model used for discussion pages does require patching the existing
152 >> page template, which I was trying to avoid - I'm not convinced that having
153 >> every possible feature hard-coded there really scales (and obviously it's
154 >> rather annoying while this plugin is on a branch). --[[smcv]]
156 >>> Using the template would allow customising the html around the comments
157 >>> which seems like a good thing? --[[Joey]]
159 >>> The \[[!comments]] directive is already template-friendly - it expands to
160 >>> the contents of the template `comments_embed.tmpl`, possibly with the
161 >>> result of an \[[!inline]] appended. I should change `comments_embed.tmpl`
162 >>> so it uses a template variable `INLINE` for the inline result rather than
163 >>> having the perl code concatenate it, which would allow a bit more
164 >>> customization (whether the "post" link was before or after the inline).
165 >>> Even if you want comments in page.tmpl, keeping the separate comments_embed.tmpl
166 >>> and having a `COMMENTS` variable in page.tmpl might be the way forward,
167 >>> since the smaller each templates is, the easier it will be for users
168 >>> to maintain a patched set of templates. (I think so, anyway, based on what happens
169 >>> with dpkg prompts in Debian packages with monolithic vs split
170 >>> conffiles.) --[[smcv]]
172 >>> I've switched my branch to use page.tmpl instead; see what you think? --[[smcv]]
174 The plugin adds a new [[ikiwiki/PageSpec]] match type, `postcomment`, for use
175 with `anonok_pagespec` from the [[plugins/anonok]] plugin or `locked_pages` from
176 the [[plugins/lockedit]] plugin. Typical usage would be something like:
178 locked_pages => "!postcomment(*)"
180 to allow non-admin users to comment on pages, but not edit anything. You can also do
182 anonok_pages => "postcomment(*)"
184 to allow anonymous comments (the IP address will be used as the "author").
186 > This is still called postcomment, although I've renamed the rest of the plugin
187 > to comments as suggested on #ikiwiki --[[smcv]]
189 There are some global options for the setup file:
191 * comments_shown_pagespec: pages where comments will be displayed inline, e.g. `blog/*`
193 * comments_open_pagespec: pages where new comments can be posted, e.g.
194 `blog/* and created_after(close_old_comments)` or `*/discussion`
195 * comments_pagename: if this is e.g. `comment_` (the default), then comments on the
196 [[sandbox]] will be called something like `sandbox/comment_12`
197 * comments_allowdirectives: if true (default false), comments may contain IkiWiki
199 * comments_commit: if true (default true), comments will be committed to the version
202 This plugin aims to close the [[todo]] item "[[todo/supporting_comments_via_disussion_pages]]",
203 and is currently available from [[smcv]]'s git repository on git.pseudorandom.co.uk (it's the
204 `postcomment` branch). A demo wiki with the plugin enabled is running at
205 <http://www.pseudorandom.co.uk/2008/ikiwiki/demo/>.
210 * The access control via postcomment() is rather strange
211 * There is some common code cargo-culted from other plugins (notably inline and editpage) which
212 should probably be shared
214 > I haven't done a detailed code review, but I will say I'm pleased you
215 > avoided re-implementing inline! --[[Joey]]
219 * tbm would like anonymous people to be able to enter their name and possibly email
221 * smcv would like an indication of who you're posting as / the ability to log in
222 as someone else (even if anonymous comments are allowed, it'd be nice to be
223 able to choose to log in with a username or OpenID, like in Livejournal);
224 perhaps editpage needs this too