From d21e6caeb733ee8638f9f637f62b0d6f70e7e7df Mon Sep 17 00:00:00 2001 From: uriel Date: Wed, 4 Mar 2009 03:12:54 +0100 Subject: [PATCH 1/2] Implement file creation for dirdir. --- apps/dirdir/app.rc | 50 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/apps/dirdir/app.rc b/apps/dirdir/app.rc index 04d7e73..fe579e6 100644 --- a/apps/dirdir/app.rc +++ b/apps/dirdir/app.rc @@ -5,27 +5,47 @@ fn conf_enable_wiki { } fn dirdir_init { - if(! ~ $#enable_wiki 0 && check_user $wiki_editors_groups && test -f $local_path.md) { + if(! ~ $#enable_wiki 0 && check_user $wiki_editors_groups) { dirdir_file=$local_path.md dirdir_dir=$dirdir_file^'_werc/dirdir/' - if(~ $#post_arg_dirdir_save 1 && ! ~ $"post_arg_edit_text '') { + if(test -f $local_path.md) { + if(~ $#post_arg_dirdir_save 1 && ! ~ $"post_arg_edit_text '') + save_page - dirdir_verdir=$dirdir_dir/^`{date -n}^/ - mkdir -p $dirdir_verdir + if not if(~ 1 $#post_arg_dirdir_edit $#post_arg_dirdir_preview) + handler_body_main=(tpl_handler \ + `{get_lib_file dirdir/edit.tpl apps/dirdir/edit.tpl}) - # 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 '$"req_path'!' + if not if(! ~ $REQUEST_METHOD POST) + ll_add handlers_bar_left tpl_handler \ + apps/dirdir/sidebar_controls.tpl } - 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 + + if not if(~ 1 $#post_arg_dirdir_edit) + handler_body_main=(tpl_handler \ + `{get_lib_file dirdir/edit.tpl apps/dirdir/edit.tpl}) + + if not if(~ 1 $#post_arg_dirdir_save) { + mkdir -p `{basename -d $local_path} + save_page + } + if not + ll_add handlers_bar_left tpl_handler \ + apps/dirdir/sidebar_controls.tpl } } + +fn save_page { + 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 '$"req_path'!' +} From 8f3cbc3b0dfbf7b511e72b396660c0f6def7fc38 Mon Sep 17 00:00:00 2001 From: uriel Date: Wed, 4 Mar 2009 09:05:40 +0100 Subject: [PATCH 2/2] Only display Edit button when no other handler_body_main has been set (ie., if file really doesn't exist). --- apps/dirdir/app.rc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/dirdir/app.rc b/apps/dirdir/app.rc index fe579e6..a82872b 100644 --- a/apps/dirdir/app.rc +++ b/apps/dirdir/app.rc @@ -30,7 +30,7 @@ fn dirdir_init { mkdir -p `{basename -d $local_path} save_page } - if not + if not if(~ $"handler_body_main '') ll_add handlers_bar_left tpl_handler \ apps/dirdir/sidebar_controls.tpl