+++ /dev/null
-#!/bin/zsh
-
-info="$(egrep -o '(^|&)(i=)[0-9]{10}_[0-9]{3}(&|$)' <<<"${QUERY_STRING}" |tr -d '&i=')"
-edit="$(egrep -o '(^|&)(e=)[0-9]{10}_[0-9]{3}(&|$)' <<<"${QUERY_STRING}" |tr -d '&e=')"
-rev="$(egrep -o '(^|&)(r=)[0-9]{10}(&|$)' <<<"${QUERY_STRING}" |tr -d '&r=')"
-search="$(egrep -o '(^|&)(s=).+(&|$)' <<<"${QUERY_STRING}" |sed -r 's:^&?s=::;s:\+: :g;s:%:\\x:g')"
-search="$(echo -e "${search}" |sed 's:\t: :g;s:\r::g;s:\\:\\\\:g' |head -n1)"
-
-[ -n "$rev" ] && rev=".$rev"
-if [ -n "$search" ]; then
- info=''
- edit=''
- rev=''
-fi
-
-lock="Wiki/$info.lock"
-[ -r "$lock" -o -n "$lock" ] && if [ "$(cut -d: -f2 "$lock")" -lt "$(date +%s)" ]; then
- rm "$lock"
- lock=''
-else
- lock="$(cut -d: -f1 "$lock")"
-fi
-
-if [ -n "$edit" -a -r "Wiki/${edit}${rev}" ]; then
- title="$(egrep -x 'title=.+' "Wiki/$edit.meta" |cut -d= -f2- || echo '(Untitled)')"
- cat <<WikiEND
- <form class="edit" action="write/$($LOGIN && echo user_)wikiedit.cgi?i=$edit" method="post" accept-charset="UTF-8">
- <div id="LEFT">
- Editing <b>$title</b><br>
- <input type="submit" value="Submit">
- <input type="submit" name="cancel" value="Cancel">
- <hr>
- </div>
- <div id="MAIN">
- <div class="wiki">
- <h1>$title</h1>
- <textarea name="page" rows=30 cols=40>$(cat "Wiki/${edit}${rev}")</textarea>
- </div>
- </div>
- </form>
- <div id="RIGHT">
- $(stat -c '' Wiki/${edit}.comment.<0000000000-9999999999>_<000-999> && for each in $(ls -c Wiki/${edit}.comment.<0000000000-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)
- </div>
-WikiEND
-
-elif [ -n "$info" -a -r "Wiki/${info}${rev}" ]; then
- title="$(egrep -x 'title=.+' "Wiki/$info.meta" |cut -d= -f2- || echo '(Untitled)')"
-
- 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&i=$info&r=$revi'>$rno</a>"
- rno=$(($rno+1))
- done) <a class='rev' href='?p=Wiki&i=$info'>Latest</a><br>
- <hr>
- $($LOGIN && if [ -z "$lock" ]; then
- [ -z "$rev" ] && echo "<a class='function' href='write/$($LOGIN && echo user_)lock.cgi?p=Wiki&e=$info'>edit this page</a>"
- [ -n "$rev" ] && echo "Click <a class='function' href='write/$($LOGIN && echo user_)lock.cgi?p=Wiki&e=${info}&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='write/$($LOGIN && echo user_)lock.cgi?p=Wiki&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,^ *!!! *,,;s,[^a-zA-Z0-9],.,g' <<<"$line")'>$(sed 's,^ *!!!,,' <<<"$line")</a><br>"
- elif (egrep -q '^ *!!' <<<"$line"); then
- echo "<a class='i1' href='#$(sed 's,^ *!! *,,;s,[^a-zA-Z0-9],.,g' <<<"$line")'>$(sed 's,^ *!!,,' <<<"$line")</a><br>"
- elif (egrep -q '^ *!' <<<"$line"); then
- echo "<a class='i0' href='#$(sed 's,^ *! *,,;s,[^a-zA-Z0-9],.,g' <<<"$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>
-WikiEND
-
- echo '<div id="RIGHT">'
-$LOGIN && 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="/write/$($LOGIN && echo user_)wikimeta.cgi?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
- stat -c '' Wiki/${info}.comment.<0000000000-9999999999>_<000-999> && for each in $(ls -c Wiki/${info}.comment.<0000000000-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
- echo '</div>'
-
-elif [ -z "$info" ]; then
- 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>
-WikiEND
- if [ -n "$search" ]; then
- echo "<h1>Wiki search results for: $search</h1>"
- for each in $(grep -ile "$search" Wiki/<0000000000-9999999999>_<000-999>); do
- echo "<div class='search'><a href='?p=Wiki&i=${each:t}'><h2>$(grep '^title=' "$each.meta" |cut -d= -f2-)</h2></a>"
- grep -C1 -ie "$search" "$each" |sed "s:$search:<b>&</b>:g;s:$:<br>:g"
- echo '</div>'
- done
- echo '<hr>'
- fi
- echo '</div><div id="RIGHT">'
- $LOGIN && cat <<WikiEND
- <a id='addp_button' class='function' href='#' onclick='javascript:show_screen("add_page");hide_screen("addp_button");'>Add a new Page</a>
- <div id="add_page" style="display: none;">
- <form action="/write/$($LOGIN && echo user_)wikimeta.cgi" method="post" accept-charset="UTF-8">
- <br><b>Title:</b><br>
- <input type="text" name="title" placeholder="Fill in a title"><br>
- <b>Description:</b><br>
- <textarea name="desc" rows="6" ></textarea><br>
- <input type="submit" value="Submit">
- <a class="function" href="#" onclick="javascript:hide_screen('add_page');show_screen('addp_button');">Cancel</a>
- </form>
- </div>
-WikiEND
- echo '</div><div id="MAIN">'
-
- stat -c '' Wiki/<0000000000-9999999999>_<000-999> && for each in Wiki/<0000000000-9999999999>_<000-999>; do
- info=$(sed 's,Wiki/,,' <<<"$each")
- title="$(egrep -x 'title=.+' "$each.meta" |cut -d= -f2- || echo '(Untitled)')"
- description="$(egrep -x 'description=.+' "$each.meta" |cut -d= -f2-)"
- owner="$(egrep -x 'owner=.+' "$each.meta" |cut -d= -f2-)"
-
- cat <<WikiEND
- <div class="article">
- <div id="display_$info">
- <a name="$info" href="/?p=Wiki&i=$info"><h1>$title</h1></a>
- $description<br><br>
- <a class="function" href="/?p=Wiki&i=$info">View</a>
- $($ACL_WIKIEDIT && echo "<a class='function' href='#' onclick=\"javascript:show_screen('change_$info');hide_screen('display_$info');\">Change Info</a>")
- </div>
-WikiEND
- $ACL_WIKIEDIT && cat <<WikiEND
- <div id="change_$info" style="display: none;">
- <form action="/write/$($LOGIN && echo user_)wikimeta.cgi?i=$info" method="post" accept-charset="UTF-8">
- <b>Title:</b> <input type="text" name="title" value="$title"><br>
- <b>Description:</b><br>
- <textarea name="desc" rows="6" style="width:100%;">$description</textarea><br>
- <input type="submit" value="Submit">
- <a class="function" href="#" onclick="javascript:hide_screen('change_$info');show_screen('display_$info');">Cancel</a>
- </form>
- </div>
-WikiEND
- echo '</div>'
- done
- echo '</div>'
-fi