X-Git-Url: https://git.plutz.net/?a=blobdiff_plain;f=handlers%2F60_move_rename_delete.sh;h=d27fb3937c103f564e30bd6e0e1e05a874b9a512;hb=4f6786c2be70200b3ff43db68d0f536fcaedad3f;hp=be84ca8afc40e856fad03cb1a4ec354e52135c22;hpb=1addbd404bc8cd6f869e9e1df19cc83081fa7bc2;p=shellwiki diff --git a/handlers/60_move_rename_delete.sh b/handlers/60_move_rename_delete.sh index be84ca8..d27fb39 100755 --- a/handlers/60_move_rename_delete.sh +++ b/handlers/60_move_rename_delete.sh @@ -1,5 +1,28 @@ #!/bin/sh +# Copyright 2022 - 2023 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 +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY +# SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR +# IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +l10n_immutablepage >/dev/null 2>&1 \ +|| l10n_immutablepage(){ #TRANSLATION + cat <<-EOF +

Immutable Page

+ This is a core page of the wiki system. Its name and position cannot be changed. + You may however update this page and you can use ACLs to hide it from various listings. + EOF +} + case "${PATH_INFO}" in */\[move\]|*/\[rename\]|*/\[delete\]) page="${PATH_INFO%\[*\]}" @@ -14,9 +37,7 @@ case "${PATH_INFO}" in theme_page - <<-EOF

-

Immutable Page

- This is a core page of the wiki system. Its name and position cannot be changed. - You may however update this page and you can use ACLs to hide it from various listings. + $(l10n_immutablepage)

EOF @@ -26,16 +47,9 @@ case "${PATH_INFO}" in *) return 1;; esac -if [ "$REQUEST_METHOD" = POST ]; then - action="$(POST action)" - newname="$(POST newname |grep -m1 -xE '[^#/]*')" - newlocation="$(POST newlocation |grep -m1 -xE '/[^#]*')" -else case "${PATH_INFO}" in - */\[move\]) - location="${page%/}" location="${location%/*}/" - theme_page - <<-EOF -
- +l10n_movepage >/dev/null 2>&1 \ +|| l10n_movepage(){ # TRANSLATION + cat <<-EOF

Move Page

$(HTML "${page}")

@@ -47,15 +61,11 @@ else case "${PATH_INFO}" in -
EOF - return 0 - ;; - */\[rename\]) - name="${page%/}" name="${name##*/}" - theme_page - <<-EOF -
- +} +l10n_renamepage >/dev/null 2>&1 \ +|| l10n_renamepage(){ # TRANSLATION + cat <<-EOF

Rename Page

$(HTML "${page}")

@@ -67,14 +77,11 @@ else case "${PATH_INFO}" in -
EOF - return 0 - ;; - */\[delete\]) - theme_page - <<-EOF -
- +} +l10n_deletepage >/dev/null 2>&1 \ +|| l10n_deletepage(){ # TRANSLATION + cat <<-EOF

Delete Page

$(HTML "${page}")

This page and its attachments will be deleted

@@ -85,6 +92,39 @@ else case "${PATH_INFO}" in + EOF +} + +if [ "$REQUEST_METHOD" = POST ]; then + action="$(POST action)" + newname="$(POST newname |grep -m1 -xE '[^#/]*')" + newlocation="$(POST newlocation |grep -m1 -xE '/[^#]*')" +else case "${PATH_INFO}" in + */\[move\]) + location="${page%/}" location="${location%/*}/" + theme_page - <<-EOF + + + $(l10n_movepage) +
+ EOF + return 0 + ;; + */\[rename\]) + name="${page%/}" name="${name##*/}" + theme_page - <<-EOF +
+ + $(l10n_renamepage) +
+ EOF + return 0 + ;; + */\[delete\]) + theme_page - <<-EOF +
+ + $(l10n_deletepage)
EOF return 0 @@ -98,18 +138,21 @@ 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 printf 'Refresh: %i\r\n' 4 theme_error 403 return 0 - else + elif [ "$REV_PAGES" = true ]; then git -C "$_DATA" mv "pages/$oldname" "pages/$newname" git -C "$_DATA" commit -m 'Page # '"$oldname"' # renamed to # '"$newname"' # by user @ '"$USER_NAME"' @' \ -- "pages/$oldname" "pages/$newname" REDIRECT "$_BASE${newname}" + else + mv -- "$_DATA/pages/$oldname" "$_DATA/pages/$newname" + REDIRECT "$_BASE${newname}" fi elif [ "$action" = move -a "$newlocation" ]; then oldname="${PATH_INFO%\[*\]}" @@ -119,23 +162,26 @@ 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 printf 'Refresh: %i\r\n' 4 theme_error 403 return 0 - else + elif [ "$REV_PAGES" = true ]; then git -C "$_DATA" mv "pages/${oldname}" "pages/${newname}" git -C "$_DATA" commit -m 'Page # '"$oldname"' # moved to # '"$newname"' # by user @ '"$USER_NAME"' @' \ -- "pages/${oldname}" "pages/${newname}" REDIRECT "$_BASE${newname}" + else + mv -- "$_DATA/pages/$oldname" "$_DATA/pages/$newname" + REDIRECT "$_BASE${newname}" fi elif [ "$action" = delete ]; then oldname="${PATH_INFO%\[*\]}" @@ -143,19 +189,24 @@ elif [ "$action" = delete ]; then printf 'Refresh: %i\r\n' 4 theme_error 403 return 0 - else + 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 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