X-Git-Url: https://git.plutz.net/?a=blobdiff_plain;f=themes%2Fdefault.sh;h=e9e9d73f195466c6bfcf2433dfe0dcb8767aab60;hb=7af38aed3e2f4d019b371da3ec58a41457173248;hp=6fa6ba16566245e9e7c0b92b883a155bf9ad4a19;hpb=cb3cd16be2190c7e91aa1dafd22b295b641c0d32;p=shellwiki diff --git a/themes/default.sh b/themes/default.sh index 6fa6ba1..e9e9d73 100755 --- a/themes/default.sh +++ b/themes/default.sh @@ -15,7 +15,19 @@ theme_header(){ } theme_footer(){ - printf '' "$(wiki '[wiki]/footer/' ||echo No footer)" + printf '' "$(wiki '[wiki]/footer/')" +} + +theme_pagemenu(){ + local page="$1" + + if acl_write "$page"; then + printf ' + ' + fi } theme_page(){ @@ -33,12 +45,9 @@ theme_page(){ $(theme_header)
- + $(theme_pagemenu)
- $(wiki "$page" || printf 'Page not found') + $(wiki "$page" || printf 'Error while loading page
function "wiki" of index.sh returned with an error.')
$(theme_footer) @@ -47,9 +56,11 @@ theme_page(){ } theme_editor(){ - local page="$1" title + local page="$1" template="$2" title title="${page%/}"; title="${title##*/}" + [ "$template" ] && acl_read "$template" || template="$page" + # Important! Web Server response including newline printf "%s\r\n" "Content-Type: text/html; charset=utf-8" "" @@ -60,9 +71,10 @@ theme_editor(){ $(HTML "${title}") $(theme_header) -
+
- +
@@ -71,7 +83,7 @@ theme_editor(){ EOF } -theme_attachments(){ +theme_revisions(){ local page="$1" title title="${page%/}"; title="${title##*/}" @@ -79,6 +91,62 @@ theme_attachments(){ printf "%s\r\n" "Content-Type: text/html; charset=utf-8" "" cat <<-EOF + + + $(theme_head) + Revisions $(HTML "${title}") + + $(theme_header) +
+ $("$_EXEC/macros/revisions" "$page") +
+ $(theme_footer) + + 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" "" + + if acl_write "$page"; then + cat <<-EOF + + + $(theme_head) + Attachments $(HTML "${title}") + + $(theme_header) +
+
+ + + +
+ +
    + + $(for file in "$_EXEC/pages/$page/#attachments"/* "$_DATA/pages/$page/#attachments"/*; do + [ "$file" = "$_EXEC/pages/$page/#attachments/${file##*/}" \ + -a -f "$_DATA/pages/$page/#attachments/${file##*/}" ] && continue + stat="$(stat -c '%s %Y' -- "$file" 2>&-)" || continue + size="${stat% *}" date="${stat#* }" + + printf '
  • %s + %s%s
  • ' \ + "$(HTML "${file##*/}")" "$(HTML "${file##*/}")" "$(HTML "${file##*/}")" \ + "$(size_human "$size")" "$(date -d @"$date" +"%F %T")" + done) +
+
+ $(theme_footer) + + EOF + else + cat <<-EOF $(theme_head) @@ -93,27 +161,32 @@ theme_attachments(){ stat="$(stat -c '%s %Y' -- "$file" 2>&-)" || continue size="${stat% *}" date="${stat#* }" - printf '
  • %s + printf '
  • %s %s%s
  • ' \ - "$(HTML "${file##*/}")" "$(size_human "$size")" "$(date -d @"$date" +"%F %T")" + "$(HTML "${file##*/}")" "$(HTML "${file##*/}")" "$(size_human "$size")" "$(date -d @"$date" +"%F %T")" done)
    $(theme_footer) EOF + fi } -theme_login(){ - theme_page '[wiki]/login/' -} - -theme_register(){ - theme_page '[wiki]/register/' -} - -theme_404(){ - printf "%s\r\n" "Status: 404 Not Found" - - theme_page '[wiki]/404/' +theme_error(){ + local errno="$1" + + 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]/$errno/")" ]; then + theme_page "/[wiki]/$errno/" + else + printf "Content-Length: 0\r\n\r\n" + fi }