Remove All Anonymous Comments

Last modified by Vincent Massol on 2014/11/27 14:53

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

Jean-Vincent Drean

Rating
Rate!
0 Votes
LicenseGNU Lesser General Public License 2.1

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}}

Prerequisites & Installation Instructions

Copy the code snippet to a page and save it.

Created by Jean-Vincent Drean on 2011/11/02 15:10
     

Get Connected