]> git.plutz.net Git - shellwiki/blobdiff - handlers/60_move_rename_delete.sh
Bugfix: faulty error messages in move/rename/delete
[shellwiki] / handlers / 60_move_rename_delete.sh
index bbe994e4f7a44911d18e10f7cc4eca923d0518dc..d27fb3937c103f564e30bd6e0e1e05a874b9a512 100755 (executable)
@@ -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
+         <h1>Immutable Page</h1>
+         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
        <article>
          <p class=error>
-         <h1>Immutable Page</h1>
-         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)
          </p>
        </article>
        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
-       <form method=POST id=movepage>
-         <input type=hidden name=session_id value="$SESSION_KEY">
+l10n_movepage >/dev/null 2>&1 \
+|| l10n_movepage(){  # TRANSLATION
+  cat <<-EOF
          <h1>Move Page</h1>
          <p class="pageid">$(HTML "${page}")</p>
          <input name="newlocation" value="$(HTML "$location")" placeholder="New Location">
@@ -47,15 +61,11 @@ else case "${PATH_INFO}" in
          </ul>
          <button type=submit name=action value=move>Move</button>
          <button type=submit name=action value=cancel>Cancel</button>
-       </form>
        EOF
-      return 0
-    ;;
-  */\[rename\])
-      name="${page%/}" name="${name##*/}"
-      theme_page - <<-EOF
-       <form method=POST id=renamepage>
-         <input type=hidden name=session_id value="$SESSION_KEY">
+}
+l10n_renamepage >/dev/null 2>&1 \
+|| l10n_renamepage(){  # TRANSLATION
+  cat <<-EOF
          <h1>Rename Page</h1>
          <p class="pageid">$(HTML "${page}")</p>
          <input name="newname" value="$(HTML "$name")" placeholder="New Name">
@@ -67,14 +77,11 @@ else case "${PATH_INFO}" in
          </ul>
          <button type=submit name=action value=rename>Rename</button>
          <button type=submit name=action value=cancel>Cancel</button>
-       </form>
        EOF
-      return 0
-    ;;
-  */\[delete\])
-      theme_page - <<-EOF
-       <form method=POST id=deletepage>
-         <input type=hidden name=session_id value="$SESSION_KEY">
+}
+l10n_deletepage >/dev/null 2>&1 \
+|| l10n_deletepage(){  # TRANSLATION
+  cat <<-EOF
          <h1>Delete Page</h1>
          <p class="pageid">$(HTML "${page}")</p>
          <p>This page and its attachments will be deleted</p>
@@ -85,6 +92,39 @@ else case "${PATH_INFO}" in
          </ul>
          <button type=submit name=action value=delete>Delete</button>
          <button type=submit name=action value=cancel>Cancel</button>
+       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
+       <form method=POST id=movepage>
+         <input type=hidden name=session_id value="$SESSION_KEY">
+         $(l10n_movepage)
+       </form>
+       EOF
+      return 0
+    ;;
+  */\[rename\])
+      name="${page%/}" name="${name##*/}"
+      theme_page - <<-EOF
+       <form method=POST id=renamepage>
+         <input type=hidden name=session_id value="$SESSION_KEY">
+         $(l10n_renamepage)
+       </form>
+       EOF
+      return 0
+    ;;
+  */\[delete\])
+      theme_page - <<-EOF
+       <form method=POST id=deletepage>
+         <input type=hidden name=session_id value="$SESSION_KEY">
+         $(l10n_deletepage)
        </form>
        EOF
       return 0
@@ -98,7 +138,7 @@ 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
@@ -122,12 +162,12 @@ 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
@@ -166,7 +206,7 @@ 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