%META:TOPICINFO{author="ProjectContributor" date="1751545319" format="1.1" version="1"}%
%META:TOPICPARENT{name="CommentPlugin"}%
---+!! Templates for CommentPlugin

See [[%SYSTEMWEB%.CommentPlugin#Customisation][CommentPlugin: Customisation]] for help.

While this topic can be viewed as a topic, it is used by the CommentPlugin as a template file. The syntax is the same as used for the templates used for presentation in skins - see SkinTemplates. The important content in here is in the verbatim blocks. The rest of the topic is just comments.

%ICON{"hand"}% See %SANDBOXWEB%.CommentPluginExamples to view rendered templates

<div class="foswikiBroadcastMessage" style="background-color:#ffc;">WARNING: THIS FILE WILL BE OVERWRITTEN WHEN YOU UPGRADE THE COMMENT PLUGIN</div>

Put your local templates into %SYSTEMWEB%.UserCommentsTemplate (create if it does not exist yet). *Local templates defined in that topic will override templates defined below.*

!CommentPlugin can work in two modes, _refresh_ and _ajax_. In refresh mode,
the entire topic is refreshed whenever a comment is added. This is rather slow,
but gives the most accurate results. In _ajax_ mode, insertion of comments is
handled by Javascript in the browser, but what the user sees after adding
a comment is not necessarily identical to what they will see when the topic is
refreshed.

The templates below all use ajax mode for best performance by default.
The plugin will fall back to refresh mode if Javascript is not available
(e.g. it is enabled in your user's browsers).

If you want to disable ajax completely, then override the following template
<verbatim>
%TMPL:DEF{ajax}%commentPluginAjax%TMPL:END%
</verbatim>
setting it to empty.

%TOC{title="Table of Contents"}%

---++ Template definitions

%X% Note that the use of URLPARAM in the templates should be done in a way that prevents Cross Site Scripting attacks. The safest is to let URLPARAM encode the unsafe characters (default) but this prevents the user from entering Foswiki macros in the comment input fields. It is however safe to use encode="off" when the following rules are observed.
   * The encode="off" option for URLPARAM is only used in this topic within verbatim tags to prevent this topic from being an XSS attack vector.
   * The encode="off" option is only used in OUTPUT defs and never in the PROMPT.
   * The encode="off" should never be used for guest comments.  The comment plugin will expand the =$encodeguest= token to "off" for logged in users and "entity" for guests.
   
---+++ Templates used in rest of file

Generic prompt box used by other templates
<verbatim>
%TMPL:DEF{promptbox}%<div class="commentPlugin commentPluginPromptBox"><table border="0" cellpadding="0" cellspacing="0"><tr valign="middle"><td><textarea %DISABLED% rows="%rows|3%" cols="%cols|70%" name="comment" class="foswikiInputField commentPluginPromptBox" title="%MESSAGE%">%MESSAGE%</textarea></td><td>&nbsp;<input %DISABLED% type="submit" value="%button|Add comment%" class="foswikiButton %TMPL:P{ajax}%" /></td></tr></table></div><!--/commentPlugin-->%TMPL:END%
</verbatim>

Short comment, signed and dated
<verbatim>
%TMPL:DEF{outputoneliner}%   * %URLPARAM{"comment" encode="$encodeguest"}% -- %WIKIUSERNAME% - %GMTIME{"$day $month $year"}%%TMPL:END%
</verbatim>

%ICON{"hand"}% See rendered template [[%SANDBOXWEB%.CommentPluginExamples#Default][Default]]




---+++ User templates
---++++ top
Comments, signed and dated, added at top of file
<verbatim>
%TMPL:DEF{PROMPT:top}%%TMPL:P{promptbox}%%TMPL:END%
</verbatim>

<verbatim>
%TMPL:DEF{OUTPUT:top}%%TMPL:P{outputoneliner}%%POS:TOP%
%TMPL:END%
</verbatim>

%ICON{"hand"}% See rendered template [[%SANDBOXWEB%.CommentPluginExamples#top][top]]




---++++ bottom
Comments, signed and dated, added at end of file
<verbatim>
%TMPL:DEF{PROMPT:bottom}%%TMPL:P{promptbox}%%TMPL:END%
</verbatim>
<verbatim>
%TMPL:DEF{OUTPUT:bottom}%%POS:BOTTOM%%TMPL:P{outputoneliner}%%TMPL:END%
</verbatim>

%ICON{"hand"}% See rendered template [[%SANDBOXWEB%.CommentPluginExamples#bottom][bottom]]




---++++ above
Comments, signed and dated, added immediately before anchor
<verbatim>
%TMPL:DEF{PROMPT:above}%%TMPL:P{promptbox}%%TMPL:END%
</verbatim>
<verbatim>
%TMPL:DEF{OUTPUT:above}%%POS:BEFORE%%TMPL:P{OUTPUT:threadmode}%%TMPL:END%
</verbatim>

%ICON{"hand"}% See rendered template [[%SANDBOXWEB%.CommentPluginExamples#above][above]]




---++++ bulletabove
Bullet item added immediately before anchor. The input field width is passed with parameter =inputsize=, for example:

<verbatim>
%COMMENT{type="bulletabove" inputsize="20"}%
</verbatim>

<verbatim>
%TMPL:DEF{PROMPT:bulletabove}%<input class="foswikiInputField" name="bullet_above_item" id="bullet_above_item" type="text" size="%inputsize|40%" value="%URLPARAM{"bullet_above_item"}%" />&nbsp;<input %DISABLED% type="button" value="%button|Add item%" class="foswikiButton %TMPL:P{ajax}%" />%TMPL:END%
</verbatim>
<verbatim>
%TMPL:DEF{OUTPUT:bulletabove}%   * %URLPARAM{"bullet_above_item" encode="$encodeguest"}%%POS:BEFORE%
%TMPL:END%
</verbatim>

%ICON{"hand"}% See rendered template [[%SANDBOXWEB%.CommentPluginExamples#bulletabove][bulletabove]]




---++++ threadmode
Wiki thread mode comment, signed and dated
<verbatim>
%TMPL:DEF{PROMPT:threadmode}%%TMPL:P{promptbox}%%TMPL:END%
</verbatim>
<verbatim>
%TMPL:DEF{OUTPUT:threadmode}%%POS:BEFORE%

%URLPARAM{"comment" encode="$encodeguest"}%

-- %WIKIUSERNAME% - %DATE%
%TMPL:END%
</verbatim>

%ICON{"hand"}% See rendered template [[%SANDBOXWEB%.CommentPluginExamples#threadmode][threadmode]]




---++++ belowthreadmode
Comments, signed and dated, added recurse after comment box.

<verbatim>
%TMPL:DEF{PROMPT:belowthreadmode}%%TMPL:P{promptbox}%%TMPL:END%
</verbatim>
<verbatim>
%TMPL:DEF{OUTPUT:belowthreadmode}%%POS:AFTER%
---++++ %WIKIUSERNAME% - %SERVERTIME%

%URLPARAM{"comment" encode="$encodeguest"}%

%TMPL:END%
</verbatim>

%ICON{"hand"}% See rendered template [[%SANDBOXWEB%.CommentPluginExamples#belowthreadmode][belowthreadmode]]




---++++ below
Comments, signed and dated, added immediately below anchor
<verbatim>
%TMPL:DEF{PROMPT:below}%%TMPL:P{promptbox}%%TMPL:END%
</verbatim>
<verbatim>
%TMPL:DEF{OUTPUT:below}%%POS:AFTER%%TMPL:P{outputoneliner}%
%TMPL:END%
</verbatim>

%ICON{"hand"}% See rendered template [[%SANDBOXWEB%.CommentPluginExamples#below][below]]




---++++ tableprepend
Comments, signed and dated, added at top of table below the
anchor/location/COMMENT
<verbatim>
%TMPL:DEF{PROMPT:tableprepend}%%TMPL:P{promptbox}%%TMPL:END%
</verbatim>
<verbatim>
%TMPL:DEF{OUTPUT:tableprepend}%%POS:AFTER%| %URLPARAM{"comment" newline="<br />" encode="$encodeguest"}% | %WIKIUSERNAME% | %SERVERTIME% |
%TMPL:END%
</verbatim>

%ICON{"hand"}% See rendered template [[%SANDBOXWEB%.CommentPluginExamples#tableprepend][tableprepend]]




---++++ tableappend
Comments, signed and dated, added at end of table above the anchor/location/COMMENT
<verbatim>
%TMPL:DEF{PROMPT:tableappend}%%TMPL:P{promptbox}%%TMPL:END%
</verbatim>
<verbatim>
%TMPL:DEF{OUTPUT:tableappend}%%POS:BEFORE%| %URLPARAM{"comment" newline="<br />" encode="$encodeguest"}% | %WIKIUSERNAME% | %SERVERTIME% |
%TMPL:END%
</verbatim>

%ICON{"hand"}% See rendered template [[%SANDBOXWEB%.CommentPluginExamples#tableappend][tableappend]]




---++++ after: Add before the comment box, after the last comment
<verbatim>
%TMPL:DEF{PROMPT:after}%%TMPL:P{promptbox}%%TMPL:END%
</verbatim>
<verbatim>
%TMPL:DEF{OUTPUT:after}%%NOP%%TMPL:P{outputoneliner}%
%POS:BEFORE%%TMPL:END%
</verbatim>

%ICON{"hand"}% See rendered template [[%SANDBOXWEB%.CommentPluginExamples#after][after]]




---++++ action
Action added to action table directly above comment box
(requires Foswiki:Extensions/ActionTrackerPlugin)
<verbatim>
%TMPL:DEF{PROMPT:action}%

%TABLE{tableborder="0" cellborder="0"}%
|        <label for="action_who">Action for</label>| <input class="foswikiInputField" name="action_who" id="action_who" type="text" size="50" value="%URLPARAM{"who"}%" /> |
| <label for="action_due">Due date</label>| <input class="foswikiInputField" name="action_due" id="action_due" type="text" size="30" value="%URLPARAM{"due"}%" /> |
|    <label for="action_comment">Comment</label>| <textarea %DISABLED% rows="%rows|3%" cols="%cols|50%" name="action_comment" id="action_comment" class="foswikiInputField commentPluginPromptBox" onfocus="if(this.value=='%MESSAGE%')this.value=''" onblur="if(this.value=='')this.value='%MESSAGE%'">%MESSAGE%</textarea> |
|| <input %DISABLED% type="button" class="foswikiButton %TMPL:P{ajax}%" value="Add action" /> |
%TMPL:END%
</verbatim>
<verbatim>
%TMPL:DEF{OUTPUT:action}%%POS:BEFORE%%AC%NOP%TION{who="%URLPARAM{"action_who" encode="$encodeguest"}%" due="%URLPARAM{"action_due" encode="$encodeguest"}%"}% %URLPARAM{"action_comment" encode="$encodeguest"}%<br />- Created by %WIKIUSERNAME%, %SERVERTIME%%ENDACTION%
%TMPL:END%
</verbatim>

%ICON{"hand"}% See rendered template [[%SANDBOXWEB%.CommentPluginExamples#action][action]]




---++++ table
Tablerows adding on end
<verbatim>
%TMPL:DEF{PROMPT:table}%
%TABLE{tableborder="0" cellborder="0"}%
|        <label for="comment_date">Date</label>| <input class="foswikiInputField" %DISABLED% type="text" size="40" name="comment_date" id="comment_date" /> |
|        <label for="comment_city">City</label>| <input class="foswikiInputField" %DISABLED% type="text" size="40" name="comment_city" id="comment_city" value="" /> |
|| <input %DISABLED% type="button" class="foswikiButton %TMPL:P{ajax}%" value="%button|Add entry%" /> |
%TMPL:END%
</verbatim>
<verbatim>
%TMPL:DEF{OUTPUT:table}%%POS:BEFORE%| %URLPARAM{"comment_date" encode="$encodeguest"}% | %WIKIUSERNAME% | %URLPARAM{"comment_city" encode="$encodeguest"}% |
%TMPL:END%
</verbatim>

%ICON{"hand"}% See rendered template [[%SANDBOXWEB%.CommentPluginExamples#table][table]]




---++++ toctalk
Talk using TOC adding on end
<verbatim>
%TMPL:DEF{PROMPT:toctalk}%
%TABLE{tableborder="0" cellborder="0"}%
|        <label for="comment_summary">Summary</label>| <input class="foswikiInputField" %DISABLED% type="text" size="40" name="comment_summary" id="comment_summary" /> |
|        <label for="toctalk_comment_text">Message</label>| <textarea %DISABLED% rows="%rows|3%" cols="%cols|50%" name="toctalk_comment_text" id="toctalk_comment_text" class="foswikiInputField commentPluginPromptBox" onfocus="if(this.value=='%MESSAGE%')this.value=''" onblur="if(this.value=='')this.value='%MESSAGE%'">%MESSAGE%</textarea> |
|| <input %DISABLED% type="button" value="%button|Add%" class="foswikiButton %TMPL:P{ajax}%" /> |
%TMPL:END%
</verbatim>
<verbatim>
%TMPL:DEF{OUTPUT:toctalk}%
%POS:BEFORE%---++++ %SERVERTIME% %WIKIUSERNAME%: %URLPARAM{"comment_summary" encode="$encodeguest"}%
%POS:BEFORE%%URLPARAM{"toctalk_comment_text" encode="$encodeguest"}%
%POS:BEFORE%
%TMPL:END%
</verbatim>

%ICON{"hand"}% See rendered template [[%SANDBOXWEB%.CommentPluginExamples#toctalk][toctalk]]




---++++ bookmark
Create a list of annotated bookmarks
<verbatim>
%TMPL:DEF{PROMPT:bookmark}%
%TABLE{tableborder="0" cellborder="0"}%
|        <label for="comment_url">Url</label>| <input class="foswikiInputField" %DISABLED% type="text" size="40" name="comment_url" id="comment_url" value="http://" /> |
| <label for="comment_link">Link label</label>| <input class="foswikiInputField" %DISABLED% type="text" size="40" name="comment_link" id="comment_link" /> |
|    <label for="bookmark_comment_text">Comment</label>| <input class="foswikiInputField" %DISABLED% type="text" size="40" name="bookmark_comment_text" id="bookmark_comment_text" value="%MESSAGE%" /> |
|| <input %DISABLED% type="button" value="%button|Add bookmark%" class="foswikiButton %TMPL:P{ajax}%" /> |
%TMPL:END%
</verbatim>
<verbatim>
%TMPL:DEF{OUTPUT:bookmark}%%POS:BEFORE%   * [[%URLPARAM{"comment_url" encode="entity"}%][%URLPARAM{"comment_link" encode="entity"}%]] %IF{" '%URLPARAM{"bookmark_comment_text" encode="entity"}%' = '' " then="" else="- "}%%URLPARAM{"bookmark_comment_text" encode="entity"}%
%TMPL:END%
</verbatim>

%ICON{"hand"}% See rendered template [[%SANDBOXWEB%.CommentPluginExamples#bookmark][bookmark]]




---++++ return
Post to a different topic and return to here. The comment =target= is set in the =PROMPT=. In the form below the =redirectto= is set to the current (including) topic.

<verbatim>
%TMPL:DEF{return_promptbox}%
<input type="hidden" name="redirectto" value="%BASEWEB%.%BASETOPIC%" />
%TMPL:P{promptbox}%
%TMPL:END%
</verbatim>
<verbatim>
%TMPL:DEF{PROMPT:return}%%TMPL:P{return_promptbox}%%TMPL:END%
</verbatim>
<verbatim>
%TMPL:DEF{OUTPUT:return}%%POS:BEFORE%%TMPL:P{OUTPUT:threadmode}%%TMPL:END%
</verbatim>

%ICON{"hand"}% See rendered template [[%SANDBOXWEB%.CommentPluginExamples#return][return]]


---++ Include !UserComments

Including UserCommentsTemplate ("Template" gets automatically appended to the name):

%TMPL:INCLUDE{"UserComments"}%
%META:PREFERENCE{name="ALLOWTOPICVIEW" title="ALLOWTOPICVIEW" type="Set" value="*"}%
