Rename Space

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

cogRename all pages in a space
TypeSnippet
Category
Developed by

Vincent Massol

Rating
1 Votes
LicenseGNU Lesser General Public License 2.1

Description

If you have XWiki 7.2M1+ you just need to use the Refactoring Script service.

For example:

{{velocity}}
#set ($source = $services.model.resolveSpace('Path.To.Source'))
#set ($destination = $services.model.resolveSpace('Path.To.New.Parent'))
$services.refactoring.move($source, $destination).join()
{{/velocity}}

Old XWiki Versions

If you're on XWiki < 7.2M1 read on...

This script uses the rename feature on page (it just loops over all pages in a space) and thus has the same limitations as the standard rename.

  • The rights on the renamed space are the default rights. This script does not keep rights on the space
  • This script doesn't work for Nested Pages but starting with XWiki 8.x this feature is built in (Move/Rename page with children).

Code in XWiki Syntax 2.0

Works in XWiki versions 2.3 and above.

{{velocity}}
= Rename space =

#if($request.action == 'rename')
  #if($request.from && $request.to)
    Renamings:
    #foreach($item in $xwiki.getSpaceDocsName($request.from))
      #set ($fromReference = $services.model.createDocumentReference("", $request.from, $item))
      #set ($toReference = $services.model.createDocumentReference("", $request.to, $item))
      * Renamed [$services.model.serialize($fromReference)] to [[$services.model.serialize($toReference)]]
      #set($ok = $xwiki.getDocument($fromReference).rename($toReference))
    #end
  #end
#end

{{html wiki='true'}}
<form action="$doc.getURL()" method="post" class="xform third">
  <input type="hidden" name="action" value="rename" />
  <div class="xform">
  <dl>
    <dt>Source space:</dt>
    <dd><select name="from">
      <option value="">please select</option>
      #foreach($space in $xwiki.getSpaces())
      <option value="$escapetool.xml($space)">$escapetool.xml($space)</option>
     #end
    </select></dd>
   <dt>New space:</dt>
   <dd><input type="text" name="to" value=""/></dd>
  </dl>
  </div>
  <div class="buttons">
    <input type="submit" value="Rename" class="button" />
  </div>
</form>
{{/html}}
{{/velocity}}

Result

Screen copy of the result page with the velocity Code in XWiki Syntax 2.0:

renameSpace.png

Tags:
     

Get Connected