Delete Space
Last modified by Vincent Massol on 2022/05/03 17:15
Lists all spaces in a wiki and provides links to delete each space |
Type | Snippet |
Category | |
Developed by | |
Rating | |
License | GNU Lesser General Public License 2.1 |
Table of contents
Description
Code
Version 1
This version doesn't require programming rights (just delete rights on pages to be deleted) but will not delete hidden pages.
In XWiki Syntax 2.0:
{{velocity}}
#if ($request.space)
#if ($request.confirm == "1")
#foreach ($item in $xwiki.getSpaceDocsName($request.space))
#set($itemRef = $services.model.createDocumentReference($context.getDatabase(), ${request.space}, $item))
* Deleting $item $xwiki.getDocument(${itemRef}).delete()\\
#end
#else
#set($spaceName = $escapetool.url($request.space))
[[Confirm delete space ${request.space}>>$doc.fullName?space=${spaceName}&confirm=1]]:
#foreach ($item in $xwiki.getSpaceDocsName($request.space))
* $item
#end
#end
#else
|=Space|=Action
#foreach($space in $xwiki.spaces)
#set($spaceName = $escapetool.url($space))
|$space|[[Index>>Main.SpaceIndex?space=${spaceName}]] - [[Delete>>$doc.fullName?space=${spaceName}]]
#end
#end
{{/velocity}}
#if ($request.space)
#if ($request.confirm == "1")
#foreach ($item in $xwiki.getSpaceDocsName($request.space))
#set($itemRef = $services.model.createDocumentReference($context.getDatabase(), ${request.space}, $item))
* Deleting $item $xwiki.getDocument(${itemRef}).delete()\\
#end
#else
#set($spaceName = $escapetool.url($request.space))
[[Confirm delete space ${request.space}>>$doc.fullName?space=${spaceName}&confirm=1]]:
#foreach ($item in $xwiki.getSpaceDocsName($request.space))
* $item
#end
#end
#else
|=Space|=Action
#foreach($space in $xwiki.spaces)
#set($spaceName = $escapetool.url($space))
|$space|[[Index>>Main.SpaceIndex?space=${spaceName}]] - [[Delete>>$doc.fullName?space=${spaceName}]]
#end
#end
{{/velocity}}
In XWiki Syntax 1.0:
1 Delete Space
#if ($request.space)
#if ($request.confirm == "1")
#foreach ($item in $xwiki.getSpaceDocsName($request.space))
#set($itemRef = $services.model.createDocumentReference($context.getDatabase(), ${request.space}, $item))
* Deleting $item $xwiki.getDocument(${itemRef}).delete()
#end
#else
#set($spaceName = $escapetool.url($request.space))
[Confirm delete space ${request.space}>$doc.fullName?space=${spaceName}&confirm=1]
1.1 List of docs that will be deleted
#foreach ($item in $xwiki.getSpaceDocsName($request.space))
* $item
#end
#end
#else
{table}
Space | Action
#foreach($space in $xwiki.spaces)
#set($spaceName = $escapetool.url($space))
$space | [Index>Main.SpaceIndex?space=${spaceName}] - [Delete>$doc.fullName?space=${spaceName}]
#end
{table}
#end
#if ($request.space)
#if ($request.confirm == "1")
#foreach ($item in $xwiki.getSpaceDocsName($request.space))
#set($itemRef = $services.model.createDocumentReference($context.getDatabase(), ${request.space}, $item))
* Deleting $item $xwiki.getDocument(${itemRef}).delete()
#end
#else
#set($spaceName = $escapetool.url($request.space))
[Confirm delete space ${request.space}>$doc.fullName?space=${spaceName}&confirm=1]
1.1 List of docs that will be deleted
#foreach ($item in $xwiki.getSpaceDocsName($request.space))
* $item
#end
#end
#else
{table}
Space | Action
#foreach($space in $xwiki.spaces)
#set($spaceName = $escapetool.url($space))
$space | [Index>Main.SpaceIndex?space=${spaceName}] - [Delete>$doc.fullName?space=${spaceName}]
#end
{table}
#end
Version 2
This version requires programming rights and will delete all documents including hidden ones.
XWiki Syntax 2.0
{{velocity}}
#if ($request.space)
#if ($request.confirm == "1")
#foreach ($item in $xwiki.search("select doc.fullName from XWikiDocument doc where doc.space = '$request.space'"))
#set($itemRef = $services.model.resolveDocument($item))
* Deleting $item $xwiki.getDocument($itemRef).delete()\\
#end
#else
#set($spaceName = $escapetool.url($request.space))
[[Confirm delete space ${request.space}>>$doc.fullName?space=${spaceName}&confirm=1]]:
#foreach ($item in $xwiki.search("select doc.fullName from XWikiDocument doc where doc.space = '$request.space'"))
* $item
#end
#end
#else
|=Space|=Action
#foreach($space in $xwiki.spaces)
#set($spaceName = $escapetool.url($space))
|$space|[[Index>>Main.SpaceIndex?space=${spaceName}]] - [[Delete>>$doc.fullName?space=${spaceName}]]
#end
#end
{{/velocity}}
#if ($request.space)
#if ($request.confirm == "1")
#foreach ($item in $xwiki.search("select doc.fullName from XWikiDocument doc where doc.space = '$request.space'"))
#set($itemRef = $services.model.resolveDocument($item))
* Deleting $item $xwiki.getDocument($itemRef).delete()\\
#end
#else
#set($spaceName = $escapetool.url($request.space))
[[Confirm delete space ${request.space}>>$doc.fullName?space=${spaceName}&confirm=1]]:
#foreach ($item in $xwiki.search("select doc.fullName from XWikiDocument doc where doc.space = '$request.space'"))
* $item
#end
#end
#else
|=Space|=Action
#foreach($space in $xwiki.spaces)
#set($spaceName = $escapetool.url($space))
|$space|[[Index>>Main.SpaceIndex?space=${spaceName}]] - [[Delete>>$doc.fullName?space=${spaceName}]]
#end
#end
{{/velocity}}
Result