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