shithub: werc

Download patch

ref: 352340bf902a356a4d5d857538d78b5a6ee8b403
parent: 23283f75388d0b2e979bf4de5dc0495ed7484b48
parent: 705e286c8abfa96ac9243ce61bd257a07f9ff062
author: sl <uriel@engel.se.cat-v.org>
date: Fri Feb 27 17:39:19 EST 2009

Merge.

--- a/apps/bridge/app.rc
+++ b/apps/bridge/app.rc
@@ -11,23 +11,27 @@
 }
 
 fn bridge_init {
-    if(~ $#enable_comments 1) {
-    
+    if(~ $#enable_comments 1 && ! ~ `{ls $local_path.$comment_file_types >[2]/dev/null|wc -l} 0) {
+
         comments_dir=$sitedir$req_path'_werc/comments'
-        if(test -d $comments_dir)
+        if(~ $REQUEST_METHOD GET && test -d $comments_dir)
             ll_add handlers_body_foot template apps/bridge/comments_list.tpl
 
-        if({ check_user $groups_allowed_comments || {~ $#logged_user 0 && ! ~ $#allow_new_user_comments 0} } && ! ~ `{ls $local_path.$comment_file_types >[2]/dev/null|wc -l} 0) {
-            ll_add handlers_body_foot template apps/bridge/foot.tpl
+        if(check_user $groups_allowed_comments || {~ $#logged_user 0 && ! ~ $#allow_new_user_comments 0}) {
 
-            if(~ $REQUEST_METHOD POST && mk_new_comment $comments_dir)
-                post_redirect $base_url^$post_arg_document_uri
-            if not
-                saved_comment_text=$post_arg_comment_text
+            if(~ $#post_arg_bridge_post 1) {
+                ll_add handlers_body_foot template apps/bridge/foot.tpl
+
+                if(mk_new_comment $comments_dir)
+                    post_redirect $base_url^$req_path
+                if not
+                    saved_comment_text=$post_arg_comment_text
+            }
+            if not if(~ $REQUEST_METHOD GET)
+                ll_add handlers_body_foot template apps/bridge/foot.tpl
         }
-        if not
+        if not if(~ $REQUEST_METHOD GET)
             ll_add handlers_body_foot echo '<hr /><p>To post a comment you need to <a href="/_users/login">login</a> first.'
-        
     }
 }
 
--- a/apps/bridge/foot.tpl
+++ b/apps/bridge/foot.tpl
@@ -1,12 +1,10 @@
 <hr />
 
 % notices_handler
-% # XXX should post to bridge_post or similar
 <form action="" method="post">
     <textarea name="comment_text" id="comment_text" cols="80" rows="16">%($"saved_comment_text%)</textarea>
     <br />
-    <input type="hidden" name="document_uri" value="%($req_path%)" />
-    <input type="submit" name="post_comment" value="Post a comment" />
+    <input type="submit" name="bridge_post" value="Post a comment" />
 
 % if(~ $#logged_user 0 && ! ~ $#allow_new_user_comments 0) {
     <label>New user name:
--- a/apps/dirdir/app.rc
+++ b/apps/dirdir/app.rc
@@ -1,31 +1,31 @@
 fn conf_enable_wiki {
     enable_wiki=yes
-    wiki_editors_group=$* 
+    wiki_editors_groups=$* 
     conf_enable_app dirdir
 }
 
-
 fn dirdir_init {
-    if(! ~ $#enable_wiki 0 && check_user $wiki_editors_group) {
-        if(test -f $local_path.md)
-            ll_add handlers_bar_left  dirdir_controls
+    if(! ~ $#enable_wiki 0 && check_user $wiki_editors_groups && test -f $local_path.md) {
+        dirdir_file=$local_path.md
+        dirdir_dir=$dirdir_file^'_werc/dirdir/'
+            
+        if(~ $#post_arg_dirdir_save 1 && ! ~ $"post_arg_edit_text '') {
 
-        if(~ $req_path */dirdir_edit && ~ $REQUEST_METHOD POST) {
-            get_post_args edit_wiki_page edit_text edit_preview edit_save
-            # XXX SECURITY! should sanitize input and ensure we only edit files 
-            # we are allowed. This is a start, but should be way more careful
-            edit_file = `{echo $sitedir/$edit_wiki_page|sed -e 's/\.\.*/./g' -e 's,/$,/index,' | sed 's/$/.md/'}
-            tpl=`{get_lib_file dirdir/edit.tpl apps/dirdir/edit.tpl}
-            handler_body_main=(tpl_handler $tpl)
+            dirdir_verdir=$dirdir_dir/^`{date -n}^/
+            mkdir -p $dirdir_verdir
+
+            # XXX Use a tmp file and  mv(1) to ensure updates are atomic?
+            echo $logged_user > $dirdir_verdir/author
+            echo $post_arg_edit_text > $dirdir_verdir/data 
+            echo $post_arg_edit_text > $dirdir_file
+
+            post_redirect $base_url^$req_path
+            #notify_notes='Saved <a href="'$"req_path'">'$"req_path'</a>!'
         }
+        if not if(~ $#post_arg_dirdir_edit 1 || ~ $#post_arg_dirdir_preview 1)
+            handler_body_main=(tpl_handler `{get_lib_file dirdir/edit.tpl apps/dirdir/edit.tpl} )
+        if not if(! ~ $REQUEST_METHOD POST)
+            ll_add handlers_bar_left tpl_handler apps/dirdir/sidebar_controls.tpl
 
     }
-}
-
-fn dirdir_controls {
-    # Display 'Edit', 'History', etc, links
-    echo '<form action="dirdir_edit" method="POST">'
-    echo '<input type="hidden" name="edit_wiki_page" value="'^$req_path^'" />'
-    echo '<input type="submit" name="" value="Edit page" />'
-    echo '</form>'
 }
--- a/apps/dirdir/edit.tpl
+++ b/apps/dirdir/edit.tpl
@@ -1,46 +1,25 @@
-% if(~ $"edit_save '') {
 <div>
-    <h1>Editing %($edit_wiki_page%)</h1>
+    <h1>Editing: <a href="%($req_path%)">%($req_path%)</a></h1>
     <br />
-    <form action="dirdir_edit" method="post">
-        <input type="hidden" name="edit_wiki_page" value="%($edit_wiki_page%)">
+    <form action="" method="post">
         <textarea name="edit_text" id="edit_text" cols="80" rows="43">%{
 # FIXME Extra trailing new lines get added to the content somehow, should avoid it.
-            if(~ $#edit_text 0 && test -f $edit_file)
-                cat $edit_file | escape_html
+            if(~ $#post_arg_edit_text 0 && test -f $dirdir_file)
+                cat $dirdir_file | escape_html
             if not
-                echo -n $edit_text | escape_html
+                echo -n $post_arg_edit_text | escape_html
 
         %}</textarea>
         <br />
-        <input type="submit" name="edit_save" value="Save"/>
-        <input type="submit" name="edit_preview" value="Preview" />
+        <input type="submit" name="dirdir_save" value="Save"/>
+        <input type="submit" name="dirdir_preview" value="Preview" />
         <small>DirDir documents are written using <a href="http://daringfireball.net/projects/markdown/syntax">Markdown syntax</a>.</small>
     </form>
 </div>
-% }
 
-% if(! ~ $"edit_preview '') {
+% if(! ~ $"post_arg_dirdir_preview '') {
             <H2>Preview:</H2>
             <div id="preview">
-%               echo $edit_text | $formatter
+%               echo $post_arg_edit_text | $formatter
             </div>
-            <hr /><hr />
 % }
-% if not if(! ~ $"edit_save '') {
-%{
-    dirdir_dir = $edit_file^'_werc/dirdir/'
-
-    if(! test -d  $dirdir_dir)
-        mkdir -p $dirdir_dir
-
-    dirdir_verdir = $dirdir_dir/`{date -n}^/
-    mkdir $dirdir_verdir
-
-    echo $logged_user > $dirdir_verdir/author
-    echo $edit_text > $dirdir_verdir/data 
-    echo $edit_text > $edit_file
-%}
-<h1>Saved <a href="%($edit_wiki_page%)">%($edit_wiki_page%)</a>!</h1>
-% }
-
--- /dev/null
+++ b/apps/dirdir/sidebar_controls.tpl
@@ -1,0 +1,3 @@
+<form action="" method="POST">
+<input type="submit" name="dirdir_edit" value="Edit page" />
+</form>
--- a/sites/werc.cat-v.org/_werc/config
+++ b/sites/werc.cat-v.org/_werc/config
@@ -2,6 +2,6 @@
 siteTitle='werc'
 siteSubTitle='Bringing minimalism and sanity to the web'
 conf_enable_comments
-conf_enable_wiki admin
+conf_enable_wiki
 
 ll_add handlers_body_head echo '<div style="text-align:right"><script type="text/javascript" src="http://www.reddit.com/r/programming/button.js?t=1"></script></div>'