cogProvides a UI to rename tags from the wiki
Developed by

Bruno Neves

Rating
Rate!
0 Votes
LicenseGNU Lesser General Public License 2.1

Description

An equivalent feature is available in XWiki. See the Tag Application.

This snippet will let you rename all the tags with a specific name at once.

Follow these steps:

  • Create a new wiki page
  • Edit it and save it with the present code
  • Insert the name of the tag you want to change
  • Insert the new name
  • Submit

Code

1 Rename Tags

<form name="input" action="$xwiki.getURL("Main.Rename Tags", "view")" method="get">
    Tag to replace:
   <input type="text" name="tag1">
    New tag:
   <input type="text" name="tag2">
   <input type="submit" value="Submit">
</form>

[All Tags>Main.Tags]

#set ($tagToReplace = "")
#set ($newTag = "")

#if ($request.tag1)
    #set ($tagToReplace = $request.tag1)
#end
#if($request.tag2)
    #set ($newTag = $request.tag2)
#end

#if(($tagToReplace!="")||($newTag!=""))
    #set ($taggedDocs = $xwiki.searchDocuments(", BaseObject obj where doc.fullName=obj.name and obj.className='XWiki.TagClass'"))
   <table>
       <tr>
           <th>Results</th>
       </tr>
       <tr>
           <td>
                #foreach ($taggedDocName in $taggedDocs)
                    #set ($taglist = "")
                    #set ($taggedDoc = $xwiki.getDocument($taggedDocName))
                    #set ($taglist = $taggedDoc.getObject("XWiki.TagClass").get("tags"))
                    #if ($taglist.contains($tagToReplace)) $taggedDoc.getObject("XWiki.TagClass").set("tags", $taglist.replaceAll("(^| +)$tagToReplace( +|$)", "$1$newTag$2"))
                        * [$taggedDoc.fullName] : replacing tag "$tagToReplace" by "$newTag"
                        #set ($discard = $taggedDoc.save())
                    #end
                #end
           </td>
       </tr>
   </table>
#end

Result

RenameTags.png

Prerequisites & Installation Instructions

Copy the code snippet to a page and save it.

Created by Bruno Neves on 2008/09/08 14:16
     

Get Connected