--- /dev/null
+#!/bin/sh
+
+case "${PATH_INFO}" in
+ */\[move\]|*/\[rename\]|*/\[delete\])
+ page="${PATH_INFO%\[*\]}"
+ if [ ! -d "$_DATA/pages/${page}" -a ! -d "$_EXEC/pages/${page}" ]; then
+ theme_error 404
+ return 0
+ elif ! acl_write "$page"; then
+ printf 'Refresh: %i, url=%s\r\n' 4 ./
+ theme_error 403
+ return 0
+ elif [ -d "$_EXEC/pages/${page}/" ]; then
+ theme_page - <<-EOF
+ <article>
+ <p class=error>
+ <h1>Immutable Page</h1>
+ This is a core page of the wiki system. Its name and position cannot be changed.
+ You may however update this page and you can use ACLs to hide it from various listings.
+ </p>
+ </article>
+ EOF
+ return 0
+ fi
+ ;;
+ *) return 1;;
+esac
+
+if [ "$REQUEST_METHOD" = POST ]; then
+ action="$(POST action)"
+ newname="$(POST newname |grep -m1 -xE '[^#/]*')"
+ newlocation="$(POST newlocation |grep -m1 -xE '/[^#]*')"
+else case "${PATH_INFO}" in
+ */\[move\])
+ location="${page%/}" location="${location%/*}/"
+ theme_page - <<-EOF
+ <form method=POST id=movepage>
+ <input type=hidden name=session_id value="$SESSION_KEY">
+ <h1>Move Page</h1>
+ <p class="pageid">$(HTML "${page}")</p>
+ <input name="newlocation" value="$(HTML "$location")" placeholder="New Location">
+ <ul>
+ <li>A page with the same name must not already exist at the new location.</li>
+ <li>You must have permission to create new pages at this location.</li>
+ <li>All subpages will become available under the new path name.</li>
+ <li>Subpages will become unavailable under their current name.</li>
+ </ul>
+ <button type=submit name=action value=move>Move</button>
+ <button type=submit name=action value=cancel>Cancel</button>
+ </form>
+ EOF
+ return 0
+ ;;
+ */\[rename\])
+ name="${page%/}" name="${name##*/}"
+ theme_page - <<-EOF
+ <form method=POST id=renamepage>
+ <input type=hidden name=session_id value="$SESSION_KEY">
+ <h1>Rename Page</h1>
+ <p class="pageid">$(HTML "${page}")</p>
+ <input name="newname" value="$(HTML "$name")" placeholder="New Name">
+ <ul>
+ <li>A page with the new name must not already exist.</li>
+ <li>You must have permission to create new pages at this location.</li>
+ <li>All subpages will become available under the new path name.</li>
+ <li>Subpages will become unavailable under their current name.</li>
+ </ul>
+ <button type=submit name=action value=rename>Rename</button>
+ <button type=submit name=action value=cancel>Cancel</button>
+ </form>
+ EOF
+ return 0
+ ;;
+ */\[delete\])
+ theme_page - <<-EOF
+ <form method=POST id=deletepage>
+ <input type=hidden name=session_id value="$SESSION_KEY">
+ <h1>Delete Page</h1>
+ <p class="pageid">$(HTML "${page}")</p>
+ <p>This page and its attachments will be deleted</p>
+ <ul>
+ <li>Past revisions of the page text (including the current one) will remain accessible and can be restored.</li>
+ <li>Attachments will be deleted completely, and cannot be restored.</li>
+ <li>Subpages will not be affected and can still be accessed normally.</li>
+ </ul>
+ <button type=submit name=action value=delete>Delete</button>
+ <button type=submit name=action value=cancel>Cancel</button>
+ </form>
+ EOF
+ return 0
+ ;;
+ esac
+fi
+
+if [ "$action" = rename -a "$newname" ]; then
+ oldname="${PATH_INFO%\[*\]}"
+ newname="${oldname%/*/}$(PATH "${newname}/")"
+
+ if [ -d "$_DATA/pages/$newname" ]; then
+ printf 'Refresh: %i\r\n' 4
+ export ERRORMSG="A location of that name already exists."
+ theme_error 400
+ return 0
+ elif ! acl_write "$oldname" || ! acl_write "$newname"; then
+ printf 'Refresh: %i\r\n' 4
+ theme_error 403
+ return 0
+ else
+ git -C "$_DATA" mv "pages/$oldname" "pages/$newname"
+ git -C "$_DATA" commit -m 'Page # '"$oldname"' # renamed to # '"$newname"' # by user @ '"$USER_NAME"' @' \
+ -- "pages/$oldname" "pages/$newname"
+ REDIRECT "$_BASE${newname}"
+ fi
+elif [ "$action" = move -a "$newlocation" ]; then
+ oldname="${PATH_INFO%\[*\]}"
+ newlocation="$(PATH "$newlocation")"
+ newname="${oldname%/}"
+ newname="${newlocation%/}/${newname##*/}/"
+
+ if [ -d "$_DATA/pages/$newname" ]; then
+ printf 'Refresh: %i\r\n' 4
+ export ERRORMSG="A page of that name already exists at the given location."
+ theme_error 400
+ return 0
+ elif [ ! -d "$_DATA/pages/$newlocation" ]; then
+ printf 'Refresh: %i\r\n' 4
+ export ERRORMSG="The given location does not exist."
+ theme_error 400
+ return 0
+ elif ! acl_write "$oldname" || ! acl_write "$newname"; then
+ printf 'Refresh: %i\r\n' 4
+ theme_error 403
+ return 0
+ else
+ git -C "$_DATA" mv "pages/${oldname}" "pages/${newname}"
+ git -C "$_DATA" commit -m 'Page # '"$oldname"' # moved to # '"$newname"' # by user @ '"$USER_NAME"' @' \
+ -- "pages/${oldname}" "pages/${newname}"
+ REDIRECT "$_BASE${newname}"
+ fi
+elif [ "$action" = delete ]; then
+ oldname="${PATH_INFO%\[*\]}"
+ if ! acl_write "$oldname"; then
+ printf 'Refresh: %i\r\n' 4
+ theme_error 403
+ return 0
+ else
+ git -C "$_DATA" rm "pages/${oldname}/#page.md"
+ git -C "$_DATA" commit -m 'Page # '"$oldname"' # deleted by user @ '"$USER_NAME"' @' \
+ -- "pages/${oldname}/#page.md"
+ rm -r -- "$_DATA/pages/${oldname}"/\#*
+ rmdir -- "$_DATA/pages/${oldname}/" || true
+ REDIRECT ./
+ fi
+fi