]> git.plutz.net Git - shellwiki/blob - index.cgi
Merge commit 'fb88510e7c955308c1321678f97a8f7d47b92efd'
[shellwiki] / index.cgi
1 #!/bin/sh
2
3 . "${_EXEC:-${0%/*}}/cgilite/cgilite.sh"
4 . "${_EXEC}/cgilite/session.sh"
5 . "${_EXEC}/cgilite/users.sh"
6 . "${_EXEC}/tools.sh"
7 . "${_EXEC}/acl.sh"
8
9 export REV_PAGES=${REV_PAGES:-true}
10 export REV_ATTACHMENTS=${REV_ATTACHMENTS:-false}
11 export WIKI_THEME="${WIKI_THEME:-default}"
12
13 which git >/dev/null || REV_PAGES=false
14 [ "$REV_PAGES" != true ] && REV_ATTACHMENTS=false
15
16 . "${_EXEC}/themes/${WIKI_THEME}.sh"
17
18 # Renew session cookie, only if cookie already set
19 [ "$(COOKIE session)" ] && SESSION_COOKIE
20
21 wiki_text() {
22   # Print source text of a wiki page
23   # Get page from data or underlay dir
24   local page="$(PATH "$1")" mdfile
25
26   mdfile="$(mdfile "$page")" || return 4
27   acl_read "$page" || return 3
28   cat -- "$mdfile"
29 }
30
31 if [ "$REV_PAGES" = true -a ! -f "$_DATA/.gitignore" ]; then
32   cat >"$_DATA/.gitignore" <<-EOF
33         users.db
34         serverkey
35         **/#cache/
36         **/#page.lock
37         **/#page.*.cache
38         **/#page.*.cache.*
39         **/#page:*.*.cache
40         **/#page:*.*.cache.*
41         EOF
42   [ "$REV_ATTACHMENTS" != true ] \
43   && printf '**/#attachments/\n' >>"$_DATA/.gitignore"
44   git init "$_DATA"
45   git -C "$_DATA" add .gitignore
46   printf '%s\n' "" "[user]" \
47          "email = \"shellwiki@localhost\"" \
48          "name = \"Shellwiki\"" \
49          >>"$_DATA/.git/config"
50   git -C "$_DATA" commit -m 'initialization' -- .gitignore
51 fi 1>&2
52
53 for handler in "$_EXEC"/handlers/*; do
54   . "$handler" && break
55 done
56 if [ $? != 0 ]; then
57   export ERROR_MSG="The presented URL schema cannot be handled"
58   theme_error 400
59 fi