-wiki() {
- # Print content of a wiki page
- # Get page from data or underlay dir, handle caching
- local page="$(PATH "$1")" mdfile cache cachetime
-
- cache="$_DATA/pages/$page/#page.${USER_ID}.cache"
-
- mdfile="$(mdfile "$page")" || return 4
- acl_read "$page" || return 3
-
- cachetime="$(stat -c %Y -- "$mdfile" "$cache" 2>/dev/null)"
-
- if [ "${cachetime#*${BR}}" -gt "${cachetime%${BR}*}" \
- -a "${cachetime#*${BR}}" -gt "$((_DATE - CACHE_AGE))" ]; then
- cat "${cache}"
- else
- mkdir -p -- "$_DATA/pages/$page/"
- # Macros expect to find page directory as working dir
- ( cd -- "$_DATA/pages/$page/";
- sed -E '1,20{ /^%[a-z]+/d; }' "$mdfile" \
- | md |tee -- "${cache}.$$"
- )
- grep -q '^%nocache' "$mdfile" \
- && rm -- "${cache}.$$" \
- || mv -- "${cache}.$$" "${cache}"
- fi
-}
-
-case "${PATH_INFO}" in
- /"[.]"/*)
- FILE "${_EXEC}/${PATH_INFO#/\[.\]}"
- ;;
- */"#"*/*)
- export ERROR_MSG="This page name is not allowed"
- theme_error 400
- ;;
- /|*[^]]/)
- theme_page "${PATH_INFO}"
- ;;
- */"[login]")
- theme_page "/[wiki]/login/"
- ;;
- */"[register]")
- theme_page "/[wiki]/register/"
- ;;
- */"[invite]")
- theme_page "/[wiki]/invite/"
- ;;
- *)
- . "$_EXEC/page_edit.sh" \
- || . "$_EXEC/attachment.sh" \
- || theme_error 404
- ;;
-esac
-
+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
+ 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
+fi