]> git.plutz.net Git - shellwiki/blobdiff - handlers/30_edit.sh
Merge commit 'bfe458e83c0157879767976ba97bf95d1e27918c'
[shellwiki] / handlers / 30_edit.sh
index aa55796ccce501fae8af249458bbef2513ee5994..6d4e1eac12bd7c1359b7b1a95ad9bd19dcfa11b4 100755 (executable)
@@ -16,32 +16,42 @@ 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}" \
-       && S_LOCK "$edit_file"; then
+  if  mkdir -p -- "${edit_file%/#page.md}" \
+      && S_LOCK "$edit_file"; then
     POST pagetext >"$edit_file"
     S_RELEASE "$edit_file"
-    REDIRECT "${_BASE}${PATH_INFO%\[edit\]}"
   else
     export ERRMSG="ERR_NOLOCK"
     REDIRECT "${_BASE}${PATH_INFO%\[edit\]}/[edit]"
   fi
 
-elif [ "$edit_action" = cancel ]; then
-  S_RELEASE "$edit_file"
-  REDIRECT "${_BASE}${PATH_INFO%\[edit\]}"
+  if [ "$(which git)" ]; then
+    git -C "$_DATA" add \
+      -- "pages/$edit_page/#page.md"
+    git -C "$_DATA" commit -qm \
+      "Page # ${edit_page} # updated by user @ ${USER_NAME} @" \
+      -- "pages/$edit_page/#page.md"
+  fi 1>&2
 
-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