none
[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 _( Discussion in TWiki:Plugins/CommentPluginDev )_
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="#Important Note regarding Locks"> Important Note regarding Locks</a></li>
26     <li><a href="#Settings"> Settings</a></li>
27     <li><a href="#Plugin Installation Instructions"> Plugin Installation Instructions</a></li>
28     <li><a href="#Plugin Info"> Plugin Info</a></li>
29   </ul>
30 </div>
31
32 # <a name="Features"></a> Features
33
34 Inserts an edit box into the page that allows users to type in and save comments. Comments can be made
35
36 - in different formats (as defined by a template),
37 - in both forward and reverse chronological order,
38 - signed or unsigned, dated or undated (as defined by a template),
39 - in other topics, or other positions within the current topic.
40
41 # <a name="Syntax Rules"></a> Syntax Rules
42
43 Write the command `%COMMENT{` _attributes_ `}%` anywhere in a TWiki topic. %COMMENT% is also legal.
44
45 <a name="StandardAttrs"></a> The following attributes are [[recognised|Main/WebHome#MoreAttrs]]
46
47 <table border="1" cellpadding="0" cellspacing="0">
48   <tr>
49     <th bgcolor="#99CCCC"><strong> Name </strong></th>
50     <th bgcolor="#99CCCC"><strong> Description </strong></th>
51   </tr>
52   <tr>
53     <td><code>type</code></td>
54     <td> (Required) 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>
55   </tr>
56   <tr>
57     <td><code>target</code></td>
58     <td> Name of the topic to add the comment to. Defaults to the current topic. </td>
59   </tr>
60   <tr>
61     <td><code>location</code></td>
62     <td> Regular expression specifying the comment location in the target topic. Read <em>carefully</em> below! </td>
63   </tr>
64   <tr>
65     <td><code>mode</code></td>
66     <td> For compatability with older versions only, synonymous with <code>type</code></td>
67   </tr>
68   <tr>
69     <td><code>nonotify</code></td>
70     <td> Set to "on" to disable change notification for target topics </td>
71   </tr>
72 </table>
73
74 ## <a name="Positioning the comment"></a> Positioning the comment
75
76 `%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.
77
78 ### <a name="Location relative to %COMMENT ta"></a> Location relative to `%COMMENT` tag
79
80 The default _location_ is the `%COMMENT` tag itself. For example:
81
82     %COMMENT{type="below"}%
83
84 will add comments in the current topic, directly below the `%COMMENT` tag.
85
86 ### <a name="Location relative to a TWiki anc"></a> Location relative to a TWiki anchor
87
88 The `target` attribute may specify a web, and may also specify an anchor within the target topic; for example,
89
90     %COMMENT{type="above" target="%MAINWEB%.PersonalRemarks#InsertHere"}%
91
92 This uses a standard TWiki in-topic anchor as the insertion location. See [[TextFormattingRules]] for more about TWiki anchors.
93
94 ### <a name="Location relative to an arbitrar"></a> Location relative to an arbitrary text string
95
96 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,
97
98     %COMMENT{type="above" location="Flights of Fancy"}%
99
100 will place comments above the first occurence of the string `Flights of Fancy` in the current topic.
101
102 **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.
103
104 If you specify an anchor _and_ a `location`, the anchor will be ignored.
105
106 ## <a name="Default templates"></a> Default templates
107
108 A set of default comment templates are shipped with the plugin. These are:
109
110 <table border="1" cellpadding="0" cellspacing="0">
111   <tr>
112     <th bgcolor="#99CCCC"><strong> Template type </strong></th>
113     <th bgcolor="#99CCCC"><strong> Description </strong></th>
114   </tr>
115   <tr>
116     <td><code>top</code></td>
117     <td> Comments, signed and dated, added at top of the topic (the anchor is ignored) </td>
118   </tr>
119   <tr>
120     <td><code>bottom</code></td>
121     <td> Comments, signed and dated, added at end of the target topic (the anchor is ignored) </td>
122   </tr>
123   <tr>
124     <td><code>above</code></td>
125     <td> Comments, signed and dated, added immediately before the target anchor, or the <code>%COMMENT</code> if no anchor is specified </td>
126   </tr>
127   <tr>
128     <td><code>below</code></td>
129     <td> Comments, signed and dated, added immediately below the target anchor, or the <code>%COMMENT</code> if no anchor is specified </td>
130   </tr>
131   <tr>
132     <td><code>tableprepend</code></td>
133     <td> Comments, signed and dated, formatted as an HTML table row, added below the anchor (which must be in an HTML &lt;table&gt;) </td>
134   </tr>
135   <tr>
136     <td><code>tableappend</code></td>
137     <td> Comments, signed and dated, formatted as an HTML table row, added above the anchor (which must be in an HTML &lt;table&gt;) </td>
138   </tr>
139 </table>
140
141 Your local installation may add more template types as well - see [[Customisation|Main/WebHome#TemPlates]], below.
142
143 <a name="TemPlates"></a>
144
145 # <a name="Customisation"></a> Customisation
146
147 Customisation of the comment plugin requires
148
149 - familiarity with HTML forms,
150 - some familiarity with the [[TWiki templating language|TWiki/TWikiTemplates]].
151
152 The plugin picks up its templates from a standard TWiki template file, named "comments". This allows different templates to be defined for different TWiki skins. This template file may include other template files, or may include a topic from a user web (this is an extension to the normal handling of `%TMPL:INCLUDE` described in the documentation). The shipped plugin defines default templates in `comments.tmpl` and then includes the topic [[CommentsTmpl]]. If you want to define your own templates, add them to [[UserTemplates]]. Note that you can use `%TMPL:INCLUDE` in this file to include other files of templates. Note also that if you want to override any of the default templates shipped with the plugin, you can simply do so by defining them in [[UserTemplates]], and they will replace the installed versions.
153
154 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.
155
156 ## <a name="The &lt;code&gt;PROMPT&lt;/code&gt; template"></a> The `PROMPT` template
157
158 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.
159
160 Only the input fields of the form need be defined. The plugin automatically generates the `>form<` and `&gt:/form<` tags. **Note** that you must define a "submit" button if you want the form to work!
161
162 <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:
163
164     <textarea rows=%rows|3% cols="%cols|50%" value="%tval|Rubbish%">
165
166 and the %COMMENT tag is:
167
168     %COMMENT{type="example" rows="5" cols="20"}%
169
170 then the template will be expanded as
171
172     <textarea rows=5 cols="20" value="Rubbish">
173
174 As well as support for all the usual TWiki variables in templates, the following special variables are supported in the `PROMPT` definition:
175
176 <table border="1" cellpadding="0" cellspacing="0">
177   <tr>
178     <th bgcolor="#99CCCC"><strong> Variable </strong></th>
179     <th bgcolor="#99CCCC"><strong> Description </strong></th>
180   </tr>
181   <tr>
182     <td><code>%MESSAGE%</code></td>
183     <td> A helpful generated message, either a lock message or a reminder to refresh. </td>
184   </tr>
185   <tr>
186     <td><code>%DISABLED%</code></td>
187     <td> Set to 'disabled' when you cannot comment (see [[Main/WebHome#HandlingPageLock]], below). </td>
188   </tr>
189 </table>
190
191 ## <a name="The &lt;code&gt;OUTPUT&lt;/code&gt; template"></a> The `OUTPUT` template
192
193 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.
194
195 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:
196
197 <table border="1" cellpadding="0" cellspacing="0">
198   <tr>
199     <td><code>%POS:TOP%</code></td>
200     <td> If present, comments will be inserted <strong>at the top of the topic</strong> i.e. before any other text </td>
201   </tr>
202   <tr>
203     <td><code>%POS:BOTTOM%</code></td>
204     <td> If present, comments will be inserted <strong>at the end of the topic</strong> i.e. after all existing text </td>
205   </tr>
206   <tr>
207     <td><code>%POS:BEFORE%</code></td>
208     <td> If present, comments will be inserted <b>immediately before the <code>%COMMENT%</code> tag</b></td>
209   </tr>
210   <tr>
211     <td><code>%POS:AFTER%</code></td>
212     <td> If present, comments will be inserted <b>immediately after the <code>%COMMENT%</code> tag</b></td>
213   </tr>
214 </table>
215
216 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`
217
218 <a name="HandlingPageLock"></a>
219
220 # <a name="Important Note regarding Locks"></a> Important Note regarding Locks
221
222 The plugin checks if the page is locked for edit. When a locked page is displayed in 'view' mode, comment input is automatically disabled.
223
224 Note that if the page was read long time ago, it's possible that page was locked by another user **after** it was read, and the lock is still outstanding. In this case, comments cannot be saved, and you will be redirected to a "topic is locked" page. You then have two options:
225
226 - **Cancel** - throw away your comment and return to viewing the page.
227 - **Back** - **WARNING** some browsers might requery the page and **lose** your comments - so test how your browser behaves before using the Back button.
228
229 To help avoid edit conflict, a reminder to refresh the page before entering comments is the default text for a `%COMMENT`. When the target page is known to be locked, the `PROMPT` form is automatically disabled.
230
231 # <a name="Settings"></a> Settings
232
233 - Description:
234   - Set SHORTDESCRIPTION = Allows users to quickly post comments to a page without an edit/preview/save cycle.
235 - templates; includes user templates from [[CommentsTmpl]]
236   - Set TEMPLATES = comments
237 - default template type (if not present, defaults to "below")
238   - Set DEFAULT\_TYPE = above
239
240 # <a name="Plugin Installation Instructions"></a> Plugin Installation Instructions
241
242 \* Make sure you have the TWiki:Plugins/SharedCode module installed. Among other things, TWiki:Plugins/SharedCode includes a compatibility module that enables plugins to use new TWiki features with earlier TWiki releases. If you don't already have it, install it now.
243
244 - Download the ZIP file from the Plugin web (see below)
245 - Unzip <code>**%TOPIC%.zip**</code> in your twiki installation directory. Content: <table border="1" cellpadding="0" cellspacing="0">
246   <tr>
247     <th bgcolor="#99CCCC"><strong> File: </strong></th>
248     <th bgcolor="#99CCCC"><strong> Description: </strong></th>
249   </tr>
250   <tr>
251     <td><code><b>data/TWiki/CommentPlugin.txt</b></code></td>
252     <td> Plugin doc page (this page) </td>
253   </tr>
254   <tr>
255     <td><code><b>data/TWiki/CommentsTmpl.txt</b></code></td>
256     <td> Example user templates </td>
257   </tr>
258   <tr>
259     <td><code><b>templates/comments.tmpl</b></code></td>
260     <td> Master comment templates </td>
261   </tr>
262   <tr>
263     <td><code><b>lib/TWiki/Plugins/CommentPlugin.pm</b></code></td>
264     <td> Plugin Perl module </td>
265   </tr>
266   <tr>
267     <td><code><b>lib/TWiki/Plugins/CommentPlugin/Comment.pm</b></code></td>
268     <td> Plugin Perl module </td>
269   </tr>
270   <tr>
271     <td><code><b>lib/TWiki/Plugins/CommentPlugin/Templates.pm</b></code></td>
272     <td> Plugin Perl module </td>
273   </tr>
274   <tr>
275     <td><code><b>lib/TWiki/Plugins/CommentPlugin/test.zip</b></code></td>
276     <td> Tests </td>
277   </tr>
278   <tr>
279     <td><code><b>lib/TWiki/Plugins/CommentPlugin/build.pl</b></code></td>
280     <td> Build file </td>
281   </tr>
282 </table>
283
284 - The Plugin depends on the `viewauth` script to authenticate the user. As described in [[TWikiAccessControl]], copy the `view` script to `viewauth` (or better, create a symbolic link) and add `viewauth` to the list of authenticated scripts in the `.htaccess` file.
285
286 If installed correctly, you should see a `%COMMENT` edit box below here.
287
288 <form action="http://www.dementia.org/twiki/save/Sandbox/Comments" enctype="multipart/form-data" id="top0" method="post" name="top0"><input name="comment_action" type="hidden" value="save" /><input name="comment_type" type="hidden" value="top" /><input name="comment_index" type="hidden" value="0" /></form>
289
290 # <a name="Plugin Info"></a> Plugin Info
291
292 <table border="1" cellpadding="0" cellspacing="0">
293   <tr>
294     <td align="right"> Plugin Author: </td>
295     <td> v1.0 TWiki:Main/DavidWeller v2.0 TWiki:Main/PeterMasiar v3.0 TWiki:Main/CrawfordCurrie </td>
296   </tr>
297   <tr>
298     <td align="right"> Plugin Version: </td>
299     <td> 3.0 </td>
300   </tr>
301   <tr>
302     <td align="right"> Change History: </td>
303     <td> 3.003 11 Apr 2004: Minor line termination problem fixed, and "security" hyphen on standard comment removed and replaced with a bulleted list. </td>
304   </tr>
305   <tr>
306     <td>   </td>
307     <td> 3.002 6 April 2004: Applied patches (thanks Peter Thoeny) for multiple comment adding, BOTTOM and TOP inside meta-data, and moved example to Sandbox. </td>
308   </tr>
309   <tr>
310     <td>   </td>
311     <td> 3.001 13 March 2004: Modified to use viewauth save technique (safer), add nonotify parameter, move templates fully into topics, with a hook for site-specifics, support %COMMENT%, internationalisation fixes </td>
312   </tr>
313   <tr>
314     <td>   </td>
315     <td> 3.000 18 Feb 2004: TWiki:Main/CrawfordCurrie rewrote for standard templates and other user requests. Recognition to Patrice Fournier and Sam Abrams for terrific testing and patch support. </td>
316   </tr>
317   <tr>
318     <td>   </td>
319     <td> 7 Feb 2004: TWiki:Main/CrawfordCurrie rewrote this page and [[Main/CommentTemplates]] in an effort to make the plugin more user friendly. Added {TIME} variable. Also updated CVS. </td>
320   </tr>
321   <tr>
322     <td>   </td>
323     <td> 23 Sep 2003 TWiki:Main/PeterMasiar: 80% rewrite/refactor, adding templates </td>
324   </tr>
325   <tr>
326     <td>   </td>
327     <td> 15 July 2003: TWiki:Main/PeterMasiar added "reminder" parameter and feature to pass comments to oopslockedcomments.tmpl template to copy-paste later </td>
328   </tr>
329   <tr>
330     <td>   </td>
331     <td> 5 March 2002 Bug fixes, TWiki:Main/JonLambert created oopslockedcomments.tmpl template </td>
332   </tr>
333   <tr>
334     <td>   </td>
335     <td> 24 Feb 2002 added a few more user requests, made "English" text configurable </td>
336   </tr>
337   <tr>
338     <td>   </td>
339     <td> 4 Dec 2001: 1.01 release, changed name to [[Main/CommentPlugin]], added $button var, changed textarea WRAP setting to "soft" </td>
340   </tr>
341   <tr>
342     <td>   </td>
343     <td> 30 Nov 2001: Initial version </td>
344   </tr>
345   <tr>
346     <td align="right"> Dependencies: </td>
347     <td>   </td>
348   </tr>
349   <tr>
350     <td align="right"> Perl Version: </td>
351     <td> 5.0 </td>
352   </tr>
353   <tr>
354     <td align="right"> Plugin Home: </td>
355     <td> TWiki:Plugins/%TOPIC% </td>
356   </tr>
357   <tr>
358     <td align="right"> Feedback: </td>
359     <td> TWiki:Plugins/%TOPIC%Dev </td>
360   </tr>
361 </table>
362
363 **_Related Topics:_** [[TWikiPreferences]], [[TWikiPlugins]]
364
365 -- TWiki:Main/DavidWeller - 05 Mar 2002 <br /> -- TWiki:Main/PeterMasiar - 15 Jul 2003, 23 Sep 2003<br /> -- TWiki:Main/CrawfordCurrie - 21 May 2004