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

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