]> git.plutz.net Git - shellwiki/blobdiff - handlers/30_edit.sh
Merge commit '3812fa77d2234432e57912e3a6501259b30b1be5'
[shellwiki] / handlers / 30_edit.sh
index 6dfe2e863f26d86862a5ee0d3c11183967f66052..6d4e1eac12bd7c1359b7b1a95ad9bd19dcfa11b4 100755 (executable)
@@ -16,13 +16,22 @@ wiki_text() {
   fi
 }
 
+case $PATH_INFO in
+  */\[edit\]) : ;;
+  *) return 1 ;;
+esac
+
 edit_page="${PATH_INFO%\[edit\]}"
 edit_file="$_DATA/pages/$edit_page/#page.md"
 [ "$REQUEST_METHOD" = POST ] && edit_action="$(POST action)"
 
-if [ "$edit_page" = "$PATH_INFO" ]; then
-  unset edit_page edit_action edit_file
-  # END EDIT SCRIPT, continue in index.cgi
+if ! acl_write "$edit_page"; then
+  theme_error 403
+  return 0
+
+elif [ "$edit_action" = cancel ]; then
+  S_RELEASE "$edit_file"
+  REDIRECT "${_BASE}${PATH_INFO%\[edit\]}"
 
 elif [ "$edit_action" = update ]; then
   if  mkdir -p -- "${edit_file%/#page.md}" \
@@ -37,20 +46,12 @@ elif [ "$edit_action" = update ]; then
   if [ "$(which git)" ]; then
     git -C "$_DATA" add \
       -- "pages/$edit_page/#page.md"
-    git -C "$_DATA" commit -m \
+    git -C "$_DATA" commit -qm \
       "Page # ${edit_page} # updated by user @ ${USER_NAME} @" \
       -- "pages/$edit_page/#page.md"
-  fi
+  fi 1>&2
 
-  REDIRECT "${_BASE}${PATH_INFO%\[edit\]}"
-
-elif [ "$edit_action" = cancel ]; then
-  S_RELEASE "$edit_file"
-  REDIRECT "${_BASE}${PATH_INFO%\[edit\]}"
-
-elif ! acl_write "$edit_page"; then
-  theme_error 403
-  return 0
+  REDIRECT "${_BASE}${edit_page}"
 
 elif mkdir -p -- "${edit_file%/#page.md}" \
      && S_LOCK "$edit_file"; then