]> git.plutz.net Git - shellwiki/blobdiff - index.cgi
bugfix: prevent test errors from bleeding into http headers
[shellwiki] / index.cgi
index 57398a4ff7f9aabc4879b9a2b20cfb5b3b6dcb94..a27a75dbdddd133b086b71b9a222434cf10a0811 100755 (executable)
--- a/index.cgi
+++ b/index.cgi
@@ -6,9 +6,18 @@
 . "${_EXEC}/tools.sh"
 . "${_EXEC}/acl.sh"
 
-WIKI_THEME="${WIKI_THEME:-default}"
+export REV_PAGES=${REV_PAGES:-true}
+export REV_ATTACHMENTS=${REV_ATTACHMENTS:-false}
+export 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
+[ "$(COOKIE session)" ] && SESSION_COOKIE
+
 wiki_text() {
   # Print source text of a wiki page
   # Get page from data or underlay dir
@@ -19,10 +28,31 @@ wiki_text() {
   cat -- "$mdfile"
 }
 
+if [ "$REV_PAGES" = true -a ! -f "$_DATA/.gitignore" ]; then
+  cat >"$_DATA/.gitignore" <<-EOF
+       users.db
+       serverkey
+       **/#cache/
+       **/#page.lock
+       **/#page.*.cache
+       **/#page.*.cache.*
+       **/#page:*.*.cache
+       **/#page:*.*.cache.*
+       EOF
+  [ "$REV_ATTACHMENTS" != true ] \
+  && printf '**/#attachments/\n' >>"$_DATA/.gitignore"
+  git init "$_DATA"
+  git -C "$_DATA" add .gitignore
+  printf '%s\n' "" "[user]" \
+         "email = \"shellwiki@localhost\"" \
+         "name = \"Shellwiki\"" \
+         >>"$_DATA/.git/config"
+  git -C "$_DATA" commit -m 'initialization' -- .gitignore
+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