#* * commentsinline.vm Shows document comments and gives the user an oppertunity to add a comment. * To include this template in a document you may specify: * * $replyTo (Integer) - If set then the comment form will appear ready to make a reply to the comment with the id number given. * If not set and request parameter 'replyto' is set then $replyTo is set to parameter 'replyto', if * no replyto request parameter and $replyTo isn't set, and $fillInFields is true and * 'XWiki.XWikiComments_replyto' is set then $replyTo is set to that. * * $hideCaptcha (boolean) - If true then the captcha is hidden and then shown by javascript when the user focuses on the comment * textarea. If not set and $captchaAnswerWrong is true or 'X-Requested-With' equals 'XMLHttpRequest' then * it is set true. * * $captchaAnswerWrong (boolean) - If true then a message is displayed next to the captcha window telling the user that the captcha * answer is incorrect. If not set then this template will check for a request parameter by the same * name and sets this true if that equals 1. * * $fillInFields (boolean) - If true then author, and comment fields are filled in from request parameters of the same names * as the fields, also if $replyTo is set the form appears under the comment corrisponding to the $replyTo * number. If not set and $captchaAnswerWrong is true then this is set to true. * * $offerGuestsCaptcha (boolean) - If true then users who are not logged in are offered a captcha image to solve, if undefined then * $xwiki.getSpacePreference('guest_comment_requires_captcha') NOTE: this template doesn't have the power * to require the captcha (that is the commentAdd action) only offer it. * *### ## ## These are used when this page is accessed directly but are useless when the page is pulled in with ajax using ## bin/view/Space/Page?xpage=xpart&vm=commentsinline.vm $xwiki.jsfx.use('uicomponents/viewers/comments.js', {'forceSkinAction': true, 'language': ${xcontext.language}}) $xwiki.ssfx.use('uicomponents/viewers/comments.css', true) ## ##--------------------------------------------------------------------- ## Set some 'global' variables ##--------------------------------------------------------------------- ## #set($xCommentClass = 'XWiki.XWikiComments') ## #if(!$replyTo) #set($replyTo = $escapetool.xml($!request.get('replyto'))) #end ## #set($requestedByAjax = ($request.getHeader('X-Requested-With') == 'XMLHttpRequest')) ## #if("$!captchaAnswerWrong" == '') #set($captchaAnswerWrong = ($request.get('captchaAnswerWrong') == '1')) #end ## #if("$!hideCaptcha" == '') #set($hideCaptcha = ($captchaAnswerWrong != true && $requestedByAjax)) #end ## #if("$!fillInFields" == '') #set($fillInFields = ($captchaAnswerWrong == true)) #end ## ## If $fillInFields, then set variables for each field. #if($fillInFields) #set($author = $!escapetool.xml($request.get("${xCommentClass}_author"))) #set($comment = $!escapetool.xml($request.get("${xCommentClass}_comment"))) #if("$!replyTo" == '') #set($replyTo = $escapetool.xml($!request.get("${xCommentClass}_replyto"))) #end #end ## #if("$!author" == '') #set($author = $services.localization.render('core.viewers.comments.add.guestName.default')) #end ## #set($xredirect = $!escapetool.xml($request.get("xredirect"))) #if("$!xredirect" == '') #set($xredirect = "$doc.getURL('view')?$request.getQueryString()") #end ## #if("$!offerGuestsCaptcha" == '') #set($offerGuestsCaptcha = $xwiki.getSpacePreferenceAsInt('guest_comment_requires_captcha', 0) == 1) #end ## ##--------------------------------------------------------------------- ## Macros ##--------------------------------------------------------------------- ## ## If we are viewing this page through the commentAdd or save actions then we should redirect to view ## This doesn't apply if it is being viewed through javascript. #macro(redirectIfActionNotView) #if(!$requestedByAjax && $xcontext.getAction() != 'view' && $xcontext.getAction() != 'get') #if(!$captchaAnswerWrong) $response.sendRedirect("$doc.getURL('view')?viewer=comments"); #else #foreach($name in $request.getParameterNames()) #set($queryString = "$!queryString&$name=$escapetool.url($request.get($name))") #end $response.sendRedirect($doc.getURL('view', "captchaAnswerWrong=1&$queryString")); #end $response.setContentLength(0) #stop #end #end ## ## ## #macro(addCommentToThreads $comment $commentThreads $rootKey) #set($thread = $commentThreads.get("$!{comment.replyto}")) #if("$!{thread}" == '') #set($thread = $commentThreads.get($rootKey)) #end #set($discard = $thread.add($comment.number)) #set($thread = '') #end ## ## ## #macro(displayThread $key $commentThreads, $commentDoc) ## If request parameter replyto is specified then we show the form under that comment. #if($replyTo == "$key") #displayCommentForm() #set($replied = true) #end ## #set($thread = $commentThreads.get("$!key")) #if($thread.size() > 0) #end #end ## ## ## #macro(displayComment $comment, $commentDoc) ## if the current comment is an annotation (i.e. has selection) set a flag to display selection, and add a few classes #set($commentSelection = $comment.getProperty('selection').value) #set($isAnnotation = false) #if ("$!commentSelection" != "") #set($isAnnotation = true) #end
#if("$!comment.replyto" == '')#mediumUserAvatar($comment.author)#{else}#smallUserAvatar($comment.author)#end
$!xwiki.getUserName($doc.display('author', 'view', $comment))## #set($date = $comment.getProperty('date').value) ## Don't indent, otherwise the comma will be misplaced #if($date), $!xwiki.formatDate($date)#end
#if($xwiki.hasAccessLevel('comment')) #if($comment.author == $xcontext.user && $hasEdit) $services.localization.render('core.viewers.comments.edit') #end #end #if ($hasAdmin || (!$isGuest && $hasEdit && $comment.author == $xcontext.user)) $services.localization.render('core.viewers.comments.delete') #end ## commenttools
## commentheader #if ($isAnnotation)
$!escapetool.xml($commentSelection)
#end
$commentDoc.getRenderedContentRestricted($comment.getProperty('comment').getValue(), $doc.getSyntax().toIdString())
## xwikicomment #end ## ## ## #macro(displayCommentForm) #if($xwiki.hasAccessLevel('comment')) ##!!!
$services.localization.render('core.viewers.comments.add.title') ##!!!
#mediumUserAvatar($context.user)
#if($xcontext.user != 'XWiki.XWikiGuest') #else $services.localization.render('login') #end ## CSRF prevention
#if($xcontext.user == 'XWiki.XWikiGuest' && $offerGuestsCaptcha) #displayCaptcha() #end
##!!!$services.localization.render('core.viewers.comments.add.cancel')
#end #end ## ## ## #macro(displayCaptcha)
## We only want to hide the captcha if we're sure the user has javascript, if this is an ajax call then it's a safe bet. #if($hideCaptcha) #else $services.localization.render("core.captcha.image.alternateText") #end

#if($captchaAnswerWrong) $services.localization.render('core.captcha.captchaAnswerIsWrong') #end
#end ## ## ## #macro(displayEditCommentForm $comment) #if (${comment.author} == ${xcontext.user})
#if("$!comment.replyto" == '')#mediumUserAvatar($comment.author)#{else}#smallUserAvatar($comment.author)#end
$!xwiki.getUserName($doc.display('author', 'view', $comment))## ## Don't indent, otherwise the comma will be misplaced #set($date = $comment.getProperty('date').value)## #if($date), $!xwiki.formatDate($date)#end
## commentheader
$doc.display('comment', 'edit', $comment)
$services.localization.render('core.viewers.comments.edit.cancel')
## xwikicomment
#else $response.setStatus(403) ## forbidden #error($services.localization.render('core.viewers.comments.edit.notAllowed')) #end #end ## ##--------------------------------------------------------------------- ## Code ##--------------------------------------------------------------------- ## #redirectIfActionNotView() #set($commentNumber = "$!{request.number}") #if($commentNumber != '') #set($commentNumber = $mathtool.toInteger($commentNumber)) #set($comment = $doc.getObject($xCommentClass, $commentNumber)) #if("$!{comment}" != '') #if ("$!{request.xpage}" == '')
#end #displayEditCommentForm($comment) #if ("$!{request.xpage}" == '')
#end #else $response.setStatus(404) ## Comment not found #error($services.localization.render('core.viewers.comments.edit.notFound')) #end #else #if($xwiki.getSpacePreferenceAsInt('commentsorder', 1) == 1) #set($comments = $doc.getComments()) #else #set($comments = $doc.getComments(false)) #end ## ##
#if($comments.size() > 0) #set($rootKey = "-1") #set($commentThreads = {}) #set($discard = $commentThreads.put($rootKey, [])) #foreach($comment in $comments) #set($discard = $commentThreads.put("${comment.number}", [])) #end #foreach($comment in $comments) #addCommentToThreads($comment, $commentThreads, $rootKey) #end ## ## Comments will be rendered in the context of this document. #set($commentDoc = $doc) ## #displayThread($rootKey, $commentThreads, $commentDoc) #else

$services.localization.render('core.viewers.comments.noComments')

#end ## ## #if(!$replied) #displayCommentForm() #end
## comments
## commentscontent #end ## comment == ''