]> git.plutz.net Git - busy/blobdiff - templates/Wiki_show.page
upgraded to fit new shcgi revision, slightly better input validation, switched to...
[busy] / templates / Wiki_show.page
index 87e848f805e9d7b588240d1e5c415f3c031dd682..fc3fd26d5fdb8b8fd49f511d01bf0a689b40e370 100755 (executable)
@@ -3,8 +3,7 @@
 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
+  for each in $(ls -r 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
@@ -15,23 +14,28 @@ list_comments() {
 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
+       <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
 }
 
+wikitext="$(_wiki Wiki/"${info}${rev}")"
+wikitoc="$(echo -E "$wikitext" \
+           | 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'
+          )"
+
 cat <<WikiEND
     <div id="LEFT">
-      <form method="GET" action="/${SCRIPTNAME}" accept-charset="utf-8">
+      <form method="GET" action="./" 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">
@@ -46,30 +50,22 @@ cat <<WikiEND
         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."
+          [ -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>"
+         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)
+        ${wikitoc}
       </div>
       <hr>
     </div>
     <div id="MAIN">
       <div class="wiki"><div class="wikitext">
-        <h1>$title</h1>
-        $(_wiki Wiki/"${info}${rev}")
+        <h1 class="wikihead">$title</h1>
+        ${wikitext}
       </div></div>
     </div>