#!/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
# 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
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)"
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
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 --
[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 {
}
[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; }
[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;
}
<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">
<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>