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

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