}
theme_footer(){
- printf '<footer>%s</footer>' "$(wiki '[wiki]/footer/' ||echo No footer)"
+ printf '<footer>%s</footer>' "$(wiki '[wiki]/footer/')"
+}
+
+theme_pagemenu(){
+ local page="$1"
+
+ if acl_write "$page"; then
+ printf '
+ <ul class="pagemenu">
+ <li><a href="[edit]">Edit</a></li>
+ <li><a href="[attachment]/">Attachments</a></li>
+ </ul>'
+ fi
}
theme_page(){
local page="$1" title
title="${page%/}"; title="${title##*/}"
- if [ ! "$(mdfile "$page")" ]; then
- theme_404
- return 0
- elif ! acl_read "$page"; then
- theme_403
- return 0
- fi
-
# Important! Web Server response including newline
printf "%s\r\n" "Content-Type: text/html; charset=utf-8" ""
</head><body id="$(HTML "$page")">
$(theme_header)
<main>
- $(acl_write "$page" && printf %s \
- '<ul class="pagemenu">
- <li><a href="[edit]">Edit</a></li>
- <li><a href="[attachment]/">Attachments</a></li>
- </ul>'
- )
+ $(theme_pagemenu)
<article>
$(wiki "$page" || printf 'Error while loading page <br> function "wiki" of index.sh returned with an error.')
</article>
}
theme_editor(){
- local page="$1" title
+ local page="$1" template="$2" title
title="${page%/}"; title="${title##*/}"
- if [ ! "$(mdfile "$page")" ]; then
- theme_404
- return 0
- elif ! acl_write "$page"; then
- theme_403
- return 0
- fi
+ [ "$template" ] && acl_read "$template" || template="$page"
# Important! Web Server response including newline
printf "%s\r\n" "Content-Type: text/html; charset=utf-8" ""
<title>$(HTML "${title}")</title>
</head><body id="$(HTML "$page")" class="editor">
$(theme_header)
- <main><form method=POST>
+ <main><form method=POST action="$(HTML "${page%/}/[edit]")">
<input type=hidden name=session_key value="${SESSION_KEY}"/>
- <textarea name=pagetext>$(wiki_text "$page" |HTML)</textarea>
+ <textarea name=pagetext>$({ wiki_text "$page" \
+ || wiki_text "$template"; } |HTML)</textarea>
<button type=submit name=action value=update>Update</button>
<button type=submit name=action value=cancel>Cancel</button>
</form></main>
EOF
}
-theme_attachments(){
+theme_revisions(){
local page="$1" title
title="${page%/}"; title="${title##*/}"
- if [ ! "$(mdfile "$page")" ]; then
- theme_404
- return 0
- elif ! acl_read "$page"; then
- theme_403
- return 0
- fi
+ # Important! Web Server response including newline
+ printf "%s\r\n" "Content-Type: text/html; charset=utf-8" ""
+
+ cat <<-EOF
+ <!DOCTYPE HTML>
+ <html><head>
+ $(theme_head)
+ <title>Revisions $(HTML "${title}")</title>
+ </head><body id="$(HTML "$page")[attachment]/">
+ $(theme_header)
+ <main>
+ $("$_EXEC/macros/revisions" "$page")
+ </main>
+ $(theme_footer)
+ </body></html>
+ EOF
+}
+
+theme_attachments(){
+ local page="$1" title
+ title="${page%/}"; title="${title##*/}"
# Important! Web Server response including newline
printf "%s\r\n" "Content-Type: text/html; charset=utf-8" ""
fi
}
-theme_login(){
- theme_page '/[wiki]/login/'
-}
-
-theme_register(){
- theme_page '/[wiki]/register/'
-}
-
-theme_403(){
- printf "%s\r\n" "Status: 403 Forbidden"
-
- if [ "$(mdfile '/[wiki]/403/')" ]; then
- theme_page '/[wiki]/403/'
- else
- printf "Content-Length: 0\r\n\r\n"
- fi
-}
+theme_error(){
+ local errno="$1"
-theme_404(){
- printf "%s\r\n" "Status: 404 Not Found"
+ case $errno in
+ 400) printf "%s\r\n" "Status: 400 Bad Request";;
+ 403) printf "%s\r\n" "Status: 403 Forbidden";;
+ 404) printf "%s\r\n" "Status: 404 Not Found";;
+ 409) printf "%s\r\n" "Status: 409 Conflict";;
+ 500) printf "%s\r\n" "Status: 500 Internal Server Error";;
+ esac
- if [ "$(mdfile '/[wiki]/404/')" ]; then
- theme_page '/[wiki]/404/'
+ if [ "$(mdfile "/[wiki]/$errno/")" ]; then
+ theme_page "/[wiki]/$errno/"
else
printf "Content-Length: 0\r\n\r\n"
fi