Exemple #1
0
def wp_read(req_path, show_full_path, auto_toc, highlight, pages_path,
            show_quick_links, show_source_button):
    full_path = req_path_to_full_path(req_path)

    if conf.button_mode_path:
        buf = commons.text_path2btns_path("/%s" % req_path)
        button_path = commons.md2html(buf)
    else:
        button_path = None

    if os.path.isfile(full_path):
        work_full_path = os.path.dirname(full_path)
        static_file_prefix = os.path.join("/static/pages", os.path.dirname(req_path))

        content = commons.cat(full_path)
        content = commons.strip_bom(content)

        HOME_PAGE = "home"
        if req_path == HOME_PAGE:
            button_path = None
        else:
            show_quick_links = False

    elif os.path.isdir(full_path):
        work_full_path = full_path
        static_file_prefix = os.path.join("/static/pages", req_path)

        buf1 = get_dot_idx_content_by_full_path(full_path) or ""
        buf2 = get_page_file_list_by_req_path(req_path)

        if buf2:
            buf2 = sequence_to_unorder_list(buf2.split("\n"), show_full_path = show_full_path)
        else:
            buf2 = ""

        content = buf1 + "\n" + "----" + "\n" + buf2

    else:
        if req_path == "home" and (not os.path.exists(full_path)):
            return web.seeother("~all")
        else:
            return web.seeother("/%s?action=edit" % req_path)

    content = zw_macro2md(text = content, show_full_path = show_full_path, pages_path = pages_path)

    content = commons.md2html(text = content,
                              work_full_path = work_full_path,
                              static_file_prefix = static_file_prefix)

    static_files = get_the_same_folders_cssjs_files(req_path)
    if not static_files:
        static_files = get_global_static_files(auto_toc = auto_toc, highlight = highlight) + "\n"

    return tpl_render.canvas(conf = conf,
                           req_path = req_path,
                           button_path = button_path,
                           content = content,
                           static_files = static_files,
                           show_quick_links = show_quick_links,
                           show_source_button = show_source_button)
Exemple #2
0
def wp_get_all_pages(show_full_path, limit, offset):
    buf = get_all_pages_list_from_cache()
    all_lines = buf.split()
    total_lines = len(all_lines)

    title = "All Pages List (%d/%d)" % (offset, total_lines / limit)

    start = offset * limit
    end = start + limit
    lines = all_lines[start : end]

    buf = sequence_to_unorder_list(lines, show_full_path = show_full_path)
    content = commons.md2html(text = buf, work_full_path = conf.pages_path)

    paginator = commons.Paginator()
    paginator.total = total_lines
    paginator.current_offset = offset
    paginator.limit = limit
    paginator.url = "/~all"

    return tpl_render.canvas(conf = conf,
                             button_path = title,
                             content = content,
                             static_files = g_global_static_files,
                             paginator = paginator)
Exemple #3
0
def wp_edit(req_path):
    full_path = req_path_to_full_path(req_path)

    if conf.button_mode_path:        
        buf = commons.text_path2button_path("/%s" % req_path)
        title = commons.md2html(buf)
    else:
        title = req_path        

    create_new = False
    
    if os.path.isfile(full_path):
        content = commons.cat(full_path)

    elif os.path.isdir(full_path):
        content = get_dot_idx_content_by_full_path(full_path)

    elif not os.path.exists(full_path):
        create_new = True
        content = ""

    else:
        raise Exception("invalid path '%s'" % req_path)

    static_files = get_global_static_files(auto_toc = False,
                            highlight = False,
                            reader_mode = False)

    return tpl_render.editor(req_path, title, content, create_new = create_new, static_files = static_files)
Exemple #4
0
    def POST(self, req_path):
        assert req_path in g_special_paths

        inputs = web.input()
            
        if req_path == "~search":
            keywords = inputs.get("k")
            keywords = web.utils.safestr(keywords)
            if keywords:
                arg = web.cookies().get("zw_show_full_path") or conf.show_full_path
                show_full_path = int(arg)

                content = search_by_filename_and_file_content(keywords, show_full_path = show_full_path)
            else:
                content = None

            if content:
                content = commons.md2html(content)
            else:
                content = "matched not found"

            return tpl_render.search(keywords = keywords, content = content, static_files = g_global_static_files)

        elif req_path == "~settings":
            show_full_path = inputs.get("show_full_path")
            auto_toc = inputs.get("auto_toc")
            highlight = inputs.get("highlight")

            if show_full_path == "on":
                show_full_path = 1
            else:
                show_full_path = 0
            web.setcookie(name = "zw_show_full_path", value = show_full_path, expires = 31536000)

            if auto_toc == "on":
                auto_toc = 1
            else:
                auto_toc = 0
            web.setcookie(name = "zw_auto_toc", value = auto_toc, expires = 31536000)

            if highlight == "on":
                highlight = 1
            else:
                highlight = 0
            web.setcookie(name = "zw_highlight", value = highlight, expires = 31536000)


            latest_req_path = web.cookies().get("zw_latest_req_path")

            if latest_req_path and (latest_req_path not in g_redirect_paths) and latest_req_path != "/":
                web.setcookie(name = "zw_latest_req_path", value = "", expires = -1)
                latest_req_path = "/" + latest_req_path
            else:
                latest_req_path = "/"

            web.seeother(latest_req_path)
        else:
            raise web.NotFound()
Exemple #5
0
def wp_stat():
    stat_tpl = """# Stat

|| _ || _ ||
| Wiki pages | %d |
| Folder | %d |

"""
    page_count = commons.run(" cd %s ; find . -type f -name '*.md' | wc -l " % conf.pages_path) or 0
    folder_count = commons.run(" cd %s ; find . -type d | wc -l " % conf.pages_path) or 0
    text = stat_tpl % (int(page_count), int(folder_count))
    content = commons.md2html(text)

    return tpl_render.canvas(conf,
                             button_path = None,
                             content = content,
                             req_path = None,
                             static_files = g_global_static_files,
                             show_quick_links = False)