Remove All Anonymous Comments

Last modified by Vincent Massol on 2021/03/18 11:29

cogRemove all anonymous comments from all pages in the current wiki
TypeSnippet
Category
Developed by

Jean-Vincent Drean

Rating
LicenseGNU Lesser General Public License 2.1

Table of contents

Description

{{velocity}}
#set($confirm = ("$!request.confirm" == '1'))
#foreach($item in $xwiki.searchDocuments(", BaseObject obj where doc.fullName = obj.name and obj.className='XWiki.XWikiComments'"))
  #set($commentedDoc = $xwiki.getDocument($item))
  #set($dirty = false)
  #foreach($comment in $commentedDoc.getObjects('XWiki.XWikiComments'))
    #if(!$comment.get('author').startsWith('XWiki.'))
     * $item - $comment.getNumber() - $comment.get('author')
      #if($confirm)
        #set($discard = $commentedDoc.removeObject($comment))
        #set($dirty = true)
      #end
    #end
  #end
  #if($dirty)
   * Saving $commentedDoc
    #set($discard = $commentedDoc.save('Removed spam comments'))
  #end
#end
{{/velocity}}

Get Connected