]> git.plutz.net Git - busy/blob - templates/Wiki_show.page
sorted out text designs
[busy] / templates / Wiki_show.page
1 #!/bin/zsh
2
3 list_comments() {
4   base="$1"
5   
6   for each in $(ls -r Wiki/${base}.comment.<0000000001-9999999999>_<000-999>); do
7     author=$(grep -m1 '^author=' "$each" |cut -d= -f2-)
8     echo "<div class='comment'><h1>$author wrote:</h1><div class='wikitext'>"
9     tail -n+2 $each |_wiki
10     echo '</div></div>'
11   done
12 }
13
14 add_comment(){
15   info="$1"
16
17   cat <<WikiEND
18       <a id='comment_button' class='function' href='#'
19          onclick='javascript:show_screen("comment");hide_screen("comment_button");'>Comment / Ask</a>
20       <div id="comment" style="display: none;">
21         <form action="/?action=wikimeta&i=$info" method="post" accept-charset="UTF-8">
22           <b>Comment:</b><br>
23           <textarea name="comm" rows="6" style="width:99%;"></textarea><br>
24           <input type="submit" value="Submit">
25           <a class="function" href="#" onclick="javascript:hide_screen('comment');show_screen('comment_button');">Cancel</a>
26         </form>
27       </div>
28 WikiEND
29 }
30
31 cat <<WikiEND
32     <div id="LEFT">
33       <form method="GET" action="/${SCRIPTNAME}" accept-charset="utf-8">
34         <input type="hidden" name="p" value="Wiki">
35         <input type="text" name="s" placeholder="Search"><br>
36         <input type="submit" value="Search Wiki">
37       </form>
38       <hr>
39
40       <b>Revisions:</b>
41       $(rno=1; for each in Wiki/$info.<0000000000-9999999999>; do
42         revi=$(cut -d. -f2 <<<"$each")
43         echo "<a class='rev' href='?p=Wiki&amp;i=$info&amp;r=$revi'>$rno</a>"
44         rno=$(($rno+1))
45         done) <a class='rev' href='?p=Wiki&amp;i=$info'>Latest</a><br>
46       <hr>
47       $($LOGIN && if [ -z "$lock" ]; then
48           [ -z "$rev" ] && echo "<a class='function' href='/?action=lock&amp;p=Wiki&amp;e=$info'>edit this page</a>"
49           [ -n "$rev" ] && echo "Click <a class='function' href='/?action=lock&amp;p=Wiki&amp;e=${info}&amp;r=${rev:s/.//}'>edit</a> to derive a new page revision from this one."
50         else
51           echo "<b>This page is currently being edited by $lock</b><a class='function' href='/?action=lock&amp;p=Wiki&amp;e=$info'>edit anyway</a>"
52         fi
53         $LOGIN && echo '<hr>')
54       <h1>Table of Content</h1>
55       <div class="toc">
56         $(cat Wiki/"${info}${rev}" |while read line; do
57         if (egrep -q '^ *###' <<<"$line"); then
58           echo "<a class='i2' href='#$(sed 's,^ *### *,,;' <<<"$line")'>$(sed 's,^ *###,,' <<<"$line")</a><br>"
59         elif (egrep -q '^ *##' <<<"$line"); then
60           echo "<a class='i1' href='#$(sed 's,^ *## *,,;' <<<"$line")'>$(sed 's,^ *##,,' <<<"$line")</a><br>"
61         elif (egrep -q '^ *#' <<<"$line"); then
62           echo "<a class='i0' href='#$(sed 's,^ *# *,,;' <<<"$line")'>$(sed 's,^ *#,,' <<<"$line")</a><br>"
63           fi
64         done)
65       </div>
66       <hr>
67     </div>
68     <div id="MAIN">
69       <div class="wiki"><div class="wikitext">
70         <h1 class="wikihead">$title</h1>
71         $(_wiki Wiki/"${info}${rev}")
72       </div></div>
73     </div>
74
75     <div id="RIGHT">
76       $($LOGIN && add_comment $info)
77       $(list_comments $info)
78     </div>
79 WikiEND