X-Git-Url: https://git.plutz.net/?a=blobdiff_plain;ds=sidebyside;f=handlers%2F60_move_rename_delete.sh;h=27246bd108acecac61ba2d7dc17406979aa2272d;hb=e1441ae3543689244e9275c0581ad6c00d610f67;hp=84db9e4d1a5459c03830c14f6960a5c015425f30;hpb=ebac44302c70e36c951e77f0c5496c74bee547ee;p=shellwiki
diff --git a/handlers/60_move_rename_delete.sh b/handlers/60_move_rename_delete.sh
index 84db9e4..27246bd 100755
--- a/handlers/60_move_rename_delete.sh
+++ b/handlers/60_move_rename_delete.sh
@@ -85,20 +85,40 @@ l10n_deletepage >/dev/null 2>&1 \
Delete Page
$(HTML "${page}")
This page and its attachments will be deleted
+
- - Past revisions of the page text (including the current one) will remain accessible and can be restored.
- - Attachments will be deleted completely, and cannot be restored.
- - Subpages will not be affected and can still be accessed normally.
+ EOF
+ [ "$REV_PAGES" = true ] \
+ && printf ' - Past revisions of the page text (including the current one) will remain accessible and can be restored.
'
+ [ "$REV_PAGES" = true -a "$REV_ATTACHMENTS" = true ] \
+ && printf ' - Attachments can be restored as well.
' \
+ || printf ' - Attachments will be deleted completely, and cannot be restored.
'
+ cat <<-EOF
+ - Subpages will not be affected and can still be accessed normally.
EOF
}
+list_writable() {
+ local PATH_INFO page="${1%/}/"
+
+ if acl_write "$page"; then
+ PATH_INFO="$page"
+ page_glob "*" 0 \
+ | while read page; do
+ list_writable "${PATH_INFO}${page}"
+ done
+ printf %s\\n "$page" |debug
+ fi
+}
+
if [ "$REQUEST_METHOD" = POST ]; then
action="$(POST action)"
newname="$(POST newname |grep -m1 -xE '[^#/]*')"
newlocation="$(POST newlocation |grep -m1 -xE '/[^#]*')"
+ delsub="$(POST delete_subpages |grep -m1 -xE 'true|false')"
else case "${PATH_INFO}" in
*/\[move\])
location="${page%/}" location="${location%/*}/"
@@ -138,7 +158,7 @@ if [ "$action" = rename -a "$newname" ]; then
if [ -d "$_DATA/pages/$newname" ]; then
printf 'Refresh: %i\r\n' 4
- export ERRORMSG="A location of that name already exists."
+ export ERROR_MSG="A location of that name already exists."
theme_error 400
return 0
elif ! acl_write "$oldname" || ! acl_write "$newname"; then
@@ -162,12 +182,12 @@ elif [ "$action" = move -a "$newlocation" ]; then
if [ -d "$_DATA/pages/$newname" ]; then
printf 'Refresh: %i\r\n' 4
- export ERRORMSG="A page of that name already exists at the given location."
+ export ERROR_MSG="A page of that name already exists at the given location."
theme_error 400
return 0
elif [ ! -d "$_DATA/pages/$newlocation" ]; then
printf 'Refresh: %i\r\n' 4
- export ERRORMSG="The given location does not exist."
+ export ERROR_MSG="The given location does not exist."
theme_error 400
return 0
elif ! acl_write "$oldname" || ! acl_write "$newname"; then
@@ -189,24 +209,51 @@ elif [ "$action" = delete ]; then
printf 'Refresh: %i\r\n' 4
theme_error 403
return 0
- elif [ "$REV_PAGES" = true ]; then
- git -C "$_DATA" rm "pages/${oldname}/#page.md"
- git -C "$_DATA" commit -m 'Page # '"$oldname"' # deleted by user @ '"$USER_NAME"' @' \
- -- "pages/${oldname}/#page.md"
- rm -r -- "$_DATA/pages/${oldname}"/\#*
- rmdir -- "$_DATA/pages/${oldname}/" || true
- REDIRECT ./
- else
- rm -- "$_DATA/pages/${oldname}/#page.md"
- rm -r -- "$_DATA/pages/${oldname}"/\#*
- rmdir -- "$_DATA/pages/${oldname}/" || true
- REDIRECT ./
fi
+
+ printf 'Status: 202 Accepted\r\n'
+ { [ "$delsub" = true ] \
+ && list_writable "$oldname" \
+ || printf %s\\n "$oldname"
+ } | while read oldname; do
+ if [ "$REV_PAGES" = true -a "$REV_ATTACHMENTS" = true ]; then
+ git -C "$_DATA" rm "pages/${oldname}/#page.md" >&2
+ git -C "$_DATA" rm -r "pages/${oldname}/#attachments/" >&2
+ git -C "$_DATA" commit -m 'Page # '"$oldname"' # deleted by user @ '"$USER_NAME"' @' \
+ -- "pages/${oldname}/#page.md" "pages/${oldname}/#attachments/" >&2
+ rm -r -- "$_DATA/pages/${oldname}"/\#*
+ rmdir -- "$_DATA/pages/${oldname}/" || true
+ elif [ "$REV_PAGES" = true ]; then
+ git -C "$_DATA" rm "pages/${oldname}/#page.md" >&2
+ git -C "$_DATA" commit -m 'Page # '"$oldname"' # deleted by user @ '"$USER_NAME"' @' \
+ -- "pages/${oldname}/#page.md" >&2
+ rm -r -- "$_DATA/pages/${oldname}"/\#*
+ rmdir -- "$_DATA/pages/${oldname}/" || true
+ else
+ rm -- "$_DATA/pages/${oldname}/#page.md"
+ rm -r -- "$_DATA/pages/${oldname}"/\#*
+ rmdir -- "$_DATA/pages/${oldname}/" || true
+ fi
+ printf '%s\n' "$oldname"
+ done | {
+ cat <<-EOF
+
+ $(_ "Pages deleted:")
+
+ $(while read page; do
+ printf '- %s
' "$(HTML $page)"
+ done)
+
+ $(_ OK)
+
+ EOF
+ } | theme_page -
+ return 0
elif [ "$action" = cancel ]; then
REDIRECT ./
elif [ "$action" ]; then
printf 'Refresh: %i\r\n' 4
- export ERRORMSG="Missing parameters."
+ export ERROR_MSG="Missing parameters."
theme_error 400
return 0
fi