Rename Space Page Snippet

This snippet shows a convenient way to move/rename all pages from a space into another.

It shows also how to receive input from the user.

The rename functionality is available starting XWiki Enterprise 1.0B6. This snippet was tested with XWiki Enterprise 1.0B6. However several bugs have been fixed on the rename feature and we recommend using 1.0 RC1 or above.

Just copy the snippet into a new page.

Code

1 Rename Space

#if($request.space)
  #if("doRename"==$request.op)
    #set($space=$request.space)
    #foreach($item in $xwiki.getSpaceDocsName($request.space))
      $xwiki.getDocument("${space}.${item}").rename("${request.newname}.${item.replace('.','_')}")
    #end
1.1 Renamed space $space to $request.newname

[Cancel>$doc.fullName]

  #end

  #if("listRename"==$request.op)
    #set($space=$request.space)
1.1 Renaming space $space to $request.newname
    #foreach($item in $xwiki.getSpaceDocsName($request.space))
* Renaming $space.$item to ${request.newname}.${item.replace('.','_')}
    #end

[Confirm>$doc.fullName?space=$space&newname=$request.newname&op=doRename]
[Cancel>$doc.fullName]

  #end

  #if("getNewName"==$request.op)

Renaming $request.space

1.1 Renaming ${request.space}

<form method="post" action="$doc.getURL("view", "")" onsubmit="cancelCancelEdit()">
<div class="padded centered">
<input type="hidden" name="space" value="${request.space}" />
<input type="hidden" name="op" value="listRename" />
Enter new name for the space:  
<input type="text" name="newname" value="${request.space}" class="panelinput" style="margin:auto;" onfocus="if(this.value=='Title') this.value=''" onblur="if(this.value=='') this.value='Title'"/>
</div>
<div class="padded centered" style="text-align:center;">
<input type="submit" class="button" style="margin:auto;" value="Rename"/>
</div>
</form>

[Cancel>$doc.fullName]

  #end
#else
{table}
Space | Action
#foreach($space in $xwiki.spaces)
$space | [Rename>$doc.fullName?space=${space}&op=getNewName]
#end
{table}
#end
Version 4.1 last modified by VincentMassol on 26/02/2008 at 09:01

Comments 1

jeremi | 25.07.2007 at 09:02 AM
I think this script needs to be reviewed, Zurück is not english and
table: TableMacro: missing table content
tags are missing in the last else.

Attachments 0

No attachments for this document

Creator: gleeb on 2007/04/19 20:29
This wiki is licensed under a Creative Commons license
1.4.1.10194