From e1441ae3543689244e9275c0581ad6c00d610f67 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Wed, 20 Sep 2023 12:00:56 +0200 Subject: [PATCH] recursive delete function --- handlers/60_move_rename_delete.sh | 77 +++++++++++++++++++++++++------ l10n/de.sh | 1 + themes/default.css | 7 +++ 3 files changed, 70 insertions(+), 15 deletions(-) diff --git a/handlers/60_move_rename_delete.sh b/handlers/60_move_rename_delete.sh index d27fb39..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

+ 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%/*}/" @@ -189,19 +209,46 @@ 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:")

+ + $(_ OK) +
+ EOF + } | theme_page - + return 0 elif [ "$action" = cancel ]; then REDIRECT ./ elif [ "$action" ]; then diff --git a/l10n/de.sh b/l10n/de.sh index ccee2ab..6d15a83 100644 --- a/l10n/de.sh +++ b/l10n/de.sh @@ -56,6 +56,7 @@ case $* in "A page of that name already exists at the given location.") printf "Eine Seite mit diesem namen gibt es schon am angegebenen Ort.";; "The given location does not exist.") printf "Den angegebenen Ort gibt es nicht.";; "Missing parameters.") printf "Fehlende Parameter.";; + "Pages deleted:") printf "Seiten gelöscht:";; *) printf %s\\n "$*";; esac } diff --git a/themes/default.css b/themes/default.css index 51de979..d58d973 100644 --- a/themes/default.css +++ b/themes/default.css @@ -100,6 +100,13 @@ main > form#deletepage, background-color: #FFF; } +main > form#deletepage label[for=delsub] { + text-decoration: underline; +} +main > form#deletepage input#delsub:checked + label + ul li.delsub { + text-decoration: line-through; +} + [id$="/[revision]"] main .revisions, [id$="/[attachment]"] main > .attachment.list { margin: 1em; -- 2.39.2