From: Paul Hänsch Date: Wed, 25 May 2022 19:26:10 +0000 (+0200) Subject: handler for moving and deleting pages X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=fef8e307b2e7777e5c43766e625338da8089bbfc;p=shellwiki handler for moving and deleting pages --- diff --git a/handlers/30_move_rename_delete.sh b/handlers/30_move_rename_delete.sh new file mode 100644 index 0000000..12e7d45 --- /dev/null +++ b/handlers/30_move_rename_delete.sh @@ -0,0 +1,154 @@ +#!/bin/sh + +case "${PATH_INFO}" in + */\[move\]|*/\[rename\]|*/\[delete\]) + page="${PATH_INFO%\[*\]}" + if [ ! -d "$_DATA/pages/${page}" -a ! -d "$_EXEC/pages/${page}" ]; then + theme_error 404 + return 0 + elif ! acl_write "$page"; then + printf 'Refresh: %i, url=%s\r\n' 4 ./ + theme_error 403 + return 0 + elif [ -d "$_EXEC/pages/${page}/" ]; then + 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. +

+
+ EOF + return 0 + fi + ;; + *) 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 +
+ +

Move Page

+

$(HTML "${page}")

+ + + + +
+ EOF + return 0 + ;; + */\[rename\]) + name="${page%/}" name="${name##*/}" + theme_page - <<-EOF +
+ +

Rename Page

+

$(HTML "${page}")

+ + + + +
+ EOF + return 0 + ;; + */\[delete\]) + theme_page - <<-EOF +
+ +

Delete Page

+

$(HTML "${page}")

+

This page and its attachments will be deleted

+ + + +
+ EOF + return 0 + ;; + esac +fi + +if [ "$action" = rename -a "$newname" ]; then + oldname="${PATH_INFO%\[*\]}" + newname="${oldname%/*/}$(PATH "${newname}/")" + + if [ -d "$_DATA/pages/$newname" ]; then + printf 'Refresh: %i\r\n' 4 + export ERRORMSG="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 + 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}" + fi +elif [ "$action" = move -a "$newlocation" ]; then + oldname="${PATH_INFO%\[*\]}" + newlocation="$(PATH "$newlocation")" + newname="${oldname%/}" + newname="${newlocation%/}/${newname##*/}/" + + 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." + 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." + 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 + 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}" + fi +elif [ "$action" = delete ]; then + oldname="${PATH_INFO%\[*\]}" + if ! acl_write "$oldname"; then + printf 'Refresh: %i\r\n' 4 + theme_error 403 + return 0 + else + 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 ./ + fi +fi diff --git a/themes/default.css b/themes/default.css index 11c3dae..91458c3 100644 --- a/themes/default.css +++ b/themes/default.css @@ -52,6 +52,8 @@ main .pagemenu li { main .pagemenu li a { color: #FFF; } main article, +main > form#renamepage, main > form#movepage, +main > form#deletepage, [id$="/[attachment]"] main form.upload { margin: 1em; padding: .125em 1em 1em 1em; diff --git a/themes/default.sh b/themes/default.sh index 89d4fad..0b85007 100755 --- a/themes/default.sh +++ b/themes/default.sh @@ -28,6 +28,9 @@ theme_pagemenu(){
  • Edit
  • Attachments
  • Revisions
  • +
  • Rename
  • +
  • Move
  • +
  • Delete
  • ' fi }