wok-tiny view wiki/stuff/var/www/wiki/index.sh @ rev 142

Remove ashism ==
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Feb 27 17:43:23 2019 +0100 (6 months ago)
parents 48d2c4c7a227
children
line source
1 #!/bin/sh
2 #
3 # TazWikiss - A tiny Wiki for busybox/httpd
4 # Licence GNU/GPLv2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
5 # Copyright (C) Pascal Bellard
6 # Based on WiKiss - http://wikiss.tuxfamily.org/
8 . /usr/bin/httphelper.sh
10 cd $(dirname $0)
11 CONFIG=config-${HTTP_ACCEPT_LANGUAGE%%[,;_-]*}.sh
12 [ -x "$CONFIG" ] || CONFIG=config.sh
13 . ./$CONFIG
15 WIKI_VERSION="Based on WiKiss 0.3"
17 # Initialisations
18 toc='' # Table Of Content
19 CONTENT='' # contenu de la page
20 HISTORY='' # lien vers l'historique
21 plugins_dir="plugins/" # repertoire ou stocker les plugins
22 template="template.html" # Fichier template
23 PAGE_TITLE_link=true # y-a-t-il un lien sur le titre de la page ?
24 editable=true # la page est editable
25 urlbase="$SCRIPT_NAME"
26 #urlbase="./"
28 die()
29 {
30 echo $@
31 exit
32 }
34 redirect()
35 {
36 awk '{ printf "%s\r\n",$0 }' <<EOT
37 HTTP/1.0 302 Found
38 location: $1
40 EOT
41 exit
42 }
44 cache_auth()
45 {
46 local tmp
47 tmp="$(echo $1$(date +%d) | md5sum | cut -c1-8)"
48 [ "$(POST sc)" = "$1" ] && AUTH=$tmp || [ "$AUTH" = "$tmp" ]
49 }
51 authentified()
52 {
53 [ -n "$PASSWORDS" ] && for i in $PASSWORDS ; do
54 cache_auth "$i" && return
55 done
56 cache_auth "$PASSWORD"
57 }
59 sedesc()
60 {
61 echo "$1" | sed 's|[/&"]|\\&|g' | \
62 sed ':a;N;$!ba;s|\n|\\n|g;s|'$(echo -en "\r")'||g'
63 }
65 plugin_call_method()
66 {
67 local status
68 local name
69 name=$1
70 shift
71 [ -d "$plugins_dir" ] || return
72 status=false
73 for i in $plugins_dir/*.sh ; do
74 [ -x $i ] || continue
75 grep -q "^$name()" $i || continue
76 . $i
77 eval $name "$@"
78 [ $? = 0 ] && status=true
79 done 2> /tmp/tazwiki$$stderr
80 [ -s /tmp/tazwiki$$stderr ] &&
81 logger -t "httpd/wiki/plugin" < /tmp/tazwiki$$stderr
82 rm -f /tmp/tazwiki$$stderr 2> /dev/null
83 $status
84 }
86 curdate()
87 {
88 date '+%Y-%m-%d %H:%M'
89 }
91 filedate()
92 {
93 stat -c %y $1 | sed -e 's|-|/|g' -e 's/\(:..\):.*/\1/'
94 }
96 AUTH=$(GET auth)
97 [ -n "$AUTH" ] || AUTH=$(POST auth)
98 PAGE_TITLE="$(GET page)"
99 [ -n "$PAGE_TITLE" ] || PAGE_TITLE="$(POST page)"
100 if [ -z "$PAGE_TITLE" ]; then
101 PAGE_TITLE="$START_PAGE"
102 case "$(GET action)" in
103 recent) PAGE_TITLE="$RECENT_CHANGES" ;;
104 search) PAGE_TITLE="$LIST"
105 [ -n "$(GET query)" ] && PAGE_TITLE="$SEARCH_RESULTS $(GET query)"
106 esac
107 fi
108 case "$PAGE_TITLE" in
109 */*|*\&*) PAGE_TITLE="$START_PAGE" ;;
110 esac
111 gtime=$(GET time)
112 case "$gtime" in
113 */*|*\&*) gtime="" ;;
114 esac
115 action=$(GET action)
116 datew="$(curdate)"
117 content="$(POST content)"
119 # Ecrire les modifications, s'il y a lieu
120 PAGE_txt="$PAGES_DIR$PAGE_TITLE.txt"
121 plugin_call_method "init" $PAGE_txt
122 if [ -n "$content" ]; then # content => page
123 if authentified; then
124 CR="$(echo -en '\r')"
125 sed 's/</\&lt;/g;s/'$CR' /'$CR'\n/g' > $PAGE_txt <<EOT
126 $POST_content_1
127 EOT
128 if [ -n "$BACKUP_DIR" ]; then
129 complete_dir_s="$BACKUP_DIR$PAGE_TITLE/"
130 if [ ! -d "$complete_dir_s" ]; then
131 mkdir -p $complete_dir_s
132 chmod 777 $complete_dir_s
133 fi
134 cat >> "$complete_dir_s$(curdate).bak" <<EOT
136 // $datew / $REMOTE_ADDR
137 $(cat $PAGE_txt)
138 EOT
139 fi
140 plugin_call_method "writedPage" $PAGE_txt
141 PAGE_TITLE="$PAGE_TITLE&auth=$AUTH"
142 else
143 PAGE_TITLE="$PAGE_TITLE&action=edit&error=1"
144 fi
145 redirect "$urlbase?page=$PAGE_TITLE"
146 fi
148 if [ -r "$PAGE_txt" -o -n "$action" ]; then
149 CONTENT=""
150 if [ -e "$PAGE_txt" ]; then
151 TIME=$(filedate "$PAGE_txt")
152 CONTENT="$(cat "$PAGE_txt")"
153 fi
154 # Restaurer une page
155 [ -n "$(GET page)" -a -n "$gtime" -a "$(GET restore)" = 1 ] &&
156 [ -r "$BACKUP_DIR$PAGE_TITLE/$gtime" ] &&
157 CONTENT="$(cat $BACKUP_DIR$PAGE_TITLE/$gtime)"
158 CONTENT="$(sed -e 's/\$/\&#036;/g' -e 's/\\/\&#092;/g' <<EOT
159 $CONTENT
160 EOT
161 )"
162 else
163 CONTENT="$(sed -e "s/%page%/$(sedesc "$PAGE_TITLE")/" <<EOT
164 $DEFAULT_CONTENT
165 EOT
166 )"
167 fi
169 htmldiff()
170 {
171 local files
172 local old
173 local new
174 old="$BACKUP_DIR$(GET page)/$1"
175 new="$BACKUP_DIR$(GET page)/$2"
176 [ -s "$old" ] || old=/dev/null
177 [ -n "$2" -a "$2" != "none" ] || new=$PAGES_DIR$(GET page).txt
178 files="$old $new"
179 [ "$old" -nt "$new" -a "$old" != "/dev/null" ] && files="$new $old"
180 diff -aU 99999 $files | sed -e '1,3d' -e '/^\\/d' -e 's|$|<br/>|' \
181 -e 's|^-\(.*\)$|<font color=red>\1</font>|' \
182 -e 's|^+\(.*\)$|<font color=green>\1</font>|'
183 }
185 # Actions speciales du Wiki
186 case "$action" in
187 edit)
188 editable=false
189 HISTORY="<a href=\"$urlbase?page=$(urlencode $PAGE_TITLE)&amp;action=history\" accesskey=\"6\" rel=\"nofollow\">$HISTORY_BUTTON</a><br />"
190 CONTENT="$(sed 's/%/\&#37;/g' <<EOT
191 $CONTENT
192 EOT
193 )"
194 CONTENT="<form method=\"post\" action=\"$urlbase\">
195 <textarea name=\"content\" cols=\"83\" rows=\"30\" style=\"width: 100%;\">
196 $CONTENT
197 </textarea>
198 <input type=\"hidden\" name=\"page\" value=\"$PAGE_TITLE\" /><br />
199 <p align=\"right\">"
200 if authentified; then
201 CONTENT="$CONTENT<input type=\"hidden\" value=\"$(POST password)\""
202 else
203 CONTENT="$CONTENT$MDP : <input type=\"password\""
204 fi
205 CONTENT="$CONTENT name=\"sc\" /> <input type=\"submit\" value=\"$DONE_BUTTON\" accesskey=\"s\" /></p></form>"
206 ;;
207 history)
208 complete_dir="$BACKUP_DIR$PAGE_TITLE/"
209 if [ -n "$gtime" ]; then
210 HISTORY="<a href=\"$urlbase?page=$PAGE_TITLE&amp;action=history\" rel=\"nofollow\">$HISTORY_BUTTON</a>"
211 if [ -r "$complete_dir$gtime" ]; then
212 HISTORY="$HISTORY <a href=\"$urlbase?page=$PAGE_TITLE&amp;action=edit&amp;time=$gtime&amp;restore=1\" rel=\"nofollow\">$RESTORE</a>"
213 CONTENT="$(cat $complete_dir$gtime | sed -e s/$(echo -ne '\r')//g -e 's|$|<br/>|g')"
214 else
215 HISTORY="$HISTORY -"
216 fi
217 else
218 HISTORY="$HISTORY_BUTTON"
219 CONTENT="$NO_HISTORY"
220 if [ -d $complete_dir ]; then
221 CONTENT="<form method=\"GET\" action=\"$urlbase\">\n<input type=hidden name=action value=diff><input type=hidden name=page value=\"$PAGE_TITLE\">"
222 for file in $(ls $complete_dir | sort -r); do
223 CONTENT="$CONTENT
224 <input type=radio name=f1 value=$file><input type=radio name=f2 value=$file />
225 <a href=\"$urlbase?page=$PAGE_TITLE&amp;action=history&amp;time=$file\">$file</a><br />
226 "
227 done
228 CONTENT="$CONTENT<input type=submit value=diff></form>"
229 fi
230 fi ;;
231 diff)
232 if [ -n "$(GET f1)" ]; then
233 HISTORY="<a href=\"$urlbase?page=$(urlencode "$PAGE_TITLE")&amp;action=history\">$HISTORY_BUTTON</a>"
234 CONTENT="$(htmldiff "$(GET f1)" "$(GET f2)" )"
235 else
236 # diff auto entre les 2 dernières versions
237 ls "$BACKUP_DIR$PAGE_TITLE/" | ( sort -r ; echo none ; echo ) | head -n 2 | while read f1 f2; do
238 redirect "$urlbase?page=$(urlencode "$PAGE_TITLE")&action=$action&f1=$f1&f2=$f2"
239 done
240 fi ;;
241 search)
242 PAGE_TITLE_link=false
243 editable=false
244 query="$(GET query)"
245 n=0
246 for file in $(ls $PAGES_DIR/*.txt 2> /dev/null | sort) ; do
247 [ -e $file ] || continue
248 echo $file | grep -qs "$query" $file /dev/stdin || continue
249 file=$(basename $file ".txt")
250 CONTENT="$CONTENT<a href=\"$urlbase?page=$file\">$file</a><br />
251 "
252 n=$(($n + 1))
253 done
254 PAGE_TITLE="$PAGE_TITLE ($n)" ;;
255 recent)
256 PAGE_TITLE_link=false
257 editable=false
258 n=0
259 for file in $(ls -l $PAGES_DIR/*.txt 2> /dev/null | awk '{ print $9 }' | tail -n 10) ; do
260 filename=$(basename $file ".txt")
261 timestamp=$(filedate $file)
262 CONTENT="$CONTENT<a href=\"$urlbase?page=$filename\">$filename</a> ($timestamp - <a href=\"$urlbase?page=$filename&amp;action=diff\">diff</a>)<br />
263 "
264 done ;;
265 '') ;;
266 *)
267 plugin_call_method "action" $action || action="" ;;
268 esac
269 if [ -z "$action" ]; then
270 if echo "$CONTENT" | grep -q '%html%\s'; then
271 CONTENT="$(sed 's/%html%\s//' <<EOT
272 $CONTENT
273 EOT
274 )"
275 else
276 tmpdir=/tmp/tazwiki$$
277 mkdir $tmpdir
278 unesc="$(echo "$CONTENT" | sed 's/\^\(.\)/\n^\1\n/g' | grep '\^' |\
279 sort | uniq | grep -v "['[!]" | hexdump -e '"" 3/1 "%d " "\n"' |\
280 awk '{ printf "-e '\''s/\\^%c/\\&#%d;/g'\'' ",$2,$2}' | \
281 sed 's/\^\([*.]\)/^\\\1/') \
282 -e 's/\\^'\\''/\\&#39;/g' -e 's/\^\!/\&#33;/g' \
283 -e 's/\^\[/\&#91;/g'"
284 CONTENT="$(eval sed $unesc <<EOT | \
285 sed -e 's/&/\&amp;/g' -e s/$(echo -ne '\r')//g \
286 -e 's/&amp;lt;/\&lt;/g' -e 's/&amp;#\([0-9]\)/\&#\1/g' | \
287 awk -v tmpdir=$tmpdir 'BEGIN { n=1; state=0 } {
288 s=$0
289 while (1) {
290 if (state == 0) {
291 if (match(s,/\{\{/)) {
292 printf "%s<pre><code>{{CODE%s}}</code></pre>",substr(s,1,RSTART-1),n
293 s=substr(s,RSTART+RLENGTH)
294 state=1
295 }
296 else {
297 print s
298 break
299 }
300 }
301 if (state == 1) {
302 if (match(s,/\}\}/)) {
303 printf "%s",substr(s,1,RSTART-1) >> tmpdir "/CODE" n
304 s=substr(s,RSTART+RLENGTH)
305 n++
306 state=0
307 }
308 else {
309 print s >> tmpdir "/CODE" n
310 break
311 }
312 }
313 }
314 }'
315 $CONTENT
316 EOT
317 )"
318 plugin_call_method formatBegin
319 CONTENT="$(sed -e 's/&lt;-->/\&harr;/g' -e 's/&lt;==>/\&hArr;/g'\
320 -e 's/-->/\&rarr;/g' -e 's/&lt;--/\&larr;/g' \
321 -e 's/==>/\&rArr;/g' -e 's/&lt;==/\&lArr;/g' \
322 -e 's/([eE])/\&euro;/g' -e 's/([pP])/\&pound;/g' \
323 -e 's/([yY])/\&yen;/g' -e 's/([tT][mM])/\&trade;/g' \
324 -e 's/([cC])/\&copy;/g' -e 's/([rR])/\&reg;/g' \
325 -e 's/([dD])/\&deg;/g' -e 's/(1\/2)/\&frac12;/g' \
326 -e 's/(1\/4)/\&frac14;/g' -e 's/(3\/4)/\&frac34;/g' \
327 -e 's/(phone)/\&#9742;/' -e 's/(wphone)/\&#9743;/' \
328 -e 's/(skull)/\&#9760;/' -e 's/(radioactive)/\&#9762;/' \
329 -e 's/(sad)/\&#9785;/' -e 's/(smile)/\&#9786;/' \
330 -e 's/(recycle)/\&#9842;/' -e 's/(wheelchair)/\&#9855;/' \
331 -e 's/(wflag)/\&#9872;/' -e 's/(bflag)/\&#9873;/' \
332 -e 's/(anchor)/\&#9875;/' -e 's/(flower)/\&#9880;/' \
333 -e 's/(gear)/\&#9881;/' -e 's/(volt)/\&#9889;/' \
334 -e 's/(warn)/\&#9888;/' -e 's/(star)/\&#9733;/' \
335 -e 's/(&lt;=)/\&le;/g' -e 's/(>=)/\&ge;/g' \
336 -e 's/(!=)/\&ne;/g' -e 's/(+-)/\&plusmn;/g' <<EOT
337 $CONTENT
338 EOT
339 )"
340 rg_url="[0-9a-zA-Z\.\#/~\_%=\?\&,\+\:@;!\(\)\*\$'\-]*" # TODO: verif & / &amp;
341 rg_link_local="$rg_url"
342 rg_link_http="https\?://$rg_url"
343 rg_img_local="$rg_url\.jpe\?g\|$rg_url\.gif\|$rg_url\.png"
344 rg_img_http="$rg_link_http\.jpe\?g\|$rg_link_http\.gif\|$rg_link_http\.png"
346 # image, image link, link, wikipedia, email ...
347 CONTENT="$(sed \
348 -e "s#\[\($rg_img_http\)\]#<img src=\"\1\" alt=\"\1\" style=\"float:\"/>#g" \
349 -e "s#\[\($rg_img_local\)\]#<img src=\"\1\" alt=\"\1\" style=\"float:\"/>#g" \
350 -e "s#\[\($rg_img_http\)|*\([a-z]*\)*\]#<img src=\"\1\" alt=\"\1\" style=\"float:\2;\"/>#g" \
351 -e "s#\[\($rg_img_local\)|*\([a-z]*\)*\]#<img src=\"\1\" alt=\"\1\" style=\"float:\2;\"/>#g" \
352 -e "s#\[\($rg_img_http\)|\($rg_link_http\)|*\([a-z]*\)*\]#<a href=\"\2\" class=\"url\"><img src=\"\1\" alt=\"\1\" title=\"\1\"style=\"float:\3;\"/></a>#g" \
353 -e "s#\[\($rg_img_http\)|\($rg_link_local\)|*\([a-z]*\)*\]#<a href=\"\2\" class=\"url\"><img src=\"\1\" alt=\"\1\" title=\"\1\"style=\"float:\3;\"/></a>#g" \
354 -e "s#\[\($rg_img_local\)|\($rg_link_http\)|*\([a-z]*\)*\]#<a href=\"\2\" class=\"url\"><img src=\"\1\" alt=\"\1\" title=\"\1\"style=\"float:\3;\"/></a>#g" \
355 -e "s#\[\($rg_img_local\)|\($rg_link_local\)|*\([a-z]*\)*\]#<a href=\"\2\" class=\"url\"><img src=\"\1\" alt=\"\1\" title=\"\1\"style=\"float:\3;\"/></a>#g" \
356 -e "s#\[\([^]]*\)|\($rg_link_http\)\]#<a href=\"\2\" class=\"url\">\1</a>#g" \
357 -e "s#\[\([^]]*\)|\($rg_link_local\)\]#<a href=\"\2\" class=\"url\">\1</a>#g" \
358 -e "s#\[\($rg_link_http\)\]#<a href=\"\1\" class=\"url\">\1</a>#g" \
359 -e "s#\([^>\"]\)\($rg_link_http\)#\1<a href=\"\2\" class=\"url\">\2</a>#g" \
360 -e "s#\[?\([^]]*\)\]#<a href=\"http://$LANG.wikipedia.org/wiki/\1\" class=\"url\" title=\"Wikipedia\">\1</a>#g" \
361 -e "s#\[\([^]]*\)\]#<a href=\"$urlbase?page=\1\">\1</a>#g" \
362 -e 's#\([0-9a-zA-Z\./~\-\_][0-9a-zA-Z\./~\-\_]*@[0-9a-zA-Z\./~\-\_][0-9a-zA-Z\./~\-\_]*\)#<a href=\"mailto:\1\">\1</a>#g' \
363 -e 's#^\*\*\*\(.*\)#<ul><ul><ul><li>\1</li></ul></ul></ul>#g' \
364 -e 's#^\*\*\(.*\)#<ul><ul><li>\1</li></ul></ul>#g' \
365 -e 's#^\*\(.*\)#<ul><li>\1</li></ul>#g' \
366 -e 's,^\#\#\#\(.*\),<ol><ol><ol><li>\1</li></ol></ol></ol>,g' \
367 -e 's,^\#\#\(.*\),<ol><ol><li>\1</li></ol></ol>,g' \
368 -e 's,^\#\(.*\),<ol><li>\1</li></ol>,g' \
369 -e "s/$(printf '\r')//" <<EOT | sed \
370 -e ':x;/<\/ol>$/{N;s/\n//;$P;$D;bx;}' | sed \
371 -e ':x;/<\/ul>$/{N;s/\n//;$P;$D;bx;}' | sed \
372 -e ':x;s/<\/ul><ul>//g;tx' -e ':x;s/<\/ol><ol>//g;tx' \
373 -e 's|----*$|<hr />|' -e 's|$|<br />|' \
374 -e 's|</ul>|&\n|g' -e 's|</ol>|&\n|g' \
375 -e 's#</li>#&\n#g' -e 's#\(</h[123456]>\)<br />#\1#g' \
376 -e "s#'--\([^']*\)--'#<del>\1</del>#g" \
377 -e "s#'__\([^']*\)__'#<u>\1</u>#g" \
378 -e "s#'''''\([^']*\)'''''#<strong><em>\1</em></strong>#g" \
379 -e "s#'''\([^']*\)'''#<strong>\1</strong>#g" \
380 -e "s#''\([^']*\)''#<em>\1</em>#g"
381 $CONTENT
382 EOT
383 )"
384 while read link; do
385 [ -s "$PAGES_DIR$link.txt" ] && continue
386 CONTENT="$(sed "s/\\?page=$(sedesc "$link")\"/& class=\"pending\"/" <<EOT
387 $CONTENT
388 EOT
389 )"
390 done <<EOT
391 $(grep "$urlbase?page=" <<EOM | sed -e 's/^.*\?page=\([^"]*\).*$/\1/' -e 's/&.*//'
392 $CONTENT
393 EOM
394 )
395 EOT
396 while echo "$CONTENT" | grep -q '^ ' ; do
397 CONTENT="$(sed 's/^\( *\) \([^ ]\)/\1\&nbsp;\&nbsp;\&nbsp;\&nbsp;\2/' <<EOT
398 $CONTENT
399 EOT
400 )"
401 done
402 read hastoc <<EOT
403 $CONTENT
404 EOT
405 CONTENT="$(sed -e 's/^ /\&nbsp;\&nbsp;\&nbsp;\&nbsp;/' -e '1s/^TOC//' <<EOT
406 $CONTENT
407 EOT
408 )"
409 toc='<div id="toc">'
410 while read line; do
411 [ -n "$line" ] || continue
412 i=$(echo "$line" | sed 's/^!\(!*\).*/\1/' | wc -c)
413 line="$(echo "$line" | sed 's/^!!*//')"
414 label="$(echo "$line" | sed 's/[^\dA-Za-z]/_/g')"
415 toc="$(cat <<EOT
416 $toc
417 <h$i><a href="#$label">$line</a></h$i>
418 EOT
419 )"
420 CONTENT="$(sed "s/^!!* *$(sedesc "$line")\$/<h$i><a name=\"$label\">$(sedesc "$line")<\/a><\/h$i>/" <<EOT
421 $CONTENT
422 EOT
423 )"
424 done <<EOT
425 $(grep "^!" <<EOM | sed -e 's/#/\#/g' -e 's/&/\\\&/g'
426 $CONTENT
427 EOM
428 )
429 EOT
430 toc="$(cat <<EOT
431 $toc
432 </div>
433 EOT
434 )"
435 false &&
436 case "$hastoc" in
437 TOC*) ;;
438 *) toc='';;
439 esac
440 CONTENT="$(awk -v tmpdir=$tmpdir '{
441 s=$0
442 while (1) {
443 if (match(s,/\{\{CODE[0-9]+\}\}/)) {
444 printf "%s" substr(s,1,RSTART-1)
445 system("cat " tmpdir "/" substr(s,RSTART+2,RLENGTH-4))
446 s=substr(s,RSTART+RLENGTH)
447 }
448 else {
449 print s
450 break
451 }
452 }
453 }' <<EOT
454 $CONTENT
455 EOT
456 )"
457 rm -rf $tmpdir
458 plugin_call_method formatEnd
459 fi
460 fi
462 # Remplacement dans le template
463 RECENT="<a href=\"$urlbase?action=recent\" accesskey=\"3\">$RECENT_CHANGES</a>"
464 [ "$action" = "recent" ] && RECENT=$RECENT_CHANGES
465 HOME="<a href=\"$urlbase?page=$START_PAGE\" accesskey=\"1\">$HOME_BUTTON</a>"
466 [ "$PAGE_TITLE" = "$START_PAGE" -a "$action" != "search" ] && HOME=$HOME_BUTTON
467 HELP="\1<a href=\"$urlbase?page=$HELP_BUTTON\" accesskey=\"2\" rel=\"nofollow\">$HELP_BUTTON</a>\2"
468 [ "$action" != "edit" ] && HELP=""
470 [ -r "$template" ] || die "'$template' is missing!"
471 html="$(sed -e "s/{\([^}]*\)RECENT_CHANGES\([^}]*\)}/\1$(sedesc "$RECENT")\2/" \
472 -e "s/{\([^}]*\)HOME\([^}]*\)}/\1$(sedesc "$HOME")\2/" \
473 -e "s/{\([^}]*\)HELP\([^}]*\)}/$(sedesc "$HELP")/" \
474 -e "s/{SEARCH}/<form method=\"get\" action=\"$(sedesc "$urlbase?page=$(urlencode "$PAGE_TITLE" | sed 's/#/\\#/g')")\"><div><input type=\"hidden\" name=\"action\" value=\"search\" \/><input type=\"text\" name=\"query\" value=\"$(sedesc "$(htmlentities $(GET query) )")\" tabindex=\"1\" \/> <input type=\"submit\" value=\"$(sedesc "$SEARCH_BUTTON")\" accesskey=\"q\" \/><\/div><\/form>/" \
475 < $template )"
476 [ "$action" != "" -a "$action" != "edit" -o ! -e "$PAGE_txt" ] && TIME="-"
477 plugin_call_method template
478 [ -n "$(GET error)" ] || ERROR=""
479 [ -n "$HISTORY" ] && HISTORY="\1$HISTORY\2"
480 PAGE_TITLE_str="$(htmlentities "$PAGE_TITLE")"
481 $PAGE_TITLE_link &&
482 PAGE_TITLE_str="<a href=\"$urlbase?page=$(urlencode "$PAGE_TITLE")\">$PAGE_TITLE_str</a>"
483 EDIT="$EDIT_BUTTON"
484 if $editable ; then
485 EDIT="$PROTECTED_BUTTON"
486 [ -w "$PAGE_txt" -o ! -e "$PAGE_txt" ] &&
487 EDIT="<a href=\"$urlbase?page=$(urlencode "$PAGE_TITLE")&amp;action=edit\" accesskey=\"5\" rel=\"nofollow\">$EDIT_BUTTON</a>"
488 fi
489 [ $(echo "$toc" | wc -l) -gt 2 ] && toc="\1$toc\2" || toc=""
490 AUTH_GET=""
491 AUTH_POST=""
492 if authentified; then
493 AUTH_GET="auth=$AUTH&"
494 AUTH_POST="\n<input type=\"hidden\" name=\"auth\" value=\"$AUTH\" />"
495 fi
497 html2="$(sed -e "s/{ERROR}/$(sedesc "$ERROR")/" \
498 -e "s/{WIKI_TITLE}/$(sedesc "$WIKI_TITLE")/" \
499 -e "s/{\([^}]*\)HISTORY\([^}]*\)}/$(sedesc "$HISTORY")/" \
500 -e "s/{PAGE_TITLE}/$(sedesc "$PAGE_TITLE_str")/" \
501 -e "s/{\([^}]*\)EDIT\([^}]*\)}/\1$(sedesc "$EDIT")\2/" \
502 -e "s/{\([^}]*\)TOC\([^}]*\)}/$(sedesc "$toc")/" \
503 -e "s/{PAGE_TITLE_BRUT}/$(sedesc "$(htmlentities "$PAGE_TITLE")")/" \
504 -e "s/{LAST_CHANGE}/$(sedesc "$LAST_CHANGES") :/" \
505 -e "s/{LANG}/$(sedesc "$LANG")/g" \
506 -e "s/href=\"?/href=\"$(sedesc "$urlbase?$AUTH_GET")/g" \
507 -e "s/action=\"$(sedesc "$urlbase")\">/&$(sedesc "$AUTH_POST")/g" \
508 -e "s/{WIKI_VERSION}/$(sedesc "$WIKI_VERSION")/" \
509 -e "s/{TIME}/$(sedesc "$TIME")/" -e "s/{DATE}/$(sedesc "$datew")/" \
510 -e "s/{IP}/$REMOTE_ADDR/" -e "s/{COOKIE}//" -e "s/{RSS}//" <<EOT
511 $html
512 EOT
513 )"
514 header "Content-type: text/html"
515 sed '/{CONTENT}/{s/{CONTENT}.*//;q}' <<EOT
516 $html2
517 EOT
518 cat <<EOT
519 $CONTENT
520 EOT
521 sed ':a;N;/{CONTENT}/!ba;s/.*{CONTENT}//;:b;N;$!bb' <<EOT
522 $html2
523 EOT