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.
22 <meta name="viewport" content="width=device-width">
24 for css in "$_BASE/%5B.%5D/cgilite/common.css" "$_BASE/%5B.%5D/themes/default.css" $PAGE_CSS; do
25 printf '<link rel="stylesheet" type="text/css" href="%s">' \
26 "$(HTML "${css##*//}")"
31 printf '<header>%s</header>' "$(wiki '[wiki]/header/')"
35 printf '<footer>%s</footer>' "$(wiki '[wiki]/footer/')"
41 if acl_write "$page"; then
44 <li><a href="./%5Bview%5D">$(_ View)</a></li>
45 <li><a href="./%5Bedit%5D">$(_ Edit)</a></li>
46 <li><a href="./%5Battachment%5D">$(_ Attachments)</a></li>
47 <li><a href="./%5Brevision%5D">$(_ Revisions)</a></li>
48 <li><a href="./%5Brename%5D">$(_ Rename)</a></li>
49 <li><a href="./%5Bmove%5D">$(_ Move)</a></li>
50 <li><a href="./%5Bdelete%5D">$(_ Delete)</a></li>
57 local page="$1" title="$2"
58 title="$(HTML "${title:-"${PAGE_TITLE:-"${page}"}"}")"
60 # Important! Web Server response including newline
61 printf "%s\r\n" "Content-Type: text/html; charset=utf-8" ""
65 <html${LANGUAGE:+ lang=\"${LANGUAGE}\"}><head>
67 <title>${title}</title>
68 </head><body id="$(HTML "${PATH_INFO}")">
72 $(if [ "$page" = '-' ]; then
86 local page="$1" template="$2" file att
88 [ "$template" ] && acl_read "$template" || template="$page"
90 theme_page - "$(_ Editor): ${PAGE_TITLE:-"${page}"}" <<-EOF
91 <input checked type=radio class=tab name=edithelp value=edtr id=editor><label for=editor>$(_ Editor)</label>
92 <input type=radio class=tab name=edithelp value=help id=syntax><label for=syntax>$(_ Syntax)</label>
93 <input type=radio class=tab name=edithelp value=att id=attach><label for=attach>$(_ Attachments)</label>
94 $([ "$LANGUAGE_DEFAULT" -a "$LANGUAGE_DEFAULT" != "$LANGUAGE" ] && printf '
95 <input type=radio class=tab name=edithelp value=att id=transl><label for=transl>%s</label>
98 <form class="tab editor" method=POST action="$(HTML "${_BASE}${page%/}/[edit]")">
99 <input type=hidden name=session_key value="${SESSION_KEY}"/>
100 <textarea name=pagetext>$({ wiki_text "$page" \
101 || wiki_text "$template"; } |HTML)</textarea>
102 <button type=submit name=action value=update>$(_ Update)</button>
103 <button type=submit name=action value=cancel>$(_ Cancel)</button>
105 <div class="tab syntax">$(wiki "/[wiki]/editorhelp/")</div>
106 <div class="tab attach">
107 $(for file in "$_EXEC/pages/${page%/:$LANGUAGE/}/#attachments"/* "$_DATA/pages/${page%/:$LANGUAGE/}/#attachments"/*; do
108 [ "$file" = "$_EXEC/pages/${page%/:$LANGUAGE/}/#attachments/${file##*/}" \
109 -a -f "$_DATA/pages/${page%/:$LANGUAGE/}/#attachments/${file##*/}" ] && continue
110 att="$(HTML "${file##*/}")"
111 url="$(printf %s\\n "${file##*/}" |sed 's;[\\<>];\\&;g' |HTML)"
112 name="$(printf %s\\n "${file##*/}" |sed 's;[]\\[];\\&;g' |HTML)"
115 *.[pP][nN][gG]|*.[jJ][pP][gG]|*.[jJ][pP][eE][gG]|*.[gG][iI][fF])
116 [ "$page" != "${page%/:$LANGUAGE/}" ] && p=../ || p=''
117 printf '<p class=aimg><img src="%s%s">![](<%s>)</p><ul class=aimg>
118 <li>[%s](<[attachment]/%s>)</li>
119 <li>[![%s](<%s>)](<[attachment]/%s>)</li>
121 "$p" "$att" "$url" "$name" "$url" "$name" "$url" "$url"
124 printf '<p class="adoc">[%s](<%s>)</p>' "$name" "$url"
129 $(if [ "$LANGUAGE_DEFAULT" -a "$LANGUAGE_DEFAULT" != "$LANGUAGE" ]; then
130 printf '<div class="tab transl">%s</div>' "$(LANGUAGE='' wiki_text "${page%/:$LANGUAGE/}" |HTML)"
135 theme_revisions(){ theme_page "$@"; }
139 # STDIN: [STRING page][TAB][STRING teaser]
141 theme_page - "$(_ Search results): ${words}" <<-EOF
143 <h1>$([ "$words" ] && _ "Search results" || _ "Search" )</h1>
144 <form class="search" method="GET">
145 <input type="search" name="q" value="$(HTML $words)"><button class="search" type="submit">$(_ Search)</button>
147 <ol class="searchresults">
148 $(while read -r p t; do
149 path="$(UNSTRING "$p")" pfrag="${path%/}" title=''
150 while [ "$pfrag" ]; do
151 title="$(page_title "$pfrag")/$title"
154 printf '<li><a href="%s">%s</a><p>%s</p></li>' \
155 "$(URL "$path")" "$(HTML "/$title")" "$(UNSTRING "$t" |HTML)"
165 if acl_write "$page"; then
166 theme_page - "$(_ Attachments): ${PAGE_TITLE:-"${page}"}" <<-EOF
167 <form class=upload method=POST enctype="multipart/form-data">
169 <input type=hidden name=session_id value="$SESSION_ID">
170 <input type=file name=file multiple>
171 <button type=submit name=action value=upload>$(_ Upload)</button>
175 <h2>$(_ Attachments)</h2>
176 <input type=hidden name=session_key value="$SESSION_KEY">
177 <input checked type=radio class=tab name=attachaction value=view id=tview><label for=tview>$(_ View)</label>
178 <input type=radio class=tab name=attachaction value=del id=tdel ><label for=tdel >$(_ Delete)</label>
179 <input type=radio class=tab name=attachaction value=move id=tmove><label for=tmove>$(_ Move)</label>
180 <input type=radio class=tab name=attachaction value=ren id=tren ><label for=tren >$(_ Rename)</label>
182 <ul class="attachment list">
183 $(for file in "$_EXEC/pages/$page/#attachments"/* "$_DATA/pages/$page/#attachments"/*; do
184 [ "$file" = "$_EXEC/pages/$page/#attachments/${file##*/}" \
185 -a -f "$_DATA/pages/$page/#attachments/${file##*/}" ] && continue
186 stat="$(stat -c '%s %Y' -- "$file" 2>&-)" || continue
187 size="${stat% *}" date="${stat#* }"
188 hfile="$(HTML "${file##*/}")"
190 printf '<li><input id="select_%s" type=checkbox name=select value="%s">
191 <label class=name for="select_%s">%s</label>
192 <input class=name name="rename_%s" value="" placeholder="%s" />
193 <a class=name href="[attachment]/%s">%s</a>
194 <span class=size>%s</span>
195 <span class=date>%s</span>
197 "$hfile" "$hfile" "$hfile" "$hfile" \
198 "$(slopecode "${file##*/}")" "$hfile" "$hfile" "$hfile" \
199 "$(size_human "$size")" "$(date -d @"$date" +"%F %T")"
202 <button type=submit name=action value=delete>$(_ Delete)</button>
203 <label for=moveto>$(_ Move To:)</label>
204 <input id="moveto" name="moveto" value="$(HTML "$page")" placeholder="$(_ page name)">
205 <button type=submit name=action value=move >$(_ Move)</button>
206 <button type=submit name=action value=rename>$(_ Rename)</button>
211 theme_page - "$(_ Attachments): ${PAGE_TITLE:-"${page}"}" <<-EOF
212 <ul class="attachment list">
213 $(for file in "$_EXEC/pages/$page/#attachments"/* "$_DATA/pages/$page/#attachments"/*; do
214 [ "$file" = "$_EXEC/pages/$page/#attachments/${file##*/}" \
215 -a -f "$_DATA/pages/$page/#attachments/${file##*/}" ] && continue
216 stat="$(stat -c '%s %Y' -- "$file" 2>&-)" || continue
217 size="${stat% *}" date="${stat#* }"
218 hfile="$(HTML "${file##*/}")"
220 printf '<li><a class=name href="%s">%s</a>
221 <span class=size>%s</span><span class=date>%s</span></li>' \
222 "$hfile" "$hfile" "$(size_human "$size")" "$(date -d @"$date" +"%F %T")"
233 400) printf "%s\r\n" "Status: 400 Bad Request";;
234 403) printf "%s\r\n" "Status: 403 Forbidden";;
235 404) printf "%s\r\n" "Status: 404 Not Found";;
236 409) printf "%s\r\n" "Status: 409 Conflict";;
237 500) printf "%s\r\n" "Status: 500 Internal Server Error";;
240 if mdfile "/[wiki]/$errno/" >&-; then
241 theme_page "/[wiki]/$errno/"
243 printf "Content-Length: 0\r\n\r\n"