]> git.plutz.net Git - busy/blobdiff - templates/Wiki_show.page
porting busy to confetti framework
[busy] / templates / Wiki_show.page
diff --git a/templates/Wiki_show.page b/templates/Wiki_show.page
new file mode 100755 (executable)
index 0000000..87e848f
--- /dev/null
@@ -0,0 +1,80 @@
+#!/bin/zsh
+
+list_comments() {
+  base="$1"
+  
+  stat -c '' Wiki/${base}.comment.<0000000001-9999999999>_<000-999> \
+  && for each in $(ls -c Wiki/${base}.comment.<0000000001-9999999999>_<000-999>); do
+    author=$(grep -m1 '^author=' "$each" |cut -d= -f2-)
+    echo "<div class='comment'><h1>$author wrote:</h1><div class='wikitext'>"
+    tail -n+2 $each |_wiki
+    echo '</div></div>'
+  done
+}
+
+add_comment(){
+  info="$1"
+
+  cat <<WikiEND
+      <a id='comment_button' class='function' href='#'
+         onclick='javascript:show_screen("comment");hide_screen("comment_button");'>Comment / Ask</a>
+      <div id="comment" style="display: none;">
+        <form action="/?action=wikimeta&i=$info" method="post" accept-charset="UTF-8">
+          <b>Comment:</b><br>
+          <textarea name="comm" rows="6" style="width:99%;"></textarea><br>
+          <input type="submit" value="Submit">
+          <a class="function" href="#" onclick="javascript:hide_screen('comment');show_screen('comment_button');">Cancel</a>
+        </form>
+      </div>
+WikiEND
+}
+
+cat <<WikiEND
+    <div id="LEFT">
+      <form method="GET" action="/${SCRIPTNAME}" accept-charset="utf-8">
+       <input type="hidden" name="p" value="Wiki">
+       <input type="text" name="s" placeholder="Search"><br>
+       <input type="submit" value="Search Wiki">
+      </form>
+      <hr>
+
+      <b>Revisions:</b>
+      $(rno=1; for each in Wiki/$info.<0000000000-9999999999>; do
+       revi=$(cut -d. -f2 <<<"$each")
+       echo "<a class='rev' href='?p=Wiki&amp;i=$info&amp;r=$revi'>$rno</a>"
+       rno=$(($rno+1))
+        done) <a class='rev' href='?p=Wiki&amp;i=$info'>Latest</a><br>
+      <hr>
+      $($LOGIN && if [ -z "$lock" ]; then
+          [ -z "$rev" ] && echo "<a class='function' href='/?action=lock&amp;p=Wiki&amp;e=$info'>edit this page</a>"
+         [ -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."
+        else
+         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>"
+        fi
+        $LOGIN && echo '<hr>')
+      <h1>Table of Content</h1>
+      <div class="toc">
+        $(cat Wiki/"${info}${rev}" |while read line; do
+       if (egrep -q '^ *###' <<<"$line"); then
+         echo "<a class='i2' href='#$(sed 's,^ *### *,,;' <<<"$line")'>$(sed 's,^ *###,,' <<<"$line")</a><br>"
+       elif (egrep -q '^ *##' <<<"$line"); then
+         echo "<a class='i1' href='#$(sed 's,^ *## *,,;' <<<"$line")'>$(sed 's,^ *##,,' <<<"$line")</a><br>"
+       elif (egrep -q '^ *#' <<<"$line"); then
+         echo "<a class='i0' href='#$(sed 's,^ *# *,,;' <<<"$line")'>$(sed 's,^ *#,,' <<<"$line")</a><br>"
+          fi
+        done)
+      </div>
+      <hr>
+    </div>
+    <div id="MAIN">
+      <div class="wiki"><div class="wikitext">
+        <h1>$title</h1>
+        $(_wiki Wiki/"${info}${rev}")
+      </div></div>
+    </div>
+
+    <div id="RIGHT">
+      $($LOGIN && add_comment $info)
+      $(list_comments $info)
+    </div>
+WikiEND