3 # Copyright 2022 - 2023 Paul Hänsch
5 # Permission to use, copy, modify, and/or distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
9 # THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
12 # SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
15 # IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 . "$_EXEC/cgilite/file.sh"
19 CACHE_AGE=${CACHE_AGE:-300}
20 export MD_MACROS="$_EXEC/macros"
21 export MD_HTML="${MD_HTML:-false}"
24 # Print content of a wiki page
25 # Get page from data or underlay dir, handle caching
26 local page="$(PATH "$1")" mdfile cache cachetime
28 cache="$_DATA/pages/$page/#page:${LANGUAGE}.${USER_ID}.cache"
30 mdfile="$(mdfile "$page")" || return 4
31 acl_read "$page" || return 3
33 cachetime="$(stat -c %Y -- "$mdfile" "$cache" 2>/dev/null)"
35 if [ "${cachetime#*${BR}}" -gt "${cachetime%${BR}*}" \
36 -a "${cachetime#*${BR}}" -gt "$((_DATE - CACHE_AGE))" ]; then
39 mkdir -p -- "$_DATA/pages/$page/"
40 # Macros expect to find page directory as working dir
41 ( cd -- "$_DATA/pages/$page/";
43 | tee -- "${cache}.$$"
45 grep -q '^%nocache' "$mdfile" \
46 && rm -- "${cache}.$$" \
47 || mv -- "${cache}.$$" "${cache}"
51 case "${PATH_INFO}" in
53 # usually some file related to theme
54 # let file server handle errors
55 FILE "${_EXEC}/${PATH_INFO#/\[.\]}"
59 export ERROR_MSG='Page names containing newline character are not allowed'
64 export ERROR_MSG='Page names starting with "#" are not allowed'
69 # looks like some kind of handler
73 if ! mdfile "$PATH_INFO" >&-; then
75 elif ! acl_read "$PATH_INFO"; then
78 theme_page "${PATH_INFO}"