buildrelease
[openafs-wiki.git] / TWiki / CommentPlugin.mdwn
1 # <a name="Comment Plugin"></a><a name=" Comment Plugin"></a> Comment Plugin
2
3 This plugin allows users to quickly post comments to a page without an edit/preview/save cycle.
4
5 **WARNING: TWiki-4 only. If you want to use this plugin with an earlier version of TWiki, please see [here](http://twiki.org/cgi-bin/view/Plugins/%TOPIC%?rev=1.57)**
6
7 <div>
8   <ul>
9     <li><a href="#Features"> Features</a></li>
10     <li><a href="#Syntax Rules"> Syntax Rules</a><ul>
11         <li><a href="#Positioning the comment"> Positioning the comment</a><ul>
12             <li><a href="#Location relative to %COMMENT ta"> Location relative to <code>%COMMENT</code> tag</a></li>
13             <li><a href="#Location relative to a TWiki anc"> Location relative to a TWiki anchor</a></li>
14             <li><a href="#Location relative to an arbitrar"> Location relative to an arbitrary text string</a></li>
15           </ul>
16         </li>
17         <li><a href="#Default templates"> Default templates</a></li>
18       </ul>
19     </li>
20     <li><a href="#Customisation"> Customisation</a><ul>
21         <li><a href="#The <code>PROMPT</code> template"> The PROMPT template</a></li>
22         <li><a href="#The <code>OUTPUT</code> template"> The OUTPUT template</a></li>
23       </ul>
24     </li>
25     <li><a href="#Settings"> Settings</a></li>
26     <li><a href="#Plugin Installation Instructions"> Plugin Installation Instructions</a></li>
27     <li><a href="#Plugin Info"> Plugin Info</a></li>
28   </ul>
29 </div>
30
31 # <a name="Features"></a> Features
32
33 Inserts an edit box into the page that allows users to type in and save comments. Comments can be made
34
35 - in different formats (as defined by a template),
36 - in both forward and reverse chronological order,
37 - signed or unsigned, dated or undated (as defined by a template),
38 - in other topics, or other positions within the current topic.
39
40 # <a name="Syntax Rules"></a> Syntax Rules
41
42 Write the command `%COMMENT{` _attributes_ `}%` anywhere in a TWiki topic. %COMMENT% is also legal.
43
44 <a name="StandardAttrs"></a> The following attributes are [[recognised|Main/WebHome#MoreAttrs]]
45
46 <table border="1" cellpadding="0" cellspacing="0">
47   <tr>
48     <th bgcolor="#99CCCC"><strong> Name </strong></th>
49     <th bgcolor="#99CCCC"><strong> Description </strong></th>
50   </tr>
51   <tr>
52     <td><code>type</code></td>
53     <td> This is the name of the template to use for this comment. Comment templates are defined in a TWiki template - see [[Main/WebHome#TemPlates]], below. If this attribute is not defined, the type is whatever is defined by COMMENTPLUGIN_DEFAULT_TYPE, either in this topic or in your [[Main/WebPreferences]]. By default this is 'below'. </td>
54   </tr>
55   <tr>
56     <td><code>target</code></td>
57     <td> Name of the topic to add the comment to. Defaults to the current topic. </td>
58   </tr>
59   <tr>
60     <td><code>location</code></td>
61     <td> Regular expression specifying the comment location in the target topic. Read <em>carefully</em> below! </td>
62   </tr>
63   <tr>
64     <td><code>mode</code></td>
65     <td> For compatability with older versions only, synonymous with <code>type</code></td>
66   </tr>
67   <tr>
68     <td><code>nonotify</code></td>
69     <td> Set to "on" to disable change notification for target topics </td>
70   </tr>
71   <tr>
72     <td><code>noform</code></td>
73     <td> Set to "on" to disable the automatic form that encloses your comment block - <em>remember</em> to insert <code>&lt;FORM&gt;</code> tags yourself! </td>
74   </tr>
75 </table>
76
77 ## <a name="Positioning the comment"></a> Positioning the comment
78
79 `%COMMENT` supports several ways to specify _where_ a comment should be inserted in the target topic. This is referred to as the _location_ of the comment.
80
81 ### <a name="Location relative to %COMMENT ta"></a> Location relative to `%COMMENT` tag
82
83 The default _location_ is the `%COMMENT` tag itself. For example:
84
85     %COMMENT{type="below"}%
86
87 will add comments in the current topic, directly below the `%COMMENT` tag.
88
89 ### <a name="Location relative to a TWiki anc"></a> Location relative to a TWiki anchor
90
91 The `target` attribute may specify a web, and may also specify an anchor within the target topic; for example,
92
93     %COMMENT{type="above" target="%MAINWEB%.PersonalRemarks#InsertHere"}%
94
95 This uses a standard TWiki in-topic anchor as the insertion location. See [[TextFormattingRules]] for more about TWiki anchors.
96
97 ### <a name="Location relative to an arbitrar"></a> Location relative to an arbitrary text string
98
99 Getting more sophisticated, you can also specify a regular expression for the target location using the `location` parameter. The target topic is searched for the regular expression, and the comment inserted relative to the string that the search matched. For example,
100
101     %COMMENT{type="above" location="Flights of Fancy"}%
102
103 will place comments above the first occurence of the string `Flights of Fancy` in the current topic.
104
105 **Warning** of course, if a user's comment contains the string "Flights of Fancy" they may and up _changing the location_ for the next comment! Also, if you use a tag in the location, then you've just inserted another tag in the page that contains the `%COMMENT`! So be very careful how you specify the RE for `location`. Note that the RE is matched using perl "multiple line" mode, so ^ and $ match the start of a line and the end of a line respectively.
106
107 I look forward to someone leveraging this feature to create - for example - threaded conversations using `%COMMENT`.
108
109 If you specify an anchor _and_ a `location`, the anchor will be ignored.
110
111 ## <a name="Default templates"></a> Default templates
112
113 Templates are used to define the "comment style" i.e. how comments appear in the page. The default is to add comments in "Blog like" style using bulleted lists, with the most recent comment at the top, but many other styles are available such as tables or Wiki thread mode comments. It is easy to define your own customer styles as well.
114
115 A set of default comment templates are shipped with the plugin. These are:
116
117 <table border="1" cellpadding="0" cellspacing="0">
118   <tr>
119     <th bgcolor="#99CCCC"><strong> Template type </strong></th>
120     <th bgcolor="#99CCCC"><strong> Description </strong></th>
121   </tr>
122   <tr>
123     <td><code>top</code></td>
124     <td> Comments, signed and dated (server time), added at top of the topic (the anchor is ignored) </td>
125   </tr>
126   <tr>
127     <td><code>bottom</code></td>
128     <td> Comments, signed and dated (server time), added at end of the target topic (the anchor is ignored) </td>
129   </tr>
130   <tr>
131     <td><code>above</code></td>
132     <td> Comments, signed and dated (server time), added immediately before the target anchor, or the <code>%COMMENT</code> if no anchor is specified </td>
133   </tr>
134   <tr>
135     <td><code>below</code></td>
136     <td> Comments, signed and dated (server time), added immediately below the target anchor, or the <code>%COMMENT</code> if no anchor is specified </td>
137   </tr>
138   <tr>
139     <td><code>threadmode</code></td>
140     <td> Wiki thread mode comment, signed and dated (server time) </td>
141   </tr>
142   <tr>
143     <td><code>tableprepend</code></td>
144     <td> Comments, signed and dated (server time), formatted as an HTML table row, added below the anchor (which must be in an HTML &lt;table&gt;) </td>
145   </tr>
146   <tr>
147     <td><code>tableappend</code></td>
148     <td> Comments, signed and dated (server time), formatted as an HTML table row, added above the anchor (which must be in an HTML &lt;table&gt;) </td>
149   </tr>
150 </table>
151
152 Your local installation may add more template types as well - see [[Customisation|Main/WebHome#TemPlates]], below.
153
154 <a name="TemPlates"></a>
155
156 # <a name="Customisation"></a> Customisation
157
158 Customisation of the comment plugin requires
159
160 - familiarity with HTML forms,
161 - some familiarity with the [[TWiki templating language|TWiki/TWikiTemplates]].
162
163 To define a comment type, you have to provide two simple template definitions in the template file; one for the prompt box, and one for the generated output. If we have a template type "mytype", these are named `PROMPT:mytype` and `OUTPUT:mytype` respectively. See `comments.tmpl` in the templates directory for examples.
164
165 The plugin picks up these template definitions from a standard TWiki template file, `templates/comments.tmpl`. This allows different templates to be defined for different TWiki skins. By default, this template includes the topic [[CommentPluginTemplate]], which contains all the shipped standard templates and in turn includes TWiki.UserCommentsTemplate. This allows for several levels of customisation:
166
167 1. To override all default templates, everywhere, change `comments.tmpl` to include a different topic (this customisation will be lost next time you upgrade, though).
168 2. To add site-wide local template customisations, add them to TWiki.UserCommentsTemplate. You can redefine the standard templates here if you want, and your definitions will override the standard definitions.
169 3. To override templates on a web-by-web basis, add a topic UserCommentsTemplate to the web (this will replace TWiki.UserCommentsTemplate)
170 4. To override templates for a specific skin, add them to TWiki.UserComments&lt;Skin&gt;Template (where &lt;Skin&gt; is the name of the skin with the first letter capitalised, e.g. Pattern)
171
172 %X% Templates are picked up by following the [[standard TWiki rules|Main/TWikiTemplates#Finding_Templates]] for locating template files. Note that you can use `%TMPL:INCLUDE` to include other files of templates.
173
174 ## <a name="The &lt;code&gt;PROMPT&lt;/code&gt; template"></a> The `PROMPT` template
175
176 The `PROMPT` template defines the contents of an HTML form that is used to capture the comment. This form invokes the comment generator when submitted. Parameters to the comment generator are defined using standard HTML input fields, such as `input`, `textarea` and `select`. The user enters values for these parameters, and these are then available when the `OUTPUT` template is expanded, in the form of `%URLPARAM%`s.
177
178 Only the input fields of the form need be defined. The plugin automatically generates the `>form<` and `&gt:/form<` tags, unless you specify `noform="on"`, in which case you have to provide them yourself. **Note** that you must define a "submit" button if you want the form to work!
179
180 <a name="MoreAttrs"></a> If an attribute is given to the `%COMMENT` tag that is not one of the [[standard attributes|Main/WebHome#StandardAttrs]], then that attribute is taken as the name of a parameter to be expanded in the `PROMPT` template. Expressions in the template of the form `%`_param_`|`_default_`%` (e.g. `%rows|3%`, `%button|Push me%`) are expanded to the values given in the `%COMMENT`. For example, if the `PROMPT` template 'example' contains:
181
182     <textarea rows=%rows|3% cols="%cols|50%" value="%tval|Rubbish%">
183
184 and the %COMMENT tag is:
185
186     %COMMENT{type="example" cols="75"}%
187
188 then the template will be expanded as
189
190     <textarea rows="3" cols="75" value="Rubbish">
191
192 As well as support for all the usual TWiki variables in templates, the following special variables are supported in the `PROMPT` definition:
193
194 <table border="1" cellpadding="0" cellspacing="0">
195   <tr>
196     <th bgcolor="#99CCCC"><strong> Variable </strong></th>
197     <th bgcolor="#99CCCC"><strong> Description </strong></th>
198   </tr>
199   <tr>
200     <td><code>%MESSAGE%</code></td>
201     <td> A helpful generated message, either a lock message or a reminder to refresh. </td>
202   </tr>
203   <tr>
204     <td><code>%DISABLED%</code></td>
205     <td> Set to 'disabled' when you cannot comment (e.g. in preview mode). </td>
206   </tr>
207 </table>
208
209 ## <a name="The &lt;code&gt;OUTPUT&lt;/code&gt; template"></a> The `OUTPUT` template
210
211 The `OUTPUT` template defines the format for the text that actually gets embedded into the topic. All the usual TWiki variables are available in the `PROMPT` definition, but note that they get expanded _when the comment is inserted in the text_, so time, date and username will refer to the time and date when the comment was made and the user who made it.
212
213 There are also four position tags that are used to indicate where the comment should be placed, relative to the `location` defined in the `%COMMENT` tag:
214
215 <table border="1" cellpadding="0" cellspacing="0">
216   <tr>
217     <td><code>%POS:TOP%</code></td>
218     <td> If present, comments will be inserted <strong>at the top of the topic</strong> i.e. before any other text </td>
219   </tr>
220   <tr>
221     <td><code>%POS:BOTTOM%</code></td>
222     <td> If present, comments will be inserted <strong>at the end of the topic</strong> i.e. after all existing text </td>
223   </tr>
224   <tr>
225     <td><code>%POS:BEFORE%</code></td>
226     <td> If present, comments will be inserted <b>immediately before the <code>%COMMENT%</code> tag</b></td>
227   </tr>
228   <tr>
229     <td><code>%POS:AFTER%</code></td>
230     <td> If present, comments will be inserted <b>immediately after the <code>%COMMENT%</code> tag</b></td>
231   </tr>
232 </table>
233
234 Note that these position tags are obviously mutually exclusive. If you define more than one, the result is undefined. If none is present, the default is taken from the plugin setting `DEFAULT_TYPE`
235
236 All the usual [[TWikiVariables]] that can be used in a topic template can also be used in an `OUTPUT` template. See [[TWikiVariables]] for details.
237
238 # <a name="Settings"></a> Settings
239
240 - Description:
241   - Set SHORTDESCRIPTION = Allows users to quickly post comments to a page without an edit/preview/save cycle.
242 - Name of file in the 'templates' directory that contains the comment templates. The default 'comments.tmpl' automatically includes user templates from [[CommentsTmpl]]
243   - Set TEMPLATES = comments
244 - default template type (if not present, defaults to "below")
245   - Set DEFAULT\_TYPE = below
246
247 # <a name="Plugin Installation Instructions"></a> Plugin Installation Instructions
248
249 - This plugin is pre-installed in most TWiki releases. However if you need to upgrade the plugin for any reason:
250   - Download the archive file from the Plugin web (see below)
251   - Unpack the archive in your twiki installation directory.
252   - You may need to correct file permissions.
253   - Run <code>**%TOPIC%\_installer**</code> to automatically check and install other modules that this module depends on. You can also do this step manually. Dependencies: None
254   - Visit `configure` in your TWiki installation, and enable the plugin in the \{Plugins\} section.
255
256 # <a name="Plugin Info"></a> Plugin Info
257
258 <table border="1" cellpadding="0" cellspacing="0">
259   <tr>
260     <td align="right"> Plugin Author: </td>
261     <td> TWiki:Main.DavidWeller, TWiki:Main.PeterMasiar, TWiki:Main.CrawfordCurrie <a href="http://www.c-dot.co.uk" target="_top">http://www.c-dot.co.uk</a></td>
262   </tr>
263   <tr>
264     <td> Change History: </td>
265     <td>   </td>
266   </tr>
267   <tr>
268     <td> 8788 </td>
269     <td><a href="http://develop.twiki.org/~develop/cgi-bin/view/Bugs/Item1465" rel="nofollow">Item1465</a> Item1577: reverted 8433 to fix inclusion of correct user templates </td>
270   </tr>
271   <tr>
272     <td> 8787 </td>
273     <td><a href="http://develop.twiki.org/~develop/cgi-bin/view/Bugs/Item1573" rel="nofollow">Item1573</a> renamed standard templates topic to avoid naming clash on Windows, where filenames are case-insensitive </td>
274   </tr>
275   <tr>
276     <td> 8433 </td>
277     <td><a href="http://develop.twiki.org/~develop/cgi-bin/view/Bugs/Item1465" rel="nofollow">Item1465</a> Fix 'TWiki.' to '%TWIKIEB%.'; also fixed include 'UserComments' to 'UserCommentsTemplate' (at least that is what the doc suggests) </td>
278   </tr>
279   <tr>
280     <td> 7427 </td>
281     <td><a href="http://develop.twiki.org/~develop/cgi-bin/view/Bugs/Item845" rel="nofollow">Item845</a> removed duplicate date in default comments; stick with server time </td>
282   </tr>
283   <tr>
284     <td> 7251 </td>
285     <td><a href="http://develop.twiki.org/~develop/cgi-bin/view/Bugs/Item810" rel="nofollow">Item810</a> fix for user template inclusion; reorganised templates to make customisation easier </td>
286   </tr>
287   <tr>
288     <td> 5906 </td>
289     <td><a href="http://develop.twiki.org/~develop/cgi-bin/view/Bugs/Item143" rel="nofollow">Item143</a> apache warning from comment plugin when [[Main/CommentsTmpl]].txt not foudn </td>
290   </tr>
291   <tr>
292     <td> 5519 </td>
293     <td>[[Main/CommentPluginOnAnchorsBroken]]: incorporated [[Main/JacobEisinger]]'s fix </td>
294   </tr>
295   <tr>
296     <td> 5518 </td>
297     <td>[[Main/CommentPluginOnAnchorsBroken]]: incorporated [[Main/OlivierBerger]]'s fix </td>
298   </tr>
299   <tr>
300     <td> 5455 </td>
301     <td> On Niels Kodslo's prompting, removed the global recursion prevention that I believe is no longer needed. </td>
302   </tr>
303   <tr>
304     <td> 5280 </td>
305     <td> Removed templates, and some minor fixes </td>
306   </tr>
307   <tr>
308     <td> 5250 </td>
309     <td> Removed newlines from prompt box </td>
310   </tr>
311   <tr>
312     <td> 4902 </td>
313     <td> Changed to use viewauth. Moved templates into user topics. </td>
314   </tr>
315   <tr>
316     <td> 4901 </td>
317     <td> Added templates in user webs support </td>
318   </tr>
319   <tr>
320     <td> 4897 </td>
321     <td> Fixes for disabling during preview; re-enabled old legacy parameters </td>
322   </tr>
323   <tr>
324     <td> 4889 </td>
325     <td> Chopped down from [[Main/PeterMasiar]] version, removing several parameters, savecomment script, changing way templates are done. Major rewrite, atcherly. </td>
326   </tr>
327   <tr>
328     <td> 4882 </td>
329     <td> Update from [[Main/PeterMasiar]]'s 2.0 version, plus documentation and small code improvements. </td>
330   </tr>
331   <tr>
332     <td> 4745 </td>
333     <td> 06Mar 2002 initial commit </td>
334   </tr>
335   <tr>
336     <td align="right"> Perl Version: </td>
337     <td> &gt;= 5.6.1 </td>
338   </tr>
339   <tr>
340     <td align="right"> Plugin Home: </td>
341     <td> TWiki:Plugins/%TOPIC% </td>
342   </tr>
343   <tr>
344     <td align="right"> Feedback: </td>
345     <td> TWiki:Plugins/%TOPIC%Dev </td>
346   </tr>
347 </table>
348
349 **_Related Topics:_** [[TWikiPreferences]], [[TWikiPlugins]]
350
351 -- TWiki:Main/CrawfordCurrie - 21:44:41 31 March 2006