]> git.plutz.net Git - busy/blob - templates/Wiki_show.page
upgraded to fit new shcgi revision, slightly better input validation, switched to...
[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 wikitext="$(_wiki Wiki/"${info}${rev}")"
32 wikitoc="$(echo -E "$wikitext" \
33            | sed -rn '/<h[0-9]>.+<\/h[0-9]>/s;^.*<h([0-9])><a name="(.+)">(.+)</a></h[0-9]>.*$;<a class="i\1" href="#\2">\3</a><br>;p'
34           )"
35
36 cat <<WikiEND
37     <div id="LEFT">
38       <form method="GET" action="./" accept-charset="utf-8">
39         <input type="hidden" name="p" value="Wiki">
40         <input type="text" name="s" placeholder="Search"><br>
41         <input type="submit" value="Search Wiki">
42       </form>
43       <hr>
44
45       <b>Revisions:</b>
46       $(rno=1; for each in Wiki/$info.<0000000000-9999999999>; do
47         revi=$(cut -d. -f2 <<<"$each")
48         echo "<a class='rev' href='?p=Wiki&amp;i=$info&amp;r=$revi'>$rno</a>"
49         rno=$(($rno+1))
50         done) <a class='rev' href='?p=Wiki&amp;i=$info'>Latest</a><br>
51       <hr>
52       $($LOGIN && if [ -z "$lock" ]; then
53           [ -z "$rev" ] && echo "<a class='function' href='./?action=lock&amp;p=Wiki&amp;e=$info'>edit this page</a>"
54           [ -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."
55         else
56           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>"
57         fi
58         $LOGIN && echo '<hr>')
59       <h1>Table of Content</h1>
60       <div class="toc">
61         ${wikitoc}
62       </div>
63       <hr>
64     </div>
65     <div id="MAIN">
66       <div class="wiki"><div class="wikitext">
67         <h1 class="wikihead">$title</h1>
68         ${wikitext}
69       </div></div>
70     </div>
71
72     <div id="RIGHT">
73       $($LOGIN && add_comment $info)
74       $(list_comments $info)
75     </div>
76 WikiEND