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 l10n_immutablepage >/dev/null 2>&1 \
18 || l10n_immutablepage(){ #TRANSLATION
20 <h1>Immutable Page</h1>
21 This is a core page of the wiki system. Its name and position cannot be changed.
22 You may however update this page and you can use ACLs to hide it from various listings.
26 case "${PATH_INFO}" in
27 */\[move\]|*/\[rename\]|*/\[delete\])
28 page="${PATH_INFO%\[*\]}"
29 if [ ! -d "$_DATA/pages/${page}" -a ! -d "$_EXEC/pages/${page}" ]; then
32 elif ! acl_write "$page"; then
33 printf 'Refresh: %i, url=%s\r\n' 4 ./
36 elif [ ! -d "$_DATA/pages/${page}" -a -d "$_EXEC/pages/${page}" ]; then
50 l10n_movepage >/dev/null 2>&1 \
51 || l10n_movepage(){ # TRANSLATION
54 <p class="pageid">$(HTML "${page}")</p>
55 <input name="newlocation" value="$(HTML "$location")" placeholder="New Location">
57 <li>A page with the same name must not already exist at the new location.</li>
58 <li>You must have permission to create new pages at this location.</li>
59 <li>All subpages will become available under the new path name.</li>
60 <li>Subpages will become unavailable under their current name.</li>
62 <button type=submit name=action value=move>Move</button>
63 <button type=submit name=action value=cancel>Cancel</button>
66 l10n_renamepage >/dev/null 2>&1 \
67 || l10n_renamepage(){ # TRANSLATION
70 <p class="pageid">$(HTML "${page}")</p>
71 <input name="newname" value="$(HTML "$name")" placeholder="New Name">
73 <li>A page with the new name must not already exist.</li>
74 <li>You must have permission to create new pages at this location.</li>
75 <li>All subpages will become available under the new path name.</li>
76 <li>Subpages will become unavailable under their current name.</li>
78 <button type=submit name=action value=rename>Rename</button>
79 <button type=submit name=action value=cancel>Cancel</button>
82 l10n_deletepage >/dev/null 2>&1 \
83 || l10n_deletepage(){ # TRANSLATION
86 <p class="pageid">$(HTML "${page}")</p>
87 <p>This page and its attachments will be deleted</p>
88 <input type=checkbox name=delete_subpages value=true id=delsub><label for=delsub>Delete subpages</label>
91 [ "$REV_PAGES" = true ] \
92 && printf ' <li>Past revisions of the page text (including the current one) will remain accessible and can be restored.</li>'
93 [ "$REV_PAGES" = true -a "$REV_ATTACHMENTS" = true ] \
94 && printf ' <li>Attachments can be restored as well.</li>' \
95 || printf ' <li>Attachments will be deleted completely, and cannot be restored.</li>'
97 <li class="delsub">Subpages will not be affected and can still be accessed normally.</li>
99 <button type=submit name=action value=delete>Delete</button>
100 <button type=submit name=action value=cancel>Cancel</button>
105 local PATH_INFO page="${1%/}/"
107 if acl_write "$page"; then
110 | while read page; do
111 list_writable "${PATH_INFO}${page}"
113 printf %s\\n "$page" |debug
117 if [ "$REQUEST_METHOD" = POST ]; then
118 action="$(POST action)"
119 newname="$(POST newname |grep -m1 -xE '[^#/]*')"
120 newlocation="$(POST newlocation |grep -m1 -xE '/[^#]*')"
121 delsub="$(POST delete_subpages |grep -m1 -xE 'true|false')"
122 else case "${PATH_INFO}" in
124 location="${page%/}" location="${location%/*}/"
126 <form method=POST id=movepage>
127 <input type=hidden name=session_id value="$SESSION_KEY">
134 name="${page%/}" name="${name##*/}"
136 <form method=POST id=renamepage>
137 <input type=hidden name=session_id value="$SESSION_KEY">
145 <form method=POST id=deletepage>
146 <input type=hidden name=session_id value="$SESSION_KEY">
155 if [ "$action" = rename -a "$newname" ]; then
156 oldname="${PATH_INFO%\[*\]}"
157 newname="${oldname%/*/}$(PATH "${newname}/")"
159 if [ -d "$_DATA/pages/$newname" ]; then
160 printf 'Refresh: %i\r\n' 4
161 export ERROR_MSG="A location of that name already exists."
164 elif ! acl_write "$oldname" || ! acl_write "$newname"; then
165 printf 'Refresh: %i\r\n' 4
168 elif [ "$REV_PAGES" = true ]; then
169 git -C "$_DATA" mv "pages/$oldname" "pages/$newname"
170 git -C "$_DATA" commit -m 'Page # '"$oldname"' # renamed to # '"$newname"' # by user @ '"$USER_NAME"' @' \
171 -- "pages/$oldname" "pages/$newname"
172 REDIRECT "$_BASE${newname}"
174 mv -- "$_DATA/pages/$oldname" "$_DATA/pages/$newname"
175 REDIRECT "$_BASE${newname}"
177 elif [ "$action" = move -a "$newlocation" ]; then
178 oldname="${PATH_INFO%\[*\]}"
179 newlocation="$(PATH "$newlocation")"
180 newname="${oldname%/}"
181 newname="${newlocation%/}/${newname##*/}/"
183 if [ -d "$_DATA/pages/$newname" ]; then
184 printf 'Refresh: %i\r\n' 4
185 export ERROR_MSG="A page of that name already exists at the given location."
188 elif [ ! -d "$_DATA/pages/$newlocation" ]; then
189 printf 'Refresh: %i\r\n' 4
190 export ERROR_MSG="The given location does not exist."
193 elif ! acl_write "$oldname" || ! acl_write "$newname"; then
194 printf 'Refresh: %i\r\n' 4
197 elif [ "$REV_PAGES" = true ]; then
198 git -C "$_DATA" mv "pages/${oldname}" "pages/${newname}"
199 git -C "$_DATA" commit -m 'Page # '"$oldname"' # moved to # '"$newname"' # by user @ '"$USER_NAME"' @' \
200 -- "pages/${oldname}" "pages/${newname}"
201 REDIRECT "$_BASE${newname}"
203 mv -- "$_DATA/pages/$oldname" "$_DATA/pages/$newname"
204 REDIRECT "$_BASE${newname}"
206 elif [ "$action" = delete ]; then
207 oldname="${PATH_INFO%\[*\]}"
208 if ! acl_write "$oldname"; then
209 printf 'Refresh: %i\r\n' 4
214 printf 'Status: 202 Accepted\r\n'
215 { [ "$delsub" = true ] \
216 && list_writable "$oldname" \
217 || printf %s\\n "$oldname"
218 } | while read oldname; do
219 if [ "$REV_PAGES" = true -a "$REV_ATTACHMENTS" = true ]; then
220 git -C "$_DATA" rm "pages/${oldname}/#page.md" >&2
221 git -C "$_DATA" rm -r "pages/${oldname}/#attachments/" >&2
222 git -C "$_DATA" commit -m 'Page # '"$oldname"' # deleted by user @ '"$USER_NAME"' @' \
223 -- "pages/${oldname}/#page.md" "pages/${oldname}/#attachments/" >&2
224 rm -r -- "$_DATA/pages/${oldname}"/\#*
225 rmdir -- "$_DATA/pages/${oldname}/" || true
226 elif [ "$REV_PAGES" = true ]; then
227 git -C "$_DATA" rm "pages/${oldname}/#page.md" >&2
228 git -C "$_DATA" commit -m 'Page # '"$oldname"' # deleted by user @ '"$USER_NAME"' @' \
229 -- "pages/${oldname}/#page.md" >&2
230 rm -r -- "$_DATA/pages/${oldname}"/\#*
231 rmdir -- "$_DATA/pages/${oldname}/" || true
233 rm -- "$_DATA/pages/${oldname}/#page.md"
234 rm -r -- "$_DATA/pages/${oldname}"/\#*
235 rmdir -- "$_DATA/pages/${oldname}/" || true
237 printf '%s\n' "$oldname"
240 <article id="deleteconfirm">
241 <h1>$(_ "Pages deleted:")</h1>
243 $(while read page; do
244 printf '<li>%s</li>' "$(HTML $page)"
247 <a class="button" href="./">$(_ OK)</a>
252 elif [ "$action" = cancel ]; then
254 elif [ "$action" ]; then
255 printf 'Refresh: %i\r\n' 4
256 export ERROR_MSG="Missing parameters."