wok-next diff tazwikiss/stuff/var/www/wiki/index.sh @ rev 6058
commoncpp2: Upgrade to 1.8.0
author | Matthew Sheets <rcx@zoominternet.net> |
---|---|
date | Thu Aug 19 22:18:58 2010 +0000 (2010-08-19) |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/tazwikiss/stuff/var/www/wiki/index.sh Thu Aug 19 22:18:58 2010 +0000 1.3 @@ -0,0 +1,492 @@ 1.4 +#!/bin/sh 1.5 +# 1.6 +# TazWikiss - A tiny Wiki for busybox/httpd 1.7 +# Licence GNU/GPLv2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 1.8 +# Copyright (C) Pascal Bellard 1.9 +# Based on WiKiss - http://wikiss.tuxfamily.org/ 1.10 + 1.11 +. /usr/bin/httpd_helper.sh 1.12 + 1.13 +cd $(dirname $0) 1.14 +CONFIG=config-${HTTP_ACCEPT_LANGUAGE%%,*}.sh 1.15 +[ -r "$CONFIG" ] || CONFIG=config.sh 1.16 +. ./$CONFIG 1.17 + 1.18 +WIKI_VERSION="TazWiKiss 0.3" 1.19 + 1.20 +# Initialisations 1.21 +toc='' # Table Of Content 1.22 +CONTENT='' # contenu de la page 1.23 +HISTORY='' # lien vers l'historique 1.24 +plugins_dir="plugins/" # repertoire ou stocker les plugins 1.25 +template="template.html" # Fichier template 1.26 +PAGE_TITLE_link=true # y-a-t-il un lien sur le titre de la page ? 1.27 +editable=true # la page est editable 1.28 +urlbase="$SCRIPT_NAME" 1.29 +#urlbase="./" 1.30 + 1.31 +die() 1.32 +{ 1.33 + echo $@ 1.34 + exit 1.35 +} 1.36 + 1.37 +redirect() 1.38 +{ 1.39 + awk '{ printf "%s\r\n",$0 }' <<EOT 1.40 +HTTP/1.0 302 Found 1.41 +location: $1 1.42 + 1.43 +EOT 1.44 + exit 1.45 +} 1.46 + 1.47 +cache_auth() 1.48 +{ 1.49 + local tmp 1.50 + tmp="$(echo $1$(date +%d) | md5sum | cut -c1-8)" 1.51 + [ "$(POST sc)" == "$1" ] && AUTH=$tmp || [ "$AUTH" == "$tmp" ] 1.52 +} 1.53 + 1.54 +authentified() 1.55 +{ 1.56 + [ -n "$PASSWORDS" ] && for i in $PASSWORDS ; do 1.57 + cache_auth "$i" && return 1.58 + done 1.59 + cache_auth "$PASSWORD" 1.60 +} 1.61 + 1.62 +plugin_call_method() 1.63 +{ 1.64 + local status 1.65 + local name 1.66 + name=$1 1.67 + shift 1.68 + [ -d "$plugins_dir" ] || return 1.69 + status=false 1.70 + for i in $plugins_dir/*.sh ; do 1.71 + [ -x $i ] || continue 1.72 + grep -q "^$name()" $i || continue 1.73 + . $i 1.74 + eval $name "$@" 1.75 + [ $? == 0 ] && status=true 1.76 + done 1.77 + $status 1.78 +} 1.79 + 1.80 +curdate() 1.81 +{ 1.82 + date '+%Y-%m-%d %H:%M' 1.83 +} 1.84 + 1.85 +filedate() 1.86 +{ 1.87 + stat -c %y $1 | sed -e 's|-|/|g' -e 's/\(:..\):.*/\1/' 1.88 +} 1.89 + 1.90 +AUTH=$(GET auth) 1.91 +[ -n "$AUTH" ] || AUTH=$(POST auth) 1.92 +PAGE_TITLE="$(GET page)" 1.93 +[ -n "$PAGE_TITLE" ] || PAGE_TITLE="$(POST page)" 1.94 +if [ -z "$PAGE_TITLE" ]; then 1.95 + PAGE_TITLE="$START_PAGE" 1.96 + case "$(GET action)" in 1.97 + recent) PAGE_TITLE="$RECENT_CHANGES" ;; 1.98 + search) PAGE_TITLE="$LIST" 1.99 + [ -n "$(GET query)" ] && PAGE_TITLE="$SEARCH_RESULTS $(GET query)" 1.100 + esac 1.101 +fi 1.102 +case "$PAGE_TITLE" in 1.103 +*/*|*\&*) PAGE_TITLE="$START_PAGE" ;; 1.104 +esac 1.105 +gtime=$(GET time) 1.106 +case "$gtime" in 1.107 +*/*|*\&*) gtime="" ;; 1.108 +esac 1.109 +action=$(GET action) 1.110 +datew="$(curdate)" 1.111 +content="$(POST content)" 1.112 + 1.113 +# Ecrire les modifications, s'il y a lieu 1.114 +PAGE_txt="$PAGES_DIR$PAGE_TITLE.txt" 1.115 +if [ -n "$content" ]; then # content => page 1.116 + if authentified; then 1.117 + sed 's/</\</g' > $PAGE_txt <<EOT 1.118 +$POST_content 1.119 +EOT 1.120 + if [ -n "$BACKUP_DIR" ]; then 1.121 + complete_dir_s="$BACKUP_DIR$PAGE_TITLE/" 1.122 + if [ ! -d "$complete_dir_s" ]; then 1.123 + mkdir -p $complete_dir_s 1.124 + chmod 777 $complete_dir_s 1.125 + fi 1.126 + cat >> "$complete_dir_s$(curdate).bak" <<EOT 1.127 + 1.128 +// $datew / $REMOTE_ADDR 1.129 +$(cat $PAGE_txt) 1.130 +EOT 1.131 + fi 1.132 + plugin_call_method "writedPage" $PAGE_txt 1.133 + PAGE_TITLE="$PAGE_TITLE&auth=$AUTH" 1.134 + else 1.135 + PAGE_TITLE="$PAGE_TITLE&action=edit&error=1" 1.136 + fi 1.137 + redirect "$urlbase?page=$PAGE_TITLE" 1.138 +fi 1.139 + 1.140 +if [ -r "$PAGE_txt" -o -n "$action" ]; then 1.141 + CONTENT="" 1.142 + if [ -e "$PAGE_txt" ]; then 1.143 + TIME=$(filedate $PAGE_txt) 1.144 + CONTENT="$(cat $PAGE_txt)" 1.145 + fi 1.146 + # Restaurer une page 1.147 + [ -n "$(GET page)" -a -n "$gtime" -a "$(GET restore)" == 1 ] && 1.148 + [ -r "$BACKUP_DIR$PAGE_TITLE/$gtime" ] && 1.149 + CONTENT="$(cat $BACKUP_DIR$PAGE_TITLE/$gtime)" 1.150 + CONTENT="$(sed -e 's/\$/\$/g' -e 's/\\/\\/g' <<EOT 1.151 +$CONTENT 1.152 +EOT 1.153 +)" 1.154 +else 1.155 + CONTENT="$(sed -e "s#%page%#$PAGE_TITLE#" <<EOT 1.156 +$DEFAULT_CONTENT 1.157 +EOT 1.158 +)" 1.159 +fi 1.160 + 1.161 +htmldiff() 1.162 +{ 1.163 + local files 1.164 + local old 1.165 + local new 1.166 + old="$BACKUP_DIR$(GET page)/$1" 1.167 + new="$BACKUP_DIR$(GET page)/$2" 1.168 + [ -s "$old" ] || old=/dev/null 1.169 + [ -n "$2" -a "$2" != "none" ] || new=$PAGES_DIR$(GET page).txt 1.170 + files="$old $new" 1.171 + [ "$old" -nt "$new" -a "$old" != "/dev/null" ] && files="$new $old" 1.172 + diff -aU 99999 $files | sed -e '1,3d' -e '/^\\/d' -e 's|$|<br/>|' \ 1.173 + -e 's|^-\(.*\)$|<font color=red>\1</font>|' \ 1.174 + -e 's|^+\(.*\)$|<font color=green>\1</font>|' 1.175 +} 1.176 + 1.177 +# Actions speciales du Wiki 1.178 +case "$action" in 1.179 +edit) 1.180 + editable=false 1.181 + HISTORY="<a href=\"$urlbase?page=$(urlencode $PAGE_TITLE)\&action=history\" accesskey=\"6\" rel=\"nofollow\">$HISTORY_BUTTON</a><br />" 1.182 + CONTENT="<form method=\"post\" action=\"$urlbase\"> 1.183 +<textarea name=\"content\" cols=\"83\" rows=\"30\" style=\"width: 100%;\"> 1.184 +$CONTENT 1.185 +</textarea> 1.186 +<input type=\"hidden\" name=\"page\" value=\"$PAGE_TITLE\" /><br /> 1.187 +<p align=\"right\">" 1.188 + if authentified; then 1.189 + CONTENT="$CONTENT<input type=\"hidden\" value=\"$(POST password)\"" 1.190 + else 1.191 + CONTENT="$CONTENT$MDP : <input type=\"password\"" 1.192 + fi 1.193 + CONTENT="$CONTENT name=\"sc\" /> <input type=\"submit\" value=\"$DONE_BUTTON\" accesskey=\"s\" /></p></form>" 1.194 + ;; 1.195 +history) 1.196 + complete_dir="$BACKUP_DIR$PAGE_TITLE/" 1.197 + if [ -n "$gtime" ]; then 1.198 + HISTORY="<a href=\"$urlbase?page=$PAGE_TITLE\&action=history\" rel=\"nofollow\">$HISTORY_BUTTON</a>" 1.199 + if [ -r "$complete_dir$gtime" ]; then 1.200 + HISTORY="$HISTORY <a href=\"$urlbase?page=$PAGE_TITLE\&action=edit\&time=$gtime&restore=1\" rel=\"nofollow\">$RESTORE</a>" 1.201 + CONTENT="$(cat $complete_dir$gtime | sed -e s/$(echo -ne '\r')//g -e 's|$|<br/>|g')" 1.202 + else 1.203 + HISTORY="$HISTORY -" 1.204 + fi 1.205 + else 1.206 + HISTORY="$HISTORY_BUTTON" 1.207 + CONTENT="$NO_HISTORY" 1.208 + if [ -d $complete_dir ]; then 1.209 + CONTENT="<form method=\"GET\" action=\"$urlbase\">\n<input type=hidden name=action value=diff><input type=hidden name=page value=\"$PAGE_TITLE\">" 1.210 + for file in $(ls $complete_dir | sort -r); do 1.211 + CONTENT="$CONTENT 1.212 +<input type=radio name=f1 value=$file><input type=radio name=f2 value=$file /> 1.213 +<a href=\"$urlbase?page=$PAGE_TITLE&action=history&time=$file\">$file</a><br /> 1.214 +" 1.215 + done 1.216 + CONTENT="$CONTENT<input type=submit value=diff></form>" 1.217 + fi 1.218 + fi ;; 1.219 +diff) 1.220 + if [ -n "$(GET f1)" ]; then 1.221 + HISTORY="<a href=\"$urlbase?page=$(urlencode "$PAGE_TITLE")\&action=history\">$HISTORY_BUTTON</a>" 1.222 + CONTENT="$(htmldiff "$(GET f1)" "$(GET f2)" )" 1.223 + else 1.224 + # diff auto entre les 2 dernières versions 1.225 + ls "$BACKUP_DIR$PAGE_TITLE/" | ( sort -r ; echo none ; echo ) | head -n 2 | while read f1 f2; do 1.226 + redirect "$urlbase?page=$(urlencode "$PAGE_TITLE")&action=$action&f1=$f1&f2=$f2" 1.227 + done 1.228 + fi ;; 1.229 +search) 1.230 + PAGE_TITLE_link=false 1.231 + editable=false 1.232 + query="$(GET query)" 1.233 + n=0 1.234 + for file in $(ls $PAGES_DIR/*.txt 2> /dev/null | sort) ; do 1.235 + [ -e $file ] || continue 1.236 + echo $file | grep -qs "$query" $file /dev/stdin || continue 1.237 + file=$(basename $file ".txt") 1.238 + CONTENT="$CONTENT<a href=\"$urlbase?page=$file\">$file</a><br /> 1.239 +" 1.240 + n=$(($n + 1)) 1.241 + done 1.242 + PAGE_TITLE="$PAGE_TITLE ($n)" ;; 1.243 +recent) 1.244 + PAGE_TITLE_link=false 1.245 + editable=false 1.246 + n=0 1.247 + for file in $(ls -l $PAGES_DIR/*.txt 2> /dev/null | awk '{ print $9 }' | tail -n 10) ; do 1.248 + filename=$(basename $file ".txt") 1.249 + timestamp=$(filedate $file) 1.250 + CONTENT="$CONTENT<a href=\"$urlbase?page=$filename\">$filename</a> ($timestamp - <a href=\"$urlbase?page=$filename&action=diff\">diff</a>)<br /> 1.251 +" 1.252 + done ;; 1.253 +'') ;; 1.254 +*) 1.255 + plugin_call_method "action" $action || action="" ;; 1.256 +esac 1.257 +if [ -z "$action" ]; then 1.258 + if echo "$CONTENT" | grep -q '%html%\s'; then 1.259 + CONTENT="$(sed 's/%html%\s//' <<EOT 1.260 +$CONTENT 1.261 +EOT 1.262 +)" 1.263 + else 1.264 + tmpdir=/tmp/tazwiki$$ 1.265 + mkdir $tmpdir 1.266 + unesc="$(echo "$CONTENT" | sed 's/\^\(.\)/\n^\1\n/g' | grep '\^' |\ 1.267 + sort | uniq | grep -v "['[!]" | hexdump -e '"" 3/1 "%d " "\n"' |\ 1.268 + awk '{ printf "-e '\''s/\\^%c/\\&#%d;/g'\'' ",$2,$2}') \ 1.269 + -e 's/\\^'\\''/\\'/g' -e 's/\^\!/\!/g' \ 1.270 + -e 's/\^\[/\[/g'" 1.271 + CONTENT="$(eval sed $unesc <<EOT | \ 1.272 + sed -e 's/&/\&/g' -e s/$(echo -ne '\r')//g \ 1.273 + -e 's/&lt;/\</g' -e 's/&#\([0-9]\)/\&#\1/g' | \ 1.274 + awk -v tmpdir=$tmpdir 'BEGIN { n=1; state=0 } { 1.275 +s=$0 1.276 +while (1) { 1.277 + if (state == 0) { 1.278 + if (match(s,/\{\{/)) { 1.279 + printf "%s<pre><code>{{CODE%s}}</code></pre>",substr(s,1,RSTART-1),n 1.280 + s=substr(s,RSTART+RLENGTH) 1.281 + state=1 1.282 + } 1.283 + else { 1.284 + print s 1.285 + break 1.286 + } 1.287 + } 1.288 + if (state == 1) { 1.289 + if (match(s,/\}\}/)) { 1.290 + printf "%s",substr(s,1,RSTART-1) >> tmpdir "/CODE" n 1.291 + s=substr(s,RSTART+RLENGTH) 1.292 + n++ 1.293 + state=0 1.294 + } 1.295 + else { 1.296 + print s >> tmpdir "/CODE" n 1.297 + break 1.298 + } 1.299 + } 1.300 +} 1.301 +}' 1.302 +$CONTENT 1.303 +EOT 1.304 +)" 1.305 + plugin_call_method formatBegin 1.306 + CONTENT="$(sed -e 's/<-->/\↔/g' -e 's/<==>/\⇔/g'\ 1.307 + -e 's/-->/\→/g' -e 's/<--/\←/g' \ 1.308 + -e 's/==>/\⇒/g' -e 's/<==/\⇐/g' \ 1.309 + -e 's/([eE])/\€/g' -e 's/([pP])/\£/g' \ 1.310 + -e 's/([yY])/\¥/g' -e 's/([tT][mM])/\™/g' \ 1.311 + -e 's/([cC])/\©/g' -e 's/([rR])/\®/g' \ 1.312 + -e 's/(<=)/\≤/g' -e 's/(>=)/\≥/g' \ 1.313 + -e 's/(!=)/\≠/g' -e 's/(+-)/\±/g' <<EOT 1.314 +$CONTENT 1.315 +EOT 1.316 +)" 1.317 + rg_url="[0-9a-zA-Z\.\#/~\-\_%=\?\&,\+\:@;!\(\)\*\$']*" # TODO: verif & / & 1.318 + rg_link_local="$rg_url" 1.319 + rg_link_http="https\?://$rg_url" 1.320 + rg_img_local="$rg_url\.jpe\?g\|$rg_url\.gif\|$rg_url\.png" 1.321 + rg_img_http="$rg_link_http\.jpe\?g\|$rg_link_http\.gif\|$rg_link_http\.png" 1.322 + 1.323 + # image, image link, link, wikipedia, email ... 1.324 + CONTENT="$(sed \ 1.325 + -e "s#\[\($rg_img_http\)|*\([a-z]*\)*\]#<img src=\"\1\" alt=\"\1\" style=\"float:\2;\"/>#g" \ 1.326 + -e "s#\[\($rg_img_local\)|*\([a-z]*\)*\]#<img src=\"\1\" alt=\"\1\" style=\"float:\2;\"/>#g" \ 1.327 + -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" \ 1.328 + -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" \ 1.329 + -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" \ 1.330 + -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" \ 1.331 + -e "s#\[\([^]]*\)|\($rg_link_http\)\]#<a href=\"\2\" class=\"url\">\1</a>#g" \ 1.332 + -e "s#\[\([^]]*\)|\($rg_link_local\)\]#<a href=\"\2\" class=\"url\">\1</a>#g" \ 1.333 + -e "s#\[\($rg_link_http\)\]#<a href=\"\1\" class=\"url\">\1</a>#g" \ 1.334 + -e "s#\([^>\"]\)\($rg_link_http\)#\1<a href=\"\2\" class=\"url\">\2</a>#g" \ 1.335 + -e "s#\[?\([^]]*\)\]#<a href=\"http://$LANG.wikipedia.org/wiki/\1\" class=\"url\" title=\"Wikipedia\">\1</a>#g" \ 1.336 + -e "s#\[\([^]]*\)\]#<a href=\"$urlbase?page=\1\">\1</a>#g" \ 1.337 + -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' \ 1.338 + -e 's#^\*\*\*\(.*\)#<ul><ul><ul><li>\1</li></ul></ul></ul>#g' \ 1.339 + -e 's#^\*\*\(.*\)#<ul><ul><li>\1</li></ul></ul>#g' \ 1.340 + -e 's#^\*\(.*\)#<ul><li>\1</li></ul>#g' \ 1.341 + -e 's,^\#\#\#\(.*\),<ol><ol><ol><li>\1</li></ol></ol></ol>,g' \ 1.342 + -e 's,^\#\#\(.*\),<ol><ol><li>\1</li></ol></ol>,g' \ 1.343 + -e 's,^\#\(.*\),<ol><li>\1</li></ol>,g' \ 1.344 + -e "s/$(printf '\r')//" <<EOT | sed \ 1.345 + -e ':x;/<\/ol>$/{N;s/\n//;$P;$D;bx;}' | sed \ 1.346 + -e ':x;/<\/ul>$/{N;s/\n//;$P;$D;bx;}' | sed \ 1.347 + -e ':x;s/<\/ul><ul>//g;tx' -e ':x;s/<\/ol><ol>//g;tx' \ 1.348 + -e 's|----*$|<hr />|' -e 's|$|<br />|' \ 1.349 + -e 's#</li>#&\n#g' -e 's#\(</h[123456]>\)<br />#\1#g' \ 1.350 + -e "s#'--\([^']*\)--'#<del>\1</del>#g" \ 1.351 + -e "s#'__\([^']*\)__'#<u>\1</u>#g" \ 1.352 + -e "s#'''''\([^']*\)'''''#<strong><em>\1</em></strong>#g" \ 1.353 + -e "s#'''\([^']*\)'''#<strong>\1</strong>#g" \ 1.354 + -e "s#''\([^']*\)''#<em>\1</em>#g" 1.355 +$CONTENT 1.356 +EOT 1.357 +)" 1.358 + while read link; do 1.359 + [ -s $PAGES_DIR$link.txt ] && continue 1.360 + CONTENT="$(sed "s/\\?page=$link\"/& class=\"pending\"/" <<EOT 1.361 +$CONTENT 1.362 +EOT 1.363 +)" 1.364 + done <<EOT 1.365 +$(grep "$urlbase?page=" <<EOM | sed -e 's/^.*\?page=\([^"]*\).*$/\1/' -e 's/&.*//' 1.366 +$CONTENT 1.367 +EOM 1.368 +) 1.369 +EOT 1.370 + while echo "$CONTENT" | grep -q '^ ' ; do 1.371 + CONTENT="$(sed 's/^\( *\) \([^ ]\)/\1\ \ \ \ \2/' <<EOT 1.372 +$CONTENT 1.373 +EOT 1.374 +)" 1.375 + done 1.376 + read hastoc <<EOT 1.377 +$CONTENT 1.378 +EOT 1.379 + CONTENT="$(sed -e 's/^ /\ \ \ \ /' -e '1s/^TOC//' <<EOT 1.380 +$CONTENT 1.381 +EOT 1.382 +)" 1.383 + toc='<div id="toc">' 1.384 + i=1 1.385 + for pat in '^![^!]' '^!![^!]' '^!!![^!]' '^!!!![^!]' '^!!!!!' ; do 1.386 + while read line; do 1.387 + [ -n "$line" ] || continue 1.388 + label="$(echo $line | sed 's/[^\dA-Za-z]/_/g')" 1.389 + toc="$(cat <<EOT 1.390 +$toc 1.391 + <h$i><a href="#$label">$line</a></h$i> 1.392 +EOT 1.393 +)" 1.394 + CONTENT="$(sed "s#^!!* *$line\$#<h$i><a name=\"$label\">$line</a></h$i>#" <<EOT 1.395 +$CONTENT 1.396 +EOT 1.397 +)" 1.398 + done <<EOT 1.399 +$(grep "$pat" <<EOM | sed -e 's/^!!*//' -e 's/#/\#/g' -e 's/&/\\\&/g' 1.400 +$CONTENT 1.401 +EOM 1.402 +) 1.403 +EOT 1.404 + i=$(( $i + 1 )) 1.405 + done 1.406 + toc="$(cat <<EOT 1.407 +$toc 1.408 +</div> 1.409 +EOT 1.410 +)" 1.411 + case "$hastoc" in 1.412 + TOC*) ;; 1.413 + *) toc='';; 1.414 + esac 1.415 + CONTENT="$(awk -v tmpdir=$tmpdir '{ 1.416 +s=$0 1.417 +while (1) { 1.418 + if (match(s,/\{\{CODE[0-9]+\}\}/)) { 1.419 + printf "%s" substr(s,1,RSTART-1) 1.420 + system("cat " tmpdir "/" substr(s,RSTART+2,RLENGTH-4)) 1.421 + s=substr(s,RSTART+RLENGTH) 1.422 + } 1.423 + else { 1.424 + print s 1.425 + break 1.426 + } 1.427 +} 1.428 +}' <<EOT 1.429 +$CONTENT 1.430 +EOT 1.431 +)" 1.432 + rm -rf $tmpdir 1.433 + plugin_call_method formatEnd 1.434 + fi 1.435 +fi 1.436 + 1.437 +# Remplacement dans le template 1.438 +RECENT="<a href=\"$urlbase?action=recent\" accesskey=\"3\">$RECENT_CHANGES</a>" 1.439 +[ "$action" == "recent" ] && RECENT=$RECENT_CHANGES 1.440 +HOME="<a href=\"$urlbase?page=$START_PAGE\" accesskey=\"1\">$HOME_BUTTON</a>" 1.441 +[ "$PAGE_TITLE" == "$START_PAGE" -a "$action" != "search" ] && HOME=$HOME_BUTTON 1.442 +HELP="\1<a href=\"$urlbase?page=$HELP_BUTTON\" accesskey=\"2\" rel=\"nofollow\">$HELP_BUTTON</a>\2" 1.443 +[ "$action" != "edit" ] && HELP="" 1.444 + 1.445 +[ -r "$template" ] || die "'$template' is missing!" 1.446 +html="$(sed -e "s#{\([^}]*\)RECENT_CHANGES\([^}]*\)}#\1$RECENT\2#" \ 1.447 + -e "s#{\([^}]*\)HOME\([^}]*\)}#\1$HOME\2#" \ 1.448 + -e "s#{\([^}]*\)HELP\([^}]*\)}#$HELP#" \ 1.449 + -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>#" \ 1.450 + < $template )" 1.451 +[ "$action" != "" -a "$action" != "edit" -o ! -e "$PAGE_txt" ] && TIME="-" 1.452 +plugin_call_method template 1.453 +[ -n "$(GET error)" ] || ERROR="" 1.454 +[ -n "$HISTORY" ] && HISTORY="\1$HISTORY\2" 1.455 +PAGE_TITLE_str="$(htmlentities "$PAGE_TITLE")" 1.456 +$PAGE_TITLE_link && 1.457 +PAGE_TITLE_str="<a href=\"$urlbase?page=$(urlencode "$PAGE_TITLE")\">$PAGE_TITLE_str</a>" 1.458 +EDIT="$EDIT_BUTTON" 1.459 +if $editable ; then 1.460 + EDIT="$PROTECTED_BUTTON" 1.461 + [ -w "$PAGE_txt" -o ! -e "$PAGE_txt" ] && 1.462 + EDIT="<a href=\"$urlbase?page=$(urlencode "$PAGE_TITLE")\&action=edit\" accesskey=\"5\" rel=\"nofollow\">$EDIT_BUTTON</a>" 1.463 +fi 1.464 +[ -n "$toc" ] && toc="\1$toc\2" 1.465 +AUTH_GET="" 1.466 +AUTH_POST="" 1.467 +if authentified; then 1.468 + AUTH_GET="auth=$AUTH\&" 1.469 + AUTH_POST="\n<input type=\"hidden\" name=\"auth\" value=\"$AUTH\" />" 1.470 +fi 1.471 + 1.472 +header "Content-type: text/html" 1.473 +sed -e "s#{ERROR}#$ERROR#" -e "s#{WIKI_TITLE}#$WIKI_TITLE#" \ 1.474 + -e "s#{\([^}]*\)HISTORY\([^}]*\)}#$HISTORY#" \ 1.475 + -e "s#{PAGE_TITLE}#$PAGE_TITLE_str#" \ 1.476 + -e "s#{\([^}]*\)EDIT\([^}]*\)}#\1$EDIT\2#" \ 1.477 + -e "s|{\([^}]*\)TOC\([^}]*\)}|$(awk '{ printf "%s\\n" $0 }' <<EOT | \ 1.478 + sed -e 's/&/\\\&/g' -e 's/|/\\|/g' 1.479 +$toc 1.480 +EOT 1.481 +)|" \ 1.482 + -e "s#{PAGE_TITLE_BRUT}#$(htmlentities "$PAGE_TITLE")#" \ 1.483 + -e "s#{LAST_CHANGE}#$LAST_CHANGES :#" \ 1.484 + -e "s#{CONTENT}#$(awk '{ printf "%s\\n" $0 }' <<EOT | \ 1.485 + sed -e 's/&/\\\&/g' -e 's/#/\\#/g' 1.486 +$CONTENT 1.487 +EOT 1.488 +)#" \ 1.489 + -e "s#{LANG}#$LANG#" -e "s#href=\"?#href=\"$urlbase?#g" \ 1.490 + -e "s#$urlbase?#&$AUTH_GET#g" -e "s#action=\"$urlbase\">#&$AUTH_POST#g" \ 1.491 + -e "s#{WIKI_VERSION}#$WIKI_VERSION#" \ 1.492 + -e "s#{TIME}#$TIME#" -e "s#{DATE}#$datew#" \ 1.493 + -e "s#{IP}#$REMOTE_ADDR#" -e "s#{COOKIE}##" <<EOT 1.494 +$html 1.495 +EOT