]> git.plutz.net Git - shellwiki/commitdiff
enable work without git revisioning
authorPaul Hänsch <paul@plutz.net>
Wed, 31 May 2023 20:27:12 +0000 (22:27 +0200)
committerPaul Hänsch <paul@plutz.net>
Wed, 31 May 2023 20:27:12 +0000 (22:27 +0200)
handlers/60_edit.sh
handlers/60_move_rename_delete.sh
index.cgi
macros/revisions

index 6d4e1eac12bd7c1359b7b1a95ad9bd19dcfa11b4..9d1a404a85485db348e1ee405054527655de5c95 100755 (executable)
@@ -43,7 +43,7 @@ elif [ "$edit_action" = update ]; then
     REDIRECT "${_BASE}${PATH_INFO%\[edit\]}/[edit]"
   fi
 
-  if [ "$(which git)" ]; then
+  if [ "$REV_PAGES" = true ]; then
     git -C "$_DATA" add \
       -- "pages/$edit_page/#page.md"
     git -C "$_DATA" commit -qm \
index be84ca8afc40e856fad03cb1a4ec354e52135c22..bbe994e4f7a44911d18e10f7cc4eca923d0518dc 100755 (executable)
@@ -105,11 +105,14 @@ if [ "$action" = rename -a "$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%\[*\]}"
@@ -131,11 +134,14 @@ elif [ "$action" = move -a "$newlocation" ]; 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,13 +149,18 @@ 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 ./
index 8479bd9dd492127e760f19865e14a659fdecef6e..61a8bb007c5d0807eaf9d6983d34637e74e583fc 100755 (executable)
--- a/index.cgi
+++ b/index.cgi
@@ -6,8 +6,13 @@
 . "${_EXEC}/tools.sh"
 . "${_EXEC}/acl.sh"
 
+REV_PAGES=${REV_PAGES:-true}
 REV_ATTACHMENTS=${REV_ATTACHMENTS:-false}
 WIKI_THEME="${WIKI_THEME:-default}"
+
+which git >/dev/null || REV_PAGES=false
+[ "$REV_PAGES" != true ] && REV_ATTACHMENTS=false
+
 . "${_EXEC}/themes/${WIKI_THEME}.sh"
 
 # Renew session cookie, only if cookie already set
@@ -23,11 +28,10 @@ wiki_text() {
   cat -- "$mdfile"
 }
 
-if [ "$(which git)" -a ! -f "$_DATA/.gitignore" ]; then
+if [ "$REV_PAGES" = true -a ! -f "$_DATA/.gitignore" ]; then
   cat >"$_DATA/.gitignore" <<-EOF
        users.db
        serverkey
-       $([ "$REV_ATTACHMENTS" = true ] || printf %s "**/#attachments/")
        **/#cache/
        **/#page.lock
        **/#page.*.cache
@@ -35,6 +39,8 @@ if [ "$(which git)" -a ! -f "$_DATA/.gitignore" ]; then
        **/#page:*.*.cache
        **/#page:*.*.cache.*
        EOF
+  [ "$REV_ATTACHMENTS" != true ] \
+  && printf '**/#attachments/\n' >>"$_DATA/.gitignore"
   git init "$_DATA"
   git -C "$_DATA" add .gitignore
   git -C "$_DATA" commit -m 'initialization' -- .gitignore
@@ -43,7 +49,6 @@ fi 1>&2
 for handler in "$_EXEC"/handlers/*; do
   . "$handler" && break
 done
-
 if [ $? != 0 ]; then
   export ERROR_MSG="The presented URL schema cannot be handled"
   theme_error 400
index 9a5730f4021d5a069a748b8e7265658bef8cf433..4271149cffbd8074d89f16d88418b26f5f842441 100755 (executable)
@@ -9,7 +9,7 @@ page_abs="$(page_abs "$page")"
 
 if ! acl_read "$page_abs"; then
   return 0
-elif [ ! "$(which git)" ]; then
+elif [ "$REV_PAGES" != true ]; then
   printf '<div class="macro revisions error">GIT is not available to handle revisioning.</div>'
 fi