Пример #1
0
def wp_delete(req_path):
    full_path = req_path_to_full_path(req_path)

    delete_page_file_by_full_path(full_path)
    update_recent_change_cache()
    update_all_pages_list_cache()    

    web.seeother("/")
    return
Пример #2
0
    def POST(self, req_path):
        req_path = cgi.escape(req_path)
        inputs = web.input()
        action = inputs.get("action")

        if action and action not in ("edit", "rename"):
            raise web.BadRequest()

        content = inputs.get("content")
        content = web.utils.safestr(content)

        # NOTICE: if req_path == `users/`, full_path will be `/path/to/users/`,
        # parent will be `/path/to/users`.            
        full_path = req_path_to_full_path(req_path)

        parent = os.path.dirname(full_path)
        if not os.path.exists(parent):
            os.makedirs(parent)

        if action == "edit":
            update_page_by_req_path(req_path = req_path, content = content)

            web.seeother("/%s" % req_path)

        elif action == "rename":
            new_path = inputs.get("new_path")
            if not new_path:
                raise web.BadRequest()

            old_full_path = req_path_to_full_path(req_path)
            if os.path.isfile(old_full_path):
                new_full_path = req_path_to_full_path(new_path)
            elif os.path.isdir(old_full_path):
                new_full_path = os.path.join(conf.pages_path, new_path)
            else:
                raise Exception("unknow path")

            if os.path.exists(new_full_path):
                err_info = "Warning: The page foobar already exists."
                return tpl_render.rename(req_path, err_info, static_files = g_global_static_files)

            parent = os.path.dirname(new_full_path)
            if not os.path.exists(parent):
                os.makedirs(parent)

            shutil.move(old_full_path, new_full_path)

            update_all_pages_list_cache()
            update_recent_change_cache()

            if os.path.isfile(new_full_path):
                web.seeother("/%s" % new_path)
            elif os.path.isdir(new_full_path):
                web.seeother("/%s/" % new_path)

            return

        url = os.path.join("/", req_path)
        web.redirect(url)
Пример #3
0
    def POST(self, req_path):
        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)
        elif req_path == "~new":
            real_req_path = inputs.get("path")
            fixed_req_path = web.lstrips(real_req_path, "/")

            content = inputs.get("content")
            content = web.utils.safestr(content)
        
            update_page_by_req_path(req_path = fixed_req_path, content = content)

            update_recent_change_cache()
            update_all_pages_list_cache()    

            web.seeother(real_req_path)
        else:
            raise web.NotFound()
Пример #4
0
def wp_read(req_path, show_full_path, auto_toc, highlight, pages_path,
            show_quick_links,
            show_source_button,
            show_home_link,
            home_link_name):
    full_path = req_path_to_full_path(req_path)

    if conf.button_mode_path:
        buf = commons.text_path2button_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,
                           show_home_link = show_home_link,
                           home_link_name = home_link_name)