shithub: werc

ref: 11f63ba96e93bf515b2dadef5872b2574dab49e6
dir: /apps/dirdir/app.rc/

View raw version
fn conf_enable_wiki {
    enable_wiki=yes
    wiki_editors_groups=$* 
    conf_enable_app dirdir
}

fn dirdir_init {
    if(! ~ $#enable_wiki 0 && check_user $wiki_editors_groups) {
        dirdir_file=$local_path.md
        dirdir_dir=$dirdir_file^'_werc/dirdir/'
 
        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})

        if not if(! ~ '' $"post_arg_dirdir_save $"post_arg_edit_text)
            save_page

        if not if(~ $"handler_body_main  '' || {~ $REQUEST_METHOD GET && test -f $local_path.md})
            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
    umask 002

    # 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>!'
}