]> git.plutz.net Git - shellwiki/commitdiff
recursive delete function
authorPaul Hänsch <paul@plutz.net>
Wed, 20 Sep 2023 10:00:56 +0000 (12:00 +0200)
committerPaul Hänsch <paul@plutz.net>
Wed, 20 Sep 2023 10:00:56 +0000 (12:00 +0200)
handlers/60_move_rename_delete.sh
l10n/de.sh
themes/default.css

index d27fb3937c103f564e30bd6e0e1e05a874b9a512..27246bd108acecac61ba2d7dc17406979aa2272d 100755 (executable)
@@ -85,20 +85,40 @@ l10n_deletepage >/dev/null 2>&1 \
          <h1>Delete Page</h1>
          <p class="pageid">$(HTML "${page}")</p>
          <p>This page and its attachments will be deleted</p>
+         <input type=checkbox name=delete_subpages value=true id=delsub><label for=delsub>Delete subpages</label>
          <ul>
-           <li>Past revisions of the page text (including the current one) will remain accessible and can be restored.</li>
-           <li>Attachments will be deleted completely, and cannot be restored.</li>
-           <li>Subpages will not be affected and can still be accessed normally.</li>
+       EOF
+  [ "$REV_PAGES" = true ] \
+  && printf '    <li>Past revisions of the page text (including the current one) will remain accessible and can be restored.</li>'
+  [ "$REV_PAGES" = true -a "$REV_ATTACHMENTS" = true ] \
+  && printf '    <li>Attachments can be restored as well.</li>' \
+  || printf '    <li>Attachments will be deleted completely, and cannot be restored.</li>'
+  cat <<-EOF
+           <li class="delsub">Subpages will not be affected and can still be accessed normally.</li>
          </ul>
          <button type=submit name=action value=delete>Delete</button>
          <button type=submit name=action value=cancel>Cancel</button>
        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
+       <article id="deleteconfirm">
+         <h1>$(_ "Pages deleted:")</h1>
+         <ul>
+         $(while read page; do
+           printf '<li>%s</li>' "$(HTML $page)"
+         done)
+         </ul>
+         <a class="button" href="./">$(_ OK)</a>
+       </article>
+       EOF
+  } | theme_page -
+  return 0
 elif [ "$action" = cancel ]; then
   REDIRECT ./
 elif [ "$action" ]; then
index ccee2ab4914dfae7283136895271057e8c815edb..6d15a83c985851989c6b320ef311c18e1a4c5d73 100644 (file)
@@ -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
 }
index 51de9795192801d9f3b91afab67f86e45cf2d126..d58d973c82a3cb1e0a4064b1b038b25095902a42 100644 (file)
@@ -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;