--- /dev/null
+#!/bin/sh
+
+case $PATH_INFO in
+ */\[newpage\]):;;
+ *) return 1;;
+esac
+
+if [ "$(POST action)" != newpage ]; then
+ printf 'Refresh: %i; url=%s\r\n' 4 ./
+ export ERROR_MSG="Formdata invalid"
+ theme_error 400
+ return 0
+fi
+
+pattern="$(POST pattern)"
+template="$(POST template)"
+page="$(POST page)"
+
+if [ "$page" ]; then
+ pattern="$(date +"$pattern")"
+ page="$(printf -- "$pattern" "$page")"
+else
+ printf 'Refresh: %i; url=%s\r\n' 4 ./
+ export ERROR_MSG="Page name required"
+ theme_error 400
+ return 0
+fi
+
+page="$(page_abs "$page")"
+[ "$template" ] \
+&& template="$(page_abs "$template")" \
+|| template="$page"
+
+if [ -f "$_DATA/pages/$page/#page.md" -o \
+ -f "$_EXEC/pages/$page/#page.md" ]; then
+ printf 'Refresh: %i; url=%s\r\n' 4 ./
+ export ERROR_MSG="Page exists already"
+ theme_error 409
+ return 0
+
+elif ! acl_write "$page"; then
+ printf 'Refresh: %i; url=%s\r\n' 4 ./
+ export ERROR_MSG="You don't have permission to write to this page"
+ theme_error 403
+ return 0
+
+elif mkdir -p -- "$_DATA/pages/${page}" \
+ && S_LOCK "$_DATA/pages/$page/#page.md"; then
+ theme_editor "$page" "$template"
+ return 0
+
+else
+ printf 'Refresh: %i; url=%s\r\n' 4 ./
+ export ERROR_MSG="Unable to lock page for editing"
+ theme_error 409
+ return 0
+fi
+
+return 1
--- /dev/null
+#!/bin/sh
+
+. "$_EXEC/cgilite/cgilite.sh"
+. "$_EXEC/acl.sh"
+. "$_EXEC/tools.sh"
+
+pattern=./%%s
+template=''
+label='New Page'
+
+while [ $# -gt 0 ]; do case $1 in
+ template=*) template="${1#*=}"; shift 1;;
+ --template) template="$2"; shift 2;;
+ label=*) label="${1#*=}"; shift 1;;
+ --label) label="$2"; shift 2;;
+ *) pattern="$1"; shift 1;;
+esac; done
+
+if acl_write "$(page_abs "$pattern")"; then
+ cat <<-EOF
+ <form class="macro newpage" method=POST action="[newpage]">
+ <input type=hidden name=pattern value="$(HTML "$pattern")">
+ <input type=hidden name=template value="$(HTML "$template")">
+ $([ ! "${pattern##*%%s*}" ] \
+ && printf '<input name=page placeholder="page name">'
+ )<button type=submit name=action value=newpage>$(HTML "$label")</button>
+ </form>
+ EOF
+fi
}
theme_editor(){
- local page="$1" title
+ local page="$1" template="$2" title
title="${page%/}"; title="${title##*/}"
if ! acl_write "$page"; then
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>