Changes for document DeletePageWithSlash

From version 3.5
edited by Support
on 2018/08/23 14:30
To version 4.1
edited by Support
on 2018/08/23 14:31
Change comment: Rollback to version 2.1

Summary

Details

Page properties
Content
... ... @@ -1,96 +1,24 @@
1 1  {{velocity}}
2 -This script allows to programmatically delete a page whose URL is not accessible (since the regular delete is an action, the URL to the page needs to be accessible in order to delete the page).
3 -The script is using regular authorization mechanism, so the page will be deleted only if the current user has the "delete" right on the page in question. Use at your own risk!
4 -
5 -#if("$!request.action" != 'dodelete')
6 - {{html clean="false"}}
7 - <form class="xform" method='get' action="">
8 - <dl>
9 - <dt>
10 - <label for="spacename">Space</label>
11 - <div class="xHint">Fill in the name of the space of the page (all path to the page separated by dot). For nested pages, this needs to be the full name of the page, and the pagename (under) will be WebHome.</div>
12 - </dt>
13 - <dd><input name="spacename" id="spacename" type="text"></input></dd>
14 - <dt>
15 - <label for="pagename">Page</label>
16 - <div class="xHint">Fill in the name of the page. For nested pages, this needs to be WebHome.</div>
17 - </dt>
18 - <dd><input name="pagename" id="pagename" type="text"></input></dd>
19 - </dl>
20 - <div class="buttonwrapper">
21 - <input name="action" type='hidden' value='dodelete' />
22 - <input type="submit" class="button primary" name="dosubmit" value="Preview delete" /> <a href="$escapetool.xml($doc.getURL())" class="button secondary">Cancel</a>
23 - </div>
24 - </form>
25 - {{/html}}
2 +#if ("$!request.documentsToFix" != "")
3 + #set($documentsList = $request.getParameterValues('documentsToFix'))
4 + #foreach($documentName in $documentsList)
5 + #set($pageReference = $services.model.resolveDocument($documentName))
6 + #set($newPageReference = $services.model.createDocumentReference($pageReference.wikiReference.name, $pageReference.lastSpaceReference.name, $pageReference.name.replaceAll('/', ' ').replaceAll('\\', ' ')))
7 + * renaming $documentName : $xwiki.getDocument($pageReference).rename($newPageReference)
8 + #end
26 26  #else
27 - ## check if form is confirmed
28 - #set($isConfirmed = false)
29 - #if ("$!request.confirmed" == 'true')
30 - #set($isConfirmed = true)
10 + #set($pagesWithSlash = $xwiki.searchDocuments("where doc.name like '%/%' or doc.name like '%\\%'"))
11 + {{html}}
12 + <form action="" method="post">
13 + <ul>
14 + #foreach($page in $pagesWithSlash)
15 + #set($pageReference = $services.model.resolveDocument($page))
16 + #set($newPageReference = $services.model.createDocumentReference($pageReference.wikiReference.name, $pageReference.lastSpaceReference.name, $pageReference.name.replaceAll('/', ' ').replaceAll('\\', ' ')))
17 + <li> <input type="checkbox" name="documentsToFix" value="$escapetool.xml($services.model.serialize($pageReference, 'default'))">$page -> $services.model.serialize($newPageReference, 'default')</input></li>
31 31   #end
32 - ## fetch the page to delete to see if it exists and it if has children
33 - #set($spacename = "$!request.spacename")
34 - #set($pagename = "$!request.pagename")
35 - #if ($spacename != '' && $pagename != '')
36 - #set($spaceToDeleteRef = $services.model.resolveSpace($spacename))
37 - #set($docToDeleteRef = $services.model.createDocumentReference($pagename, $spaceToDeleteRef))
38 - #set($docToDelete = $xwiki.getDocument($docToDeleteRef))
39 - #set($docExists = !($docToDelete.isNew()))
40 - |**Reference**|$docToDeleteRef
41 - |**Document**|$docToDelete
42 - |**Document exists**|$docExists
43 - ## check the children of this document and list them, if it's the case
44 - #if ($pagename == 'WebHome')
45 - #set($queryParams = [])
46 - #set($discard = $queryParams.add("$!{spacename}.%"))
47 - #set($discard = $queryParams.add("$!{spacename}.WebHome"))
48 - #set($query = $services.query.hql("WHERE doc.fullName LIKE ? AND doc.fullName <> ? ORDER BY doc.fullName asc").addFilter('unique').bindValues($queryParams))
49 - #set($docToDeleteChildren = $query.execute())
50 - #if ($docToDeleteChildren.size() > 0)
51 - |**Children**|((({{warning}}Attention, the children will not be deleted!{{/warning}}
52 -
53 - #foreach($docChild in $docToDeleteChildren)
54 - #if ($velocityCount <= 10)
55 - * $docChild
56 - #else
57 - * ...and $mathtool.sub($docToDeleteChildren.size(), 10) more
58 - #break
59 - #end
60 - #end
61 - )))
62 - #end
63 - #end
64 -
65 - ##
66 - ## the confirmation form or perform, once all this information was displayed
67 - ##
68 - #if ($docExists)
69 - #if(!$isConfirmed)
70 - ## delete is not confirmed, display the confirm form, hidden
71 - {{html clean="false"}}
72 - <form class="xform" method="post" action="">
73 - <div class="hidden">
74 - <input name="spacename" value="$escapetool.xml($spacename)" type='hidden'/>
75 - <input name="pagename" value="$escapetool.xml($pagename)" type='hidden'/>
76 - <input name="action" value="dodelete" type='hidden' />
77 - <input name="confirmed" value="true" type="hidden" />
78 - </div>
79 - <div class="buttonwrapper">
80 - <input type="submit" class="button primary" name="dosubmit" value="Delete" /> <a href="$escapetool.xml($doc.getURL())" class="button secondary">Cancel</a>
81 - </div>
82 - </form>
83 - {{/html}}
84 - #else
85 - ## delete is confirmed, delete the document and display a message
86 - #set($discard = $docToDelete.delete())
87 - {{success}}The document was successfully deleted.{{/success}}
88 - #end
89 - #else
90 - {{warning}}The document that you're trying to delete does not exist, nothing will be done.{{/warning}}
91 - #end
92 - #else
93 - {{error}}The space name or the page name are not filled in. In case of doubt for the page name (because nested page), use WebHome.{{/error}}
94 - #end
19 + </ul>
20 + <input type="submit" class="button" value="Rename" />
21 + </form>
22 + {{/html}}
95 95  #end
96 96  {{/velocity}}
This wiki is licensed under a Creative Commons 2.0 license
XWiki Enterprise 7.1.4 - Documentation