]> git.plutz.net Git - shellwiki/commitdiff
copy function for attachments
authorPaul Hänsch <paul@plutz.net>
Mon, 28 Sep 2026 03:22:27 +0000 (05:22 +0200)
committerPaul Hänsch <paul@plutz.net>
Mon, 28 Sep 2026 03:22:27 +0000 (05:22 +0200)
handlers/40_edit_attachment.sh
themes/default.css
themes/default.sh

index b23a35d31bc9fc03632703751fd638d60123f0dc..11770ddf9e767fcb7cdfce69e2dffa37cb4f4f1b 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-# Copyright 2022 - 2023 Paul Hänsch
+# Copyright 2022 - 2026 Paul Hänsch
 # 
 # Permission to use, copy, modify, and/or distribute this software for any
 # purpose with or without fee is hereby granted, provided that the above
@@ -15,6 +15,7 @@
 # IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
 REV_ATTACHMENTS="${REV_ATTACHMENTS:-false}"
+COPY_ATTACHMENTS="${COPY_ATTACHMENTS:-auto}"  # copy|reflink|hardlink|auto
 
 if [ "${PATH_INFO##*/\[attachment\]}" ]; then
   # Skip any action not happening on attachment page
@@ -86,7 +87,7 @@ elif [ "$SESSION_ID" != "$tsid" ]; then
   return 0
 fi
 
-if [ "$action" = delete -o "$action" = move ]; then
+if [ "$action" = delete -o "$action" = move -o "$action" = copy ]; then
   set --
   n="$(POST_COUNT select)"; while [ $n -gt 0 ]; do
     select="$(POST select $n |PATH)"
@@ -122,6 +123,7 @@ elif [ "$action" = move ]; then
     mkdir -p -- "${_DATA}/pages${moveto}/#attachments"
     git -C "$_DATA" mv -f -- "$@" "pages${moveto}/#attachments/"
 
+    # load new names into parameter array
     cnt=$#; while [ $cnt -gt 0 ]; do
       set -- "$@" "$1" "pages/${moveto}/#attachments/${1##*/}"
       cnt=$((cnt - 1)); shift 1
@@ -135,6 +137,55 @@ elif [ "$action" = move ]; then
   fi
   REDIRECT "${_BASE}${PATH_INFO}"
 
+elif [ "$action" = copy ]; then
+  copyto="$(POST copyto |PATH)"
+
+  if ! acl_write "$copyto"; then
+    printf 'Refresh: %i\r\n' 4
+    theme_error 403
+    return 0
+
+  elif [ ! -d "${_DATA}/pages${copyto}" ]; then
+    printf 'Refresh: %i\r\n' 4
+    theme_error 404
+    return 0
+
+  else
+    mkdir -p -- "${_DATA}/pages${copyto}/#attachments"
+    case $COPY_ATTACHMENTS in
+      hardlink)
+        ( cd "$_DATA" && ln -- "$@" "pages${copyto}/#attachments/"; )
+      ;;
+      copy)
+        ( cd "$_DATA" && cp -- "$@" "pages${copyto}/#attachments/"; )
+      ;;
+      reflink)
+        ( cd "$_DATA" && cp --reflink=always -- "$@" "pages${copyto}/#attachments/"; )
+      ;;
+      auto|*)
+        ( cd "$_DATA";
+          ln -- "$@" "pages${copyto}/#attachments/" \
+          || cp --reflink=always -- "$@" "pages${copyto}/#attachments/" \
+          || cp -- "$@" "pages${copyto}/#attachments/"
+        )
+      ;;
+    esac
+  fi
+
+  if [ "$REV_ATTACHMENTS" = true ]; then
+    # load new names into parameter array
+    cnt=$#; while [ $cnt -gt 0 ]; do
+      set -- "$@" "$1" "pages/${copyto}/#attachments/${1##*/}"
+      cnt=$((cnt - 1)); shift 1
+    done
+
+    git -C "$_DATA" add -- "$@"
+    git -C "$_DATA" commit -qm \
+        "Attachment copied from # $page # to # $copyto # by @ $USER_NAME @" -- "$@"
+  fi
+
+  REDIRECT "${_BASE}${PATH_INFO}"
+
 elif [ "$action" = rename ]; then
   fail='' success=''
   set --
index 6bf4985ed82af9a3dccd93763c60bdb85b6f0635..af2f3301b680ba204c93067f130e1fa1df64b414 100644 (file)
@@ -393,7 +393,9 @@ table {
 [id$="/[attachment]"] input[type=radio].tab#tdel:checked  ~ div.tab ul li input[name=select],
 [id$="/[attachment]"] input[type=radio].tab#tdel:checked  ~ div.tab ul li label.name,
 [id$="/[attachment]"] input[type=radio].tab#tmove:checked ~ div.tab ul li input[name=select],
-[id$="/[attachment]"] input[type=radio].tab#tmove:checked ~ div.tab ul li label.name {
+[id$="/[attachment]"] input[type=radio].tab#tmove:checked ~ div.tab ul li label.name,
+[id$="/[attachment]"] input[type=radio].tab#tcopy:checked ~ div.tab ul li input[name=select],
+[id$="/[attachment]"] input[type=radio].tab#tcopy:checked ~ div.tab ul li label.name {
   display: inline;
 }
 [id$="/[attachment]"] input[type=radio].tab#tren:checked ~ .tab ul li input.name {
@@ -401,6 +403,7 @@ table {
 }
 
 [id$="/[attachment]"] label[for=moveto], [id$="/[attachment]"] input#moveto,
+[id$="/[attachment]"] label[for=copyto], [id$="/[attachment]"] input#copyto,
 [id$="/[attachment]"] button[name=action] { display: none; }
 
 [id$="/[attachment]"] .upload button[name=action] { display: inline-block; }
@@ -408,6 +411,9 @@ table {
 [id$="/[attachment]"] input[type=radio].tab#tmove:checked ~ div.tab label[for=moveto],
 [id$="/[attachment]"] input[type=radio].tab#tmove:checked ~ div.tab input#moveto,
 [id$="/[attachment]"] input[type=radio].tab#tmove:checked ~ div.tab button[name=action][value=move],
+[id$="/[attachment]"] input[type=radio].tab#tcopy:checked ~ div.tab label[for=copyto],
+[id$="/[attachment]"] input[type=radio].tab#tcopy:checked ~ div.tab input#copyto,
+[id$="/[attachment]"] input[type=radio].tab#tcopy:checked ~ div.tab button[name=action][value=copy],
 [id$="/[attachment]"] input[type=radio].tab#tren:checked  ~ div.tab button[name=action][value=rename] {
   display: inline;
 }
index e3315343e41a89923e0c36207b28cdcdc7fdc8d3..a81b06f10abe566c040b75fd4c9e0a84dca1a2a0 100755 (executable)
@@ -161,6 +161,7 @@ theme_attachments(){
           <input checked type=radio class=tab name=attachaction value=view id=tview><label for=tview>$(_ View)</label>
           <input         type=radio class=tab name=attachaction value=del  id=tdel ><label for=tdel >$(_ Delete)</label>
           <input         type=radio class=tab name=attachaction value=move id=tmove><label for=tmove>$(_ Move)</label>
+          <input         type=radio class=tab name=attachaction value=copy id=tcopy><label for=tcopy>$(_ Copy)</label>
           <input         type=radio class=tab name=attachaction value=ren  id=tren ><label for=tren >$(_ Rename)</label>
           <div class="tab">
            <ul class="attachment list">
@@ -187,6 +188,9 @@ theme_attachments(){
            <label for=moveto>$(_ Move To:)</label>
            <input id="moveto" name="moveto" value="$(HTML "$page")" placeholder="$(_ page name)">
            <button type=submit name=action value=move  >$(_ Move)</button>
+           <label for=copyto>$(_ Copy To:)</label>
+           <input id="copyto" name="copyto" value="$(HTML "$page")" placeholder="$(_ page name)">
+           <button type=submit name=action value=copy  >$(_ Copy)</button>
            <button type=submit name=action value=rename>$(_ Rename)</button>
          </div>
        </form>