tinycm view index.cgi @ rev 57

Fix i18n
author Christophe Lincoln <pankso@slitaz.org>
date Sat Jan 25 14:23:23 2014 +0100 (2014-01-25)
parents 8a26630ccceb
children 8d24e0cbcdab
line source
1 #!/bin/sh
2 #
3 # TinyCM - Small, fast and elegent CGI/SHell Content Manager
4 #
5 # Copyright (C) 2012-2014 SliTaz GNU/Linux - BSD License
6 #
7 . /usr/lib/slitaz/httphelper
9 # Let's have a peer site config file with a .cgi extension so content
10 # is secure even if left in a web server directory.
11 . ./config.cgi
13 tiny="$PWD"
14 content="content"
15 wiki="$content/wiki"
16 index="index"
17 cache="cache"
18 plugins="plugins"
19 tmp="/tmp/tinycm"
20 sessions="$tmp/sessions"
21 script="$SCRIPT_NAME"
22 activity="$cache/log/activity.log"
24 # Content negotiation for Gettext
25 IFS=","
26 for lang in $HTTP_ACCEPT_LANGUAGE
27 do
28 lang=${lang%;*} lang=${lang# } lang=${lang%-*}
29 case "$lang" in
30 en) lang="C" && break ;;
31 fr) lang="fr_FR" && break ;;
32 pt) lang="pt_BR" && break ;;
33 ru) lang="ru_RU" && break ;;
34 esac
35 done
36 unset IFS
37 export LANG=$lang LC_ALL=$lang
39 # Internationalization
40 . /usr/bin/gettext.sh
41 TEXTDOMAIN='tinycm'
42 export TEXTDOMAIN
44 #
45 # Functions
46 #
48 # Used by edit to display language name and the language box. This is
49 # for CM content not gettext support.
50 get_lang() {
51 dlang=$(echo $d | cut -d "/" -f 1)
52 doc=${d#$dlang/}
53 echo '<div id="lang">'
54 for l in $LANGUAGES
55 do
56 case $dlang in
57 en) i18n="English" ;;
58 fr) i18n="Français" ;;
59 pt) i18n="Português" ;;
60 ru) i18n="Русский" ;;
61 *) i18n="*" ;;
62 esac
63 echo "<a href='?d=$l/$doc'>$l</a>"
64 done
65 echo '</div>'
66 }
68 # HTML 5 header.
69 html_header() {
70 if [ -f "$tiny/lib/header.html" ]; then
71 cat $tiny/lib/header.html | sed -e s!'%TITLE%'!"$TITLE - $d"!g
72 else
73 cat << EOT
74 <!DOCTYPE html>
75 <html xmlns="http://www.w3.org/1999/xhtml">
76 <head>
77 <title>$TITLE</title>
78 <meta charset="utf-8" />
79 <style type="text/css">body { margin: 40px 120px; }</style>
80 </head>
81 <body>
82 <!-- Content -->
83 <div id="content">
84 EOT
85 fi
86 }
88 # HTML 5 footer.
89 html_footer() {
90 if [ -f "$tiny/lib/footer.html" ]; then
91 cat $tiny/lib/footer.html
92 else
93 cat << EOT
95 <!-- End content -->
96 </div>
98 <div id="footer">&hearts;</div>
100 </body>
101 </html>
102 EOT
103 fi
104 }
106 # Default index if missing
107 default_index() {
108 mkdir -p "$wiki"
109 cat > $wiki/$index.txt << EOT
110 ==== Welcome ====
112 <p>
113 This is the default index page of your TinyCM, you can login then start to
114 edit and adding some content. You can read the help about text formating
115 and functions: [Help page|en/help]
116 </p>
118 EOT
119 }
121 # Log main activity.
122 log_activity() {
123 [ -d "$cache/log" ] || mkdir -p ${cache}/log
124 #gravatar="$(get_gravatar $MAIL 24)"
125 grep ^[A-Z] | \
126 sed s"#^[A-Z]\([^']*\)#$user|$(date '+%Y-%m-%d')|\0#" \
127 >> $cache/log/activity.log
128 }
130 # Log documents activity.
131 log() {
132 grep ^[A-Z] | \
133 sed s"#^[A-Z]\([^']*\)#$(date '+%Y-%m-%d %H:%M') : \0#" \
134 >> $cache/$d/activity.log
135 }
137 # Check if user is auth
138 check_auth() {
139 auth="$(COOKIE auth)"
140 user="$(echo $auth | cut -d ":" -f 1)"
141 md5cookie="$(echo $auth | cut -d ":" -f 2)"
142 [ -f "$sessions/$user" ] && md5session="$(cat $sessions/$user)"
143 if [ "$md5cookie" == "$md5session" ] && [ "$auth" ]; then
144 . $PEOPLE/$user/account.conf
145 return 0
146 else
147 return 1
148 fi
149 }
151 # Check if user is admin
152 admin_user() {
153 fgrep -q 'ADMIN_USER="yes"' ${PEOPLE}/${user}/account.conf
154 }
156 # Authentified or not
157 user_box() {
158 if check_auth; then
159 cat << EOT
161 <div id="user">
162 <a href="$script?user=$user">$(get_gravatar $MAIL 20)</a>
163 <a href="$script?logout">Logout</a>
164 </div>
166 EOT
167 else
168 cat << EOT
170 <div id="user">
171 <a href="$script?login"><img src="images/avatar.png" alt="[ User ]" /></a>
172 <a href="$script?login">Login</a>
173 </div>
175 EOT
176 fi
177 cat << EOT
178 <!--
179 <div id="search">
180 <form method="get" action="$script">
181 <input type="text" name="search" placeholder="$(gettext "Search")" />
182 </form>
183 </div>
184 -->
185 EOT
186 }
188 # Link for online signup if enabled.
189 online_signup() {
190 if [ "$ONLINE_SIGNUP" == "yes" ]; then
191 echo -n "<p><a href='$script?signup'>"
192 gettext "Create a new account"
193 echo '</a></p>'
194 fi
195 }
197 # Login page
198 login_page() {
199 cat << EOT
200 <h2>$(gettext "Login")</h2>
202 <div id="account-info">
203 $(gettext "No account yet or trouble with you account? Please send
204 a request to $ADMIN_MAIL with your real name, user name, mail and password.")
205 $(online_signup)
206 </div>
208 <div id="login">
209 <form method="post" action="$script">
210 <input type="text" name="auth" placeholder="$(gettext "User name")" />
211 <input type="password" name="pass" placeholder="$(gettext "Password")" />
212 <div>
213 <input type="submit" value="Login" /> $error
214 </div>
215 </form>
216 </div>
218 <div style="clear: both;"></div>
219 EOT
220 }
222 # Signup page
223 signup_page() {
224 cat << EOT
226 <div id="signup">
227 <form method="post" name="signup" action="$script" onsubmit="return checkSignup();">
228 <input type="hidden" name="signup" value="new" />
229 <input type="text" name="name" placeholder="$(gettext "Real name")" />
230 <input type="text" name="user" placeholder="$(gettext "User name")" />
231 <input type="text" name="mail" placeholder="$(gettext "Email")" />
232 <input type="password" name="pass" placeholder="$(gettext "Password")" />
233 <div>
234 <input type="submit" value="$(gettext "Create new account")" />
235 </div>
236 </form>
237 </div>
239 EOT
240 }
242 # Create a new user in AUTH_FILE and PEOPLE
243 new_user_config() {
244 if [ ! -f "$AUTH_FILE" ];then
245 touch $(DESTDIR)$(LOGIN)/auth/people
246 chmod 0600 $(DESTDIR)$(LOGIN)/auth/people
247 fi
248 key=$(echo -n "$user:$mail:$pass" | md5sum | awk '{print $1}')
249 echo "$user:$pass" >> $AUTH_FILE
250 mkdir -p $PEOPLE/$user/
251 cat > $PEOPLE/$user/account.conf << EOT
252 # SliTaz user configuration
253 #
255 NAME="$name"
256 USER="$user"
257 MAIL="$mail"
258 KEY="$key"
260 EOT
261 chmod 0600 $PEOPLE/$user/account.conf
262 # First created user is admin
263 if [ $(ls ${PEOPLE} | wc -l) == "1" ]; then
264 echo 'ADMIN_USER="yes"' >> $PEOPLE/$user/account.conf
265 fi
266 }
268 # Display user public profile.
269 public_people() {
270 echo "</pre>"
271 # Display personnal user profile
272 if [ -f "$PEOPLE/$USER/profile.txt" ]; then
273 cat $PEOPLE/$USER/profile.txt | wiki_parser
274 fi
275 }
277 # Display authentified user profile. TODO: change password
278 auth_people() {
279 cat << EOT
280 Email : $MAIL
281 Secure key : $KEY
282 </pre>
283 EOT
284 # Each user can have personal profile page
285 if [ -f "$PEOPLE/$USER/profile.txt" ]; then
286 cat $PEOPLE/$USER/profile.txt | wiki_parser
287 cat << EOT
288 <div id="tools">
289 <a href="$script?edit=profile">$(gettext "Edit profile")</a>
290 </div>
291 EOT
292 else
293 cat << EOT
294 <div id="tools">
295 <a href="$script?edit=profile">$(gettext "Create a profile page")</a>
296 </div>
297 EOT
298 fi
299 }
301 # The CM style parser. Just a title, simple text formating and internal
302 # links, as well as images and use HTML for other stuff. Keep it fast!
303 # To make TinyCM as easy as possible we have a small HTML editor/helper
304 # written in Javascript
305 wiki_parser() {
306 doc="[0-9a-zA-Z\.\#/~\_%=\?\&,\+\:@;!\(\)\*\$'\-]*"
307 sed \
308 -e s"#====\([^']*\)====#<h2>\1</h2>#"g \
309 -e s"#===\([^']*\)===#<h3>\1</h3>#"g \
310 -e s"#==\([^']*\)==#<h4>\1</h4>#"g \
311 -e s"#\*\*\([^']*\)\*\*#<b>\1</b>#"g \
312 -e s"#''\([^']*\)''#<em>\1</em>#"g \
313 -e s"#__\([^']*\)__#<u>\1</u>#"g \
314 -e s"#\[\([^]]*\)|\($doc\)\]#<a href='$script?d=\2'>\1</a>#"g \
315 -e s"#\[\([^]]*\)!\($doc\)\]#<a href='\2'>\1</a>#"g \
316 -e s"#\[\(http://*[^]]*.png\)\]#<img src='\1' />#"g \
317 -e s"#\[\([^]]*.png\)\]#<img src='content/cloud/\1' />#"g
318 }
320 link_user() {
321 echo "<a href='$(basename $script)?user=$user'>$user</a>"
322 }
324 # Save a document. Do we need more than 1 backup and diff ?
325 save_document() {
326 mkdir -p $cache/$d $(dirname $wiki/$d)
327 # May be a new page.
328 if [ ! -f "$wiki/$d.txt" ]; then
329 new=0
330 touch $wiki/$d.txt
331 fi
332 cp $wiki/$d.txt $cache/$d/last.bak
333 sed "s/$(echo -en '\r') /\n/g" > $wiki/$d.txt << EOT
334 $(GET content)
335 EOT
336 diff $cache/$d/last.bak $wiki/$d.txt > $cache/$d/last.diff
337 # Log
338 if [ "$new" ]; then
339 echo "Page created by: $(link_user)" | log
340 echo "New document: <a href='$script?d=$d'>$d</a>" | log_activity
341 if [ "$HG" == "yes" ]; then
342 cd $content && hg -q add
343 hg commit -q -u "$NAME <$MAIL>" -m "Created new document: $d"
344 cd $tiny
345 fi
346 else
347 # Here we may clean log: cat && tail -n 40
348 echo "Page edited by: $(link_user)" | log
349 if [ "$HG" == "yes" ]; then
350 cd $content && hg commit -q -u "$NAME <$MAIL>" \
351 -m "Edited document: $d"
352 cd $tiny
353 fi
354 fi
355 }
357 # Save a user profile.
358 save_profile() {
359 path="$PEOPLE/$user"
360 cp -f ${path}/${d}.txt ${path}/${d}.bak
361 sed "s/$(echo -en '\r') /\n/g" > ${path}/${d}.txt << EOT
362 $(GET content)
363 EOT
364 }
366 # CM tools (edit, diff, etc) for auth users
367 wiki_tools() {
368 if check_auth; then
369 cat << EOT
370 <div id="tools">
371 <a href="$script?edit=$d">$(gettext "Edit document")</a>
372 <a href="$script?diff=$d">$(gettext "Last diff")</a>
373 <a href="$script?log=$d">$(gettext "File log")</a>
374 <a href='$script?dashboard'>$(gettext 'Dashboard')</a>
375 EOT
376 [ "$HG" == "yes" ] && echo "<a href='$script?hg'>Hg Log</a>"
377 echo "</div>"
378 fi
379 }
381 # Built-in Dashboard tools and ADMIN_TOOLS from plugins
382 dashboard_tools() {
383 if check_auth; then
384 cat << EOT
385 <div id='tools'>
386 <a href='$script?log'>Activity log</a>
387 <a href='$script?ls'>Pages list</a>
388 <a href='$script?dashboard'>Dashboard</a>
389 </div>
390 EOT
391 fi
392 }
394 # Get and display Gravatar image: get_gravatar email size
395 # Link to profile: <a href="http://www.gravatar.com/$md5">...</a>
396 get_gravatar() {
397 email=$1
398 size=$2
399 [ "$size" ] || size=48
400 url="http://www.gravatar.com/avatar"
401 md5=$(md5crypt $email)
402 echo "<img src='$url/$md5?d=identicon&s=$size' alt='&lowast;' />"
403 }
405 # List hg logs
406 hg_log() {
407 cd $content
408 cat << EOT
409 <table>
410 <thead>
411 <td>$(gettext "User")</td>
412 <td>$(gettext "Description")</td>
413 <td>$(gettext "Revision")</td>
414 </thead>
415 EOT
416 hg log --template "<tr><td>{author}</td><td>{desc}</td><td>{rev}</td></tr>\n"
417 echo '</table>'
418 }
420 #
421 # POST actions
422 #
424 case " $(POST) " in
425 *\ auth\ *)
426 # Authenticate user. Create a session file in $sessions to be used
427 # by check_auth. We have the user login name and a peer session
428 # md5 string in the COOKIE.
429 user="$(POST auth)"
430 pass="$(md5crypt "$(POST pass)")"
431 valid=$(fgrep "${user}:" $AUTH_FILE | cut -d ":" -f 2)
432 if [ "$pass" == "$valid" ] && [ "$pass" != "" ]; then
433 md5session=$(echo -n "$$:$user:$pass:$$" | md5sum | awk '{print $1}')
434 [ -d $sessions ] || mkdir -p $sessions
435 date '+%Y-%m-%d' > ${PEOPLE}/${user}/last
436 echo "$md5session" > $sessions/$user
437 header "Location: $script" \
438 "Set-Cookie: auth=$user:$md5session; HttpOnly"
439 else
440 header "Location: $script?login&error"
441 fi ;;
442 *\ signup\ *)
443 # POST action for signup
444 name="$(POST name)"
445 user="$(POST user)"
446 mail="$(POST mail)"
447 pass="$(md5crypt "$(POST pass)")"
448 if ! grep "^${user}:" $AUTH_FILE; then
449 new_user_config
450 header "Location: $script?login"
451 else
452 header
453 html_header
454 user_box
455 echo "<h2>$(gettext 'User already exists:') $user</h2>"
456 html_footer
457 fi ;;
458 esac
460 #
461 # Plugins
462 #
463 for p in $(ls -1 $plugins)
464 do
465 [ -f "$plugins/$p/$p.conf" ] && . $plugins/$p/$p.conf
466 [ -x "$plugins/$p/$p.cgi" ] && . $plugins/$p/$p.cgi
467 done
469 #
470 # GET actions
471 #
473 case " $(GET) " in
474 *\ edit\ *)
475 d="$(GET edit)"
476 header
477 html_header
478 user_box
479 get_lang
480 if check_auth; then
481 if [ "$doc" == "profile" ]; then
482 wiki="$PEOPLE/$user"
483 fi
484 cat << EOT
485 <h2>$(gettext "Edit $doc [ $i18n ]")</h2>
487 <div id="edit">
489 <form method="get" action="$script" name="editor">
490 <input type="hidden" name="save" value="$d" />
491 <textarea name="content">$(cat "$wiki/$d.txt")</textarea>
492 <input type="submit" value="$(gettext "Save document")" />
493 $(gettext "Code Helper:")
494 $(cat lib/jseditor.html)
495 </form>
497 </div>
498 EOT
499 else
500 gettext "You must be logged in to edit pages"
501 fi
502 html_footer ;;
504 *\ save\ *)
505 d="$(GET save)"
506 if check_auth; then
507 # User profile
508 if [ "$d" == "profile" ]; then
509 save_profile
510 header "Location: $script?user=$user"
511 else
512 save_document
513 fi
514 fi
515 header "Location: $script?d=$d" ;;
517 *\ log\ *)
518 d="$(GET log)"
519 header
520 html_header
521 user_box
522 # Main activity
523 if [ "$d" == "log" ]; then
524 dashboard_tools
525 echo "<h2>$(gettext "Activity log")</h2>"
526 echo '<pre>'
527 if [ -f "$cache/log/activity.log" ]; then
528 IFS="|"
529 tac $cache/log/activity.log | while read USER DATE LOG
530 do
531 . ${PEOPLE}/${USER}/account.conf
532 cat << EOT
533 <a href='$script?user=$USER'>$(get_gravatar $MAIL 24)</a>\
534 <span class='date'>$DATE -</span> $LOG
535 EOT
536 done
537 unset IFS
538 else
539 gettext "No activity log yet"; echo
540 fi
541 echo '</pre>'
542 html_footer && exit 0
543 fi
544 # Document activity
545 get_lang
546 wiki_tools
547 echo "<h2>$(gettext "Activity for:") <a href='$script?d=$d'>$d</a></h2>"
548 echo '<pre>'
549 if [ -f "$cache/$d/activity.log" ]; then
550 tac $cache/$d/activity.log
551 else
552 gettext "No log for: $d"; echo
553 fi
554 echo '</pre>'
555 html_footer ;;
557 *\ ls\ *)
558 d="Document list"
559 header
560 html_header
561 user_box
562 dashboard_tools
563 echo "<h2>$(gettext "Pages list")</h2>"
564 echo '<pre>'
565 cd ${wiki}
566 for d in $(find . -type f | sed s'/.\///')
567 do
568 cat << EOT
569 <a href="$script?d=${d%.txt}">${d%.txt}</a> : \
570 <a href="$script?rm=$d">$(gettext "Remove")</a> || \
571 <a href="$script?edit=$d">$(gettext "Edit")</a>
572 EOT
573 done
574 echo '</pre>'
575 html_footer ;;
577 *\ rm\ *)
578 [ ! check_auth ] && header "Location: Location: $script"
579 d="$(GET rm)"
580 rm ${wiki}/"${d}"
581 rm -rf ${cache}/"${d%.txt}"
582 header "Location: $script?ls" ;;
584 *\ diff\ *)
585 d="$(GET diff)"
586 date="last"
587 header
588 html_header
589 user_box
590 get_lang
591 wiki_tools
592 echo "<h2>$(gettext "Diff for:") <a href='$script?d=$d'>$d</a></h2>"
593 echo '<pre>'
594 if [ -f "$cache/$d/$date.diff" ]; then
595 cat $cache/$d/$date.diff | sed \
596 -e 's|&|\&amp;|g' -e 's|<|\&lt;|g' -e 's|>|\&gt;|g' \
597 -e s"#^-\([^']*\).#<span style='color: red;'>\0</span>#"g \
598 -e s"#^+\([^']*\).#<span style='color: green;'>\0</span>#"g \
599 -e s"#@@\([^']*\)@@#<span style='color: blue;'>@@\1@@</span>#"g
600 else
601 gettext "No diff for: $d"; echo
602 fi
603 echo '</pre>'
604 html_footer ;;
606 *\ login\ *)
607 # The login page
608 d="Login"
609 [ "$(GET error)" ] && \
610 error="<p class="error">$(gettext "Bad login or pass")</p>"
611 header
612 html_header
613 user_box
614 login_page
615 html_footer ;;
617 *\ signup\ *)
618 # The login page
619 d="$(gettext "Sign Up")"
620 header
621 html_header
622 user_box
623 echo "<h2>$d</h2>"
624 if [ "$ONLINE_SIGNUP" == "yes" ]; then
625 signup_page
626 else
627 gettext "Online registration is disabled"
628 fi
629 html_footer ;;
631 *\ logout\ *)
632 # Set a Cookie in the past to logout.
633 expires="Expires=Wed, 01-Jan-1980 00:00:00 GMT"
634 if check_auth; then
635 rm -f "$sessions/$user"
636 header "Location: $script" "Set-Cookie: auth=none; $expires; HttpOnly"
637 fi ;;
639 *\ user\ *)
640 # User profile
641 d="$(GET user)"
642 last="$(cat $PEOPLE/"$(GET user)"/last)"
643 header
644 html_header
645 user_box
646 . $PEOPLE/"$(GET user)"/account.conf
647 cat << EOT
648 <h2>$(get_gravatar $MAIL) $NAME</h2>
650 <pre>
651 $(gettext "User name :") $USER
652 $(gettext "Last login :") $last
653 EOT
654 if check_auth && [ "$(GET user)" == "$user" ]; then
655 auth_people
656 else
657 # check_auth will set VARS to current logged user: re-source
658 . $PEOPLE/"$(GET user)"/account.conf
659 public_people
660 fi
661 html_footer ;;
663 *\ dashboard\ *)
664 # For now simply list plugins and users info. We could have a
665 # dashbord only for ADMINS found in the config file. The dashboard
666 # should also be a plugin.
667 d="Dashboard"
668 header
669 html_header
670 user_box
671 users=$(ls -1 $PEOPLE | wc -l)
672 docs=$(find $wiki -type f | wc -l)
673 wikisize="$(du -sh $wiki | awk '{print $1}')"
674 cachesize="$(du -sh $cache | awk '{print $1}')"
675 [ "$HG" != "yes" ] && hg=$(gettext "disabled")
676 [ "$HG" == "yes" ] && hg=$(gettext "enabled")
677 # Source all plugins.conf to get DASHBOARD_TOOLS and ADMIN_TOOLS
678 ADMIN_TOOLS=""
679 DASHBOARD_TOOLS=""
680 for p in $(ls $plugins)
681 do
682 . $plugins/$p/$p.conf
683 done
684 if check_auth && ! admin_user; then
685 ADMIN_TOOLS=""
686 fi
687 if check_auth; then
688 cat << EOT
689 <div id="tools">
690 <a href='$script?log'>Activity log</a>
691 <a href='$script?ls'>Pages list</a>
692 $DASHBOARD_TOOLS
693 $ADMIN_TOOLS
694 </div>
696 <h2>$d</h2>
698 <pre>
699 Users : $users
700 Wiki : $docs ($wikisize)
701 Cache : $cachesize
702 Mercurial : $hg
703 </pre>
705 <h3>Admin users</h3>
706 EOT
707 # Get the list of administrators
708 for u in $(ls $PEOPLE)
709 do
710 user=${u}
711 if admin_user; then
712 echo "<a href='?user=$u'>$u</a>"
713 fi
714 done
715 cat << EOT
716 <h3>$(gettext "Plugins")</h3>
717 <pre>
718 EOT
719 for p in $(ls -1 $plugins)
720 do
721 . $plugins/$p/$p.conf
722 echo "<a href='?$p'>$PLUGIN</a> - $SHORT_DESC"
723 done
724 echo '</pre>'
725 else
726 gettext "You must be logged in to view the dashboard."
727 fi
728 html_footer ;;
730 *\ hg\ *)
731 header
732 [ "$HG" != "yes" ] && gettext "Hg is disabled" && exit 0
733 [ ! -x /usr/bin/hg ] && gettext "Hg is not installed" && exit 0
734 d="Hg Log"
735 html_header
736 user_box
737 echo "<h2>$d</h2>"
738 case " $(GET hg) " in
739 *\ init\ *)
740 if check_auth; then
741 [ -d "$content/.hg" ] && exit 0
742 echo '<pre>'
743 gettext "Executing: hg init"; echo
744 cd $content/ && hg init
745 echo '[hooks]' > .hg/hgrc
746 echo 'incoming = hg update' >> .hg/hgrc
747 gettext "Adding current content and committing"; echo
748 [ ! -f "$wiki/index.txt" ] && touch $wiki/$index.txt
749 hg add && hg commit -u "$NAME <$MAIL>" \
750 -m "Initial commit with current content"
751 echo '</pre>' && cd ..
752 fi ;;
753 esac
754 hg_log
755 html_footer ;;
757 *)
758 # Display requested page
759 d="$(GET d)"
760 [ "$d" ] || d=$index
761 header
762 html_header
763 user_box
764 get_lang
766 # Generate a default index on first run
767 if [ ! -f "$wiki/$index.txt" ]; then
768 if ! default_index; then
769 echo "<pre class='error'>Directory : content/ is not writable</pre>"
770 html_footer && exit 0
771 fi
772 fi
774 # Check cache dir
775 if [ ! -w "$cache" ]; then
776 echo "<pre class='error'>Directory : cache/ is not writable"
777 echo "Command : install -m 0777 -d $tiny/cache</pre>"
778 html_footer && exit 0
779 fi
781 # Wiki tools and Hg warning if enabled but not initiated
782 if [ "$HG" == "yes" ] && [ ! -d "$content/.hg" ]; then
783 echo '<p class="error box">'
784 gettext "Mercurial is enabled but no repository found"
785 echo ": <a href='?hg=init'>Hg init</a>"
786 echo '</p>'
787 fi
789 # Wiki tools
790 wiki_tools
792 # Wiki document
793 if [ ! -f "$wiki/$d.txt" ]; then
794 echo "<h2>$d</h2>"
795 gettext "The document does not exist. You can create it or read the"
796 echo " <a href='?d=en/help'>help</a>"
797 else
798 if fgrep -q [NOWIKI] $wiki/$d.txt; then
799 cat $wiki/$d.txt | sed '/\[NOWIKI\]/'d
800 else
801 cat $wiki/$d.txt | wiki_parser
802 fi
803 fi
804 html_footer ;;
805 esac
807 exit 0