slitaz-dev-tools view tazwikiss/rootfs/var/www/wiki/index.sh @ rev 228

tazwikiss: log plugins error messages (again)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon May 19 16:37:45 2014 +0000 (2014-05-19)
parents fe46b75e5d1c
children 3780599349cd
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/lib/slitaz/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 plugin_call_method()
60 {
61 local status
62 local name
63 name=$1
64 shift
65 [ -d "$plugins_dir" ] || return
66 status=false
67 for i in $plugins_dir/*.sh ; do
68 [ -x $i ] || continue
69 grep -q "^$name()" $i || continue
70 . $i
71 eval $name "$@"
72 [ $? == 0 ] && status=true
73 done 2> /tmp/tazwiki$$stderr
74 [ -s /tmp/tazwiki$$stderr ] &&
75 logger -t "httpd/wiki/plugin" < /tmp/tazwiki$$stderr
76 rm -f /tmp/tazwiki$$stderr 2> /dev/null
77 $status
78 }
80 curdate()
81 {
82 date '+%Y-%m-%d %H:%M'
83 }
85 filedate()
86 {
87 stat -c %y $1 | sed -e 's|-|/|g' -e 's/\(:..\):.*/\1/'
88 }
90 AUTH=$(GET auth)
91 [ -n "$AUTH" ] || AUTH=$(POST auth)
92 PAGE_TITLE="$(GET page)"
93 [ -n "$PAGE_TITLE" ] || PAGE_TITLE="$(POST page)"
94 if [ -z "$PAGE_TITLE" ]; then
95 PAGE_TITLE="$START_PAGE"
96 case "$(GET action)" in
97 recent) PAGE_TITLE="$RECENT_CHANGES" ;;
98 search) PAGE_TITLE="$LIST"
99 [ -n "$(GET query)" ] && PAGE_TITLE="$SEARCH_RESULTS $(GET query)"
100 esac
101 fi
102 case "$PAGE_TITLE" in
103 */*|*\&*) PAGE_TITLE="$START_PAGE" ;;
104 esac
105 gtime=$(GET time)
106 case "$gtime" in
107 */*|*\&*) gtime="" ;;
108 esac
109 action=$(GET action)
110 datew="$(curdate)"
111 content="$(POST content)"
113 # Ecrire les modifications, s'il y a lieu
114 PAGE_txt="$PAGES_DIR$PAGE_TITLE.txt"
115 plugin_call_method "init" $PAGE_txt
116 if [ -n "$content" ]; then # content => page
117 if authentified; then
118 CR="$(echo -en '\r')"
119 sed 's/</\&lt;/g;s/'$CR' /'$CR'\n/g' > $PAGE_txt <<EOT
120 $POST_content_1
121 EOT
122 if [ -n "$BACKUP_DIR" ]; then
123 complete_dir_s="$BACKUP_DIR$PAGE_TITLE/"
124 if [ ! -d "$complete_dir_s" ]; then
125 mkdir -p $complete_dir_s
126 chmod 777 $complete_dir_s
127 fi
128 cat >> "$complete_dir_s$(curdate).bak" <<EOT
130 // $datew / $REMOTE_ADDR
131 $(cat $PAGE_txt)
132 EOT
133 fi
134 plugin_call_method "writedPage" $PAGE_txt
135 PAGE_TITLE="$PAGE_TITLE&auth=$AUTH"
136 else
137 PAGE_TITLE="$PAGE_TITLE&action=edit&error=1"
138 fi
139 redirect "$urlbase?page=$PAGE_TITLE"
140 fi
142 if [ -r "$PAGE_txt" -o -n "$action" ]; then
143 CONTENT=""
144 if [ -e "$PAGE_txt" ]; then
145 TIME=$(filedate $PAGE_txt)
146 CONTENT="$(cat $PAGE_txt)"
147 fi
148 # Restaurer une page
149 [ -n "$(GET page)" -a -n "$gtime" -a "$(GET restore)" == 1 ] &&
150 [ -r "$BACKUP_DIR$PAGE_TITLE/$gtime" ] &&
151 CONTENT="$(cat $BACKUP_DIR$PAGE_TITLE/$gtime)"
152 CONTENT="$(sed -e 's/\$/\&#036;/g' -e 's/\\/\&#092;/g' <<EOT
153 $CONTENT
154 EOT
155 )"
156 else
157 CONTENT="$(sed -e "s#%page%#$PAGE_TITLE#" <<EOT
158 $DEFAULT_CONTENT
159 EOT
160 )"
161 fi
163 htmldiff()
164 {
165 local files
166 local old
167 local new
168 old="$BACKUP_DIR$(GET page)/$1"
169 new="$BACKUP_DIR$(GET page)/$2"
170 [ -s "$old" ] || old=/dev/null
171 [ -n "$2" -a "$2" != "none" ] || new=$PAGES_DIR$(GET page).txt
172 files="$old $new"
173 [ "$old" -nt "$new" -a "$old" != "/dev/null" ] && files="$new $old"
174 diff -aU 99999 $files | sed -e '1,3d' -e '/^\\/d' -e 's|$|<br/>|' \
175 -e 's|^-\(.*\)$|<font color=red>\1</font>|' \
176 -e 's|^+\(.*\)$|<font color=green>\1</font>|'
177 }
179 # Actions speciales du Wiki
180 case "$action" in
181 edit)
182 editable=false
183 HISTORY="<a href=\"$urlbase?page=$(urlencode $PAGE_TITLE)\&amp;action=history\" accesskey=\"6\" rel=\"nofollow\">$HISTORY_BUTTON</a><br />"
184 CONTENT="$(sed 's/%/\&#37;/g' <<EOT
185 $CONTENT
186 EOT
187 )"
188 CONTENT="<form method=\"post\" action=\"$urlbase\">
189 <textarea name=\"content\" cols=\"83\" rows=\"30\" style=\"width: 100%;\">
190 $CONTENT
191 </textarea>
192 <input type=\"hidden\" name=\"page\" value=\"$PAGE_TITLE\" /><br />
193 <p align=\"right\">"
194 if authentified; then
195 CONTENT="$CONTENT<input type=\"hidden\" value=\"$(POST password)\""
196 else
197 CONTENT="$CONTENT$MDP : <input type=\"password\""
198 fi
199 CONTENT="$CONTENT name=\"sc\" /> <input type=\"submit\" value=\"$DONE_BUTTON\" accesskey=\"s\" /></p></form>"
200 ;;
201 history)
202 complete_dir="$BACKUP_DIR$PAGE_TITLE/"
203 if [ -n "$gtime" ]; then
204 HISTORY="<a href=\"$urlbase?page=$PAGE_TITLE\&amp;action=history\" rel=\"nofollow\">$HISTORY_BUTTON</a>"
205 if [ -r "$complete_dir$gtime" ]; then
206 HISTORY="$HISTORY <a href=\"$urlbase?page=$PAGE_TITLE\&amp;action=edit\&amp;time=$gtime&amp;restore=1\" rel=\"nofollow\">$RESTORE</a>"
207 CONTENT="$(cat $complete_dir$gtime | sed -e s/$(echo -ne '\r')//g -e 's|$|<br/>|g')"
208 else
209 HISTORY="$HISTORY -"
210 fi
211 else
212 HISTORY="$HISTORY_BUTTON"
213 CONTENT="$NO_HISTORY"
214 if [ -d $complete_dir ]; then
215 CONTENT="<form method=\"GET\" action=\"$urlbase\">\n<input type=hidden name=action value=diff><input type=hidden name=page value=\"$PAGE_TITLE\">"
216 for file in $(ls $complete_dir | sort -r); do
217 CONTENT="$CONTENT
218 <input type=radio name=f1 value=$file><input type=radio name=f2 value=$file />
219 <a href=\"$urlbase?page=$PAGE_TITLE&amp;action=history&amp;time=$file\">$file</a><br />
220 "
221 done
222 CONTENT="$CONTENT<input type=submit value=diff></form>"
223 fi
224 fi ;;
225 diff)
226 if [ -n "$(GET f1)" ]; then
227 HISTORY="<a href=\"$urlbase?page=$(urlencode "$PAGE_TITLE")\&amp;action=history\">$HISTORY_BUTTON</a>"
228 CONTENT="$(htmldiff "$(GET f1)" "$(GET f2)" )"
229 else
230 # diff auto entre les 2 dernières versions
231 ls "$BACKUP_DIR$PAGE_TITLE/" | ( sort -r ; echo none ; echo ) | head -n 2 | while read f1 f2; do
232 redirect "$urlbase?page=$(urlencode "$PAGE_TITLE")&action=$action&f1=$f1&f2=$f2"
233 done
234 fi ;;
235 search)
236 PAGE_TITLE_link=false
237 editable=false
238 query="$(GET query)"
239 n=0
240 for file in $(ls $PAGES_DIR/*.txt 2> /dev/null | sort) ; do
241 [ -e $file ] || continue
242 echo $file | grep -qs "$query" $file /dev/stdin || continue
243 file=$(basename $file ".txt")
244 CONTENT="$CONTENT<a href=\"$urlbase?page=$file\">$file</a><br />
245 "
246 n=$(($n + 1))
247 done
248 PAGE_TITLE="$PAGE_TITLE ($n)" ;;
249 recent)
250 PAGE_TITLE_link=false
251 editable=false
252 n=0
253 for file in $(ls -l $PAGES_DIR/*.txt 2> /dev/null | awk '{ print $9 }' | tail -n 10) ; do
254 filename=$(basename $file ".txt")
255 timestamp=$(filedate $file)
256 CONTENT="$CONTENT<a href=\"$urlbase?page=$filename\">$filename</a> ($timestamp - <a href=\"$urlbase?page=$filename&amp;action=diff\">diff</a>)<br />
257 "
258 done ;;
259 '') ;;
260 *)
261 plugin_call_method "action" $action || action="" ;;
262 esac
263 if [ -z "$action" ]; then
264 if echo "$CONTENT" | grep -q '%html%\s'; then
265 CONTENT="$(sed 's/%html%\s//' <<EOT
266 $CONTENT
267 EOT
268 )"
269 else
270 tmpdir=/tmp/tazwiki$$
271 mkdir $tmpdir
272 unesc="$(echo "$CONTENT" | sed 's/\^\(.\)/\n^\1\n/g' | grep '\^' |\
273 sort | uniq | grep -v "['[!]" | hexdump -e '"" 3/1 "%d " "\n"' |\
274 awk '{ printf "-e '\''s/\\^%c/\\&#%d;/g'\'' ",$2,$2}') \
275 -e 's/\\^'\\''/\\&#39;/g' -e 's/\^\!/\&#33;/g' \
276 -e 's/\^\[/\&#91;/g'"
277 CONTENT="$(eval sed $unesc <<EOT | \
278 sed -e 's/&/\&amp;/g' -e s/$(echo -ne '\r')//g \
279 -e 's/&amp;lt;/\&lt;/g' -e 's/&amp;#\([0-9]\)/\&#\1/g' | \
280 awk -v tmpdir=$tmpdir 'BEGIN { n=1; state=0 } {
281 s=$0
282 while (1) {
283 if (state == 0) {
284 if (match(s,/\{\{/)) {
285 printf "%s<pre><code>{{CODE%s}}</code></pre>",substr(s,1,RSTART-1),n
286 s=substr(s,RSTART+RLENGTH)
287 state=1
288 }
289 else {
290 print s
291 break
292 }
293 }
294 if (state == 1) {
295 if (match(s,/\}\}/)) {
296 printf "%s",substr(s,1,RSTART-1) >> tmpdir "/CODE" n
297 s=substr(s,RSTART+RLENGTH)
298 n++
299 state=0
300 }
301 else {
302 print s >> tmpdir "/CODE" n
303 break
304 }
305 }
306 }
307 }'
308 $CONTENT
309 EOT
310 )"
311 plugin_call_method formatBegin
312 CONTENT="$(sed -e 's/&lt;-->/\&harr;/g' -e 's/&lt;==>/\&hArr;/g'\
313 -e 's/-->/\&rarr;/g' -e 's/&lt;--/\&larr;/g' \
314 -e 's/==>/\&rArr;/g' -e 's/&lt;==/\&lArr;/g' \
315 -e 's/([eE])/\&euro;/g' -e 's/([pP])/\&pound;/g' \
316 -e 's/([yY])/\&yen;/g' -e 's/([tT][mM])/\&trade;/g' \
317 -e 's/([cC])/\&copy;/g' -e 's/([rR])/\&reg;/g' \
318 -e 's/([dD])/\&deg;/g' -e 's/(1\/2)/\&frac12;/g' \
319 -e 's/(1\/4)/\&frac14;/g' -e 's/(3\/4)/\&frac34;/g' \
320 -e 's/(&lt;=)/\&le;/g' -e 's/(>=)/\&ge;/g' \
321 -e 's/(!=)/\&ne;/g' -e 's/(+-)/\&plusmn;/g' <<EOT
322 $CONTENT
323 EOT
324 )"
325 rg_url="[0-9a-zA-Z\.\#/~\_%=\?\&,\+\:@;!\(\)\*\$'\-]*" # TODO: verif & / &amp;
326 rg_link_local="$rg_url"
327 rg_link_http="https\?://$rg_url"
328 rg_img_local="$rg_url\.jpe\?g\|$rg_url\.gif\|$rg_url\.png"
329 rg_img_http="$rg_link_http\.jpe\?g\|$rg_link_http\.gif\|$rg_link_http\.png"
331 # image, image link, link, wikipedia, email ...
332 CONTENT="$(sed \
333 -e "s#\[\($rg_img_http\)\]#<img src=\"\1\" alt=\"\1\" style=\"float:\"/>#g" \
334 -e "s#\[\($rg_img_local\)\]#<img src=\"\1\" alt=\"\1\" style=\"float:\"/>#g" \
335 -e "s#\[\($rg_img_http\)|*\([a-z]*\)*\]#<img src=\"\1\" alt=\"\1\" style=\"float:\2;\"/>#g" \
336 -e "s#\[\($rg_img_local\)|*\([a-z]*\)*\]#<img src=\"\1\" alt=\"\1\" style=\"float:\2;\"/>#g" \
337 -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" \
338 -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" \
339 -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" \
340 -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" \
341 -e "s#\[\([^]]*\)|\($rg_link_http\)\]#<a href=\"\2\" class=\"url\">\1</a>#g" \
342 -e "s#\[\([^]]*\)|\($rg_link_local\)\]#<a href=\"\2\" class=\"url\">\1</a>#g" \
343 -e "s#\[\($rg_link_http\)\]#<a href=\"\1\" class=\"url\">\1</a>#g" \
344 -e "s#\([^>\"]\)\($rg_link_http\)#\1<a href=\"\2\" class=\"url\">\2</a>#g" \
345 -e "s#\[?\([^]]*\)\]#<a href=\"http://$LANG.wikipedia.org/wiki/\1\" class=\"url\" title=\"Wikipedia\">\1</a>#g" \
346 -e "s#\[\([^]]*\)\]#<a href=\"$urlbase?page=\1\">\1</a>#g" \
347 -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' \
348 -e 's#^\*\*\*\(.*\)#<ul><ul><ul><li>\1</li></ul></ul></ul>#g' \
349 -e 's#^\*\*\(.*\)#<ul><ul><li>\1</li></ul></ul>#g' \
350 -e 's#^\*\(.*\)#<ul><li>\1</li></ul>#g' \
351 -e 's,^\#\#\#\(.*\),<ol><ol><ol><li>\1</li></ol></ol></ol>,g' \
352 -e 's,^\#\#\(.*\),<ol><ol><li>\1</li></ol></ol>,g' \
353 -e 's,^\#\(.*\),<ol><li>\1</li></ol>,g' \
354 -e "s/$(printf '\r')//" <<EOT | sed \
355 -e ':x;/<\/ol>$/{N;s/\n//;$P;$D;bx;}' | sed \
356 -e ':x;/<\/ul>$/{N;s/\n//;$P;$D;bx;}' | sed \
357 -e ':x;s/<\/ul><ul>//g;tx' -e ':x;s/<\/ol><ol>//g;tx' \
358 -e 's|----*$|<hr />|' -e 's|$|<br />|' \
359 -e 's|</ul>|&\n|g' -e 's|</ol>|&\n|g' \
360 -e 's#</li>#&\n#g' -e 's#\(</h[123456]>\)<br />#\1#g' \
361 -e "s#'--\([^']*\)--'#<del>\1</del>#g" \
362 -e "s#'__\([^']*\)__'#<u>\1</u>#g" \
363 -e "s#'''''\([^']*\)'''''#<strong><em>\1</em></strong>#g" \
364 -e "s#'''\([^']*\)'''#<strong>\1</strong>#g" \
365 -e "s#''\([^']*\)''#<em>\1</em>#g"
366 $CONTENT
367 EOT
368 )"
369 while read link; do
370 [ -s $PAGES_DIR$link.txt ] && continue
371 CONTENT="$(sed "s|\\?page=$link\"|& class=\"pending\"|" <<EOT
372 $CONTENT
373 EOT
374 )"
375 done <<EOT
376 $(grep "$urlbase?page=" <<EOM | sed -e 's/^.*\?page=\([^"]*\).*$/\1/' -e 's/&.*//'
377 $CONTENT
378 EOM
379 )
380 EOT
381 while echo "$CONTENT" | grep -q '^ ' ; do
382 CONTENT="$(sed 's/^\( *\) \([^ ]\)/\1\&nbsp;\&nbsp;\&nbsp;\&nbsp;\2/' <<EOT
383 $CONTENT
384 EOT
385 )"
386 done
387 read hastoc <<EOT
388 $CONTENT
389 EOT
390 CONTENT="$(sed -e 's/^ /\&nbsp;\&nbsp;\&nbsp;\&nbsp;/' -e '1s/^TOC//' <<EOT
391 $CONTENT
392 EOT
393 )"
394 toc='<div id="toc">'
395 i=1
396 for pat in '^![^!]' '^!![^!]' '^!!![^!]' '^!!!![^!]' '^!!!!!' ; do
397 while read line; do
398 [ -n "$line" ] || continue
399 label="$(echo $line | sed 's/[^\dA-Za-z]/_/g')"
400 toc="$(cat <<EOT
401 $toc
402 <h$i><a href="#$label">$line</a></h$i>
403 EOT
404 )"
405 CONTENT="$(sed "s#^!!* *$line\$#<h$i><a name=\"$label\">$line</a></h$i>#" <<EOT
406 $CONTENT
407 EOT
408 )"
409 done <<EOT
410 $(grep "$pat" <<EOM | sed -e 's/^!!*//' -e 's/#/\#/g' -e 's/&/\\\&/g'
411 $CONTENT
412 EOM
413 )
414 EOT
415 i=$(( $i + 1 ))
416 done
417 toc="$(cat <<EOT
418 $toc
419 </div>
420 EOT
421 )"
422 case "$hastoc" in
423 TOC*) ;;
424 *) toc='';;
425 esac
426 CONTENT="$(awk -v tmpdir=$tmpdir '{
427 s=$0
428 while (1) {
429 if (match(s,/\{\{CODE[0-9]+\}\}/)) {
430 printf "%s" substr(s,1,RSTART-1)
431 system("cat " tmpdir "/" substr(s,RSTART+2,RLENGTH-4))
432 s=substr(s,RSTART+RLENGTH)
433 }
434 else {
435 print s
436 break
437 }
438 }
439 }' <<EOT
440 $CONTENT
441 EOT
442 )"
443 rm -rf $tmpdir
444 plugin_call_method formatEnd
445 fi
446 fi
448 # Remplacement dans le template
449 RECENT="<a href=\"$urlbase?action=recent\" accesskey=\"3\">$RECENT_CHANGES</a>"
450 [ "$action" == "recent" ] && RECENT=$RECENT_CHANGES
451 HOME="<a href=\"$urlbase?page=$START_PAGE\" accesskey=\"1\">$HOME_BUTTON</a>"
452 [ "$PAGE_TITLE" == "$START_PAGE" -a "$action" != "search" ] && HOME=$HOME_BUTTON
453 HELP="\1<a href=\"$urlbase?page=$HELP_BUTTON\" accesskey=\"2\" rel=\"nofollow\">$HELP_BUTTON</a>\2"
454 [ "$action" != "edit" ] && HELP=""
456 [ -r "$template" ] || die "'$template' is missing!"
457 html="$(sed -e "s#{\([^}]*\)RECENT_CHANGES\([^}]*\)}#\1$RECENT\2#" \
458 -e "s#{\([^}]*\)HOME\([^}]*\)}#\1$HOME\2#" \
459 -e "s#{\([^}]*\)HELP\([^}]*\)}#$HELP#" \
460 -e "s#{SEARCH}#<form method=\"get\" action=\"$urlbase?page=$(urlencode "$PAGE_TITLE" | sed 's/#/\\#/g')\"><div><input type=\"hidden\" name=\"action\" value=\"search\" /><input type=\"text\" name=\"query\" value=\"$(htmlentities $(GET query) )\" tabindex=\"1\" /> <input type=\"submit\" value=\"$SEARCH_BUTTON\" accesskey=\"q\" /></div></form>#" \
461 < $template )"
462 [ "$action" != "" -a "$action" != "edit" -o ! -e "$PAGE_txt" ] && TIME="-"
463 plugin_call_method template
464 [ -n "$(GET error)" ] || ERROR=""
465 [ -n "$HISTORY" ] && HISTORY="\1$HISTORY\2"
466 PAGE_TITLE_str="$(htmlentities "$PAGE_TITLE")"
467 $PAGE_TITLE_link &&
468 PAGE_TITLE_str="<a href=\"$urlbase?page=$(urlencode "$PAGE_TITLE")\">$PAGE_TITLE_str</a>"
469 EDIT="$EDIT_BUTTON"
470 if $editable ; then
471 EDIT="$PROTECTED_BUTTON"
472 [ -w "$PAGE_txt" -o ! -e "$PAGE_txt" ] &&
473 EDIT="<a href=\"$urlbase?page=$(urlencode "$PAGE_TITLE")\&amp;action=edit\" accesskey=\"5\" rel=\"nofollow\">$EDIT_BUTTON</a>"
474 fi
475 [ -n "$toc" ] && toc="\1$toc\2"
476 AUTH_GET=""
477 AUTH_POST=""
478 if authentified; then
479 AUTH_GET="auth=$AUTH\&"
480 AUTH_POST="\n<input type=\"hidden\" name=\"auth\" value=\"$AUTH\" />"
481 fi
483 header "Content-type: text/html"
484 sed -e "s#{ERROR}#$ERROR#" -e "s#{WIKI_TITLE}#$WIKI_TITLE#" \
485 -e "s#{\([^}]*\)HISTORY\([^}]*\)}#$HISTORY#" \
486 -e "s#{PAGE_TITLE}#$PAGE_TITLE_str#" \
487 -e "s#{\([^}]*\)EDIT\([^}]*\)}#\1$EDIT\2#" \
488 -e "s|{\([^}]*\)TOC\([^}]*\)}|$(awk '{ printf "%s\\n" $0 }' <<EOT | \
489 sed -e 's/&/\\\&/g' -e 's/|/\\|/g'
490 $toc
491 EOT
492 )|" \
493 -e "s#{PAGE_TITLE_BRUT}#$(htmlentities "$PAGE_TITLE")#" \
494 -e "s#{LAST_CHANGE}#$LAST_CHANGES :#" \
495 -e "s#{CONTENT}#$(awk '{ printf "%s\\n" $0 }' <<EOT | \
496 sed -e 's/&/\\\&/g' -e 's/#/\\#/g'
497 $CONTENT
498 EOT
499 )#" \
500 -e "s#{LANG}#$LANG#" -e "s#href=\"?#href=\"$urlbase?#g" \
501 -e "s#$urlbase?#&$AUTH_GET#g" -e "s#action=\"$urlbase\">#&$AUTH_POST#g" \
502 -e "s#{WIKI_VERSION}#$WIKI_VERSION#" \
503 -e "s#{TIME}#$TIME#" -e "s#{DATE}#$datew#" \
504 -e "s#{IP}#$REMOTE_ADDR#" -e "s#{COOKIE}##" <<EOT
505 $html
506 EOT