slitaz-dev-tools annotate tazwikiss/rootfs/var/www/wiki/index.sh @ rev 310

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