Big overhaul of dirdir rewriting most code to be much simpler, reliable and efficient.

Now we have a wiki engine in ~20 lines of code!
This commit is contained in:
Uriel 2009-02-26 11:50:18 +01:00
parent b00107e3b8
commit a3c2c71275
3 changed files with 32 additions and 50 deletions

View file

@ -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>'
}