changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > werc / changeset: Upgrade and cleanup dirdir, move to app framework, and its implementation more elegant and reliable.

changeset 366: a5aa90ad7906
parent 365: 9d9ff05071bb
child 367: f5ec36e93858
author: uriel@engel.se.cat-v.org
date: Mon, 26 Jan 2009 03:37:47 +0100
files: apps/dirdir/app.rc apps/dirdir/edit.tpl
description: Upgrade and cleanup dirdir, move to app framework, and its implementation more elegant and reliable.
     1.1--- a/apps/dirdir/app.rc	Sun Jan 25 16:54:03 2009 +0100
     1.2+++ b/apps/dirdir/app.rc	Mon Jan 26 03:37:47 2009 +0100
     1.3@@ -1,14 +1,24 @@
     1.4 fn dirdir_init {
     1.5-    if(! ~ $#enable_wiki 0 && test -f $local_path.md && check_user $wiki_editors_group) 
     1.6-        ll_add handlers_bar_left  dirdir_controls
     1.7+    if(! ~ $#enable_wiki 0 &&  check_user $wiki_editors_group admin) {
     1.8+        if(test -f $local_path.md)
     1.9+            ll_add handlers_bar_left  dirdir_controls
    1.10+
    1.11+        if(~ $req_path */dirdir_edit && ~ $REQUEST_METHOD POST) {
    1.12+            get_post_args edit_wiki_page edit_text edit_preview edit_save
    1.13+            # XXX SECURITY! should sanitize input and ensure we only edit files 
    1.14+            # we are allowed. This is a start, but should be way more careful
    1.15+            edit_file = `{echo $sitedir/$edit_wiki_page|sed -e 's/\.\.*/./g' -e 's,/$,/index,' | sed 's/$/.md/'}
    1.16+            tpl=`{get_lib_file dirdir/edit.tpl apps/dirdir/edit.tpl}
    1.17+            handler_body_main=(tpl_handler $tpl)
    1.18+        }
    1.19+
    1.20+    }
    1.21 }
    1.22 
    1.23 fn dirdir_controls {
    1.24     # Display 'Edit', 'History', etc, links
    1.25-    echo '<form action="/_apps/dirdir/edit" method="POST">'
    1.26+    echo '<form action="dirdir_edit" method="POST">'
    1.27     echo '<input type="hidden" name="edit_wiki_page" value="'^$req_path^'" />'
    1.28     echo '<input type="submit" name="" value="Edit page" />'
    1.29     echo '</form>'
    1.30-
    1.31-
    1.32 }
     2.1--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2+++ b/apps/dirdir/edit.tpl	Mon Jan 26 03:37:47 2009 +0100
     2.3@@ -0,0 +1,46 @@
     2.4+% if (~ $"edit_save '') {
     2.5+<div>
     2.6+    <h1>Editing %($edit_wiki_page%)</h1>
     2.7+    <br />
     2.8+    <form action="dirdir_edit" method="post">
     2.9+        <input type="hidden" name="edit_wiki_page" value="%($edit_wiki_page%)"
    2.10+        <textarea name="edit_text" id="edit_text" cols="80" rows="43">%{
    2.11+
    2.12+            if(~ $#edit_text 0 && test -f $edit_file)
    2.13+                cat $edit_file | escape_html
    2.14+            if not
    2.15+                echo $edit_text | escape_html
    2.16+
    2.17+        %}</textarea>
    2.18+        <br />
    2.19+        <input type="submit" name="edit_save" value="Save"/>
    2.20+        <input type="submit" name="edit_preview" value="Preview" />
    2.21+        <small>DirDir documents are written using <a href="http://daringfireball.net/projects/markdown/syntax">Markdown syntax</a>.</small>
    2.22+    </form>
    2.23+</div>
    2.24+% }
    2.25+
    2.26+% if(! ~ $"edit_preview '') {
    2.27+            <H2>Preview:</H2>
    2.28+            <div id="preview">
    2.29+%               echo $edit_text | $formatter
    2.30+            </div>
    2.31+            <hr /><hr />
    2.32+% }
    2.33+% if not if(! ~ $"edit_save '') {
    2.34+%{
    2.35+    dirdir_dir = $edit_file^'_werc/dirdir/'
    2.36+
    2.37+    if(! test -d  $dirdir_dir)
    2.38+        mkdir -p $dirdir_dir
    2.39+
    2.40+    dirdir_verdir = $dirdir_dir/`{date -n}^/
    2.41+    mkdir $dirdir_verdir
    2.42+
    2.43+    echo $loggin_user > $dirdir_verdir/author
    2.44+    echo $edit_text > $dirdir_verdir/data 
    2.45+    echo $edit_text > $edit_file
    2.46+%}
    2.47+<h1>Saved <a href="%($edit_wiki_page%)">%($edit_wiki_page%)!</a></h1>
    2.48+% }
    2.49+