Пример #1
0
    def GET(self, req_path):
        assert req_path in g_special_paths

        inputs = web.input()
        offset = int(inputs.get("offset", 0))
        limit = int(inputs.get("limit", conf.page_limit))

        if req_path == "~recent":
            show_full_path = int(web.cookies().get("zw_show_full_path", conf.show_full_path))
            return wp_get_recent_changes_from_cache(show_full_path = show_full_path, limit = limit, offset = offset)

        elif req_path == "~all":
            show_full_path = int(web.cookies().get("zw_show_full_path", conf.show_full_path))
            return wp_get_all_pages(show_full_path = show_full_path, limit = limit, offset = offset)
            
        elif req_path == "~settings":
            return wp_view_settings()

        elif req_path == "~stat":
            return wp_stat()

        elif req_path == "~new":
            return wp_new()

        else:
            return web.BadRequest()
Пример #2
0
def wp_view_settings():
    show_full_path = web.cookies().get("zw_show_full_path", conf.show_full_path)
    show_full_path = int(show_full_path)

    auto_toc = web.cookies().get("zw_auto_toc", conf.auto_toc)
    auto_toc = int(auto_toc)

    highlight = web.cookies().get("zw_highlight", conf.highlight)
    highlight = int(highlight)

    return tpl_render.view_settings(show_full_path = show_full_path,
                                    auto_toc = auto_toc,
                                    highlight = highlight,
                                    static_files = g_global_static_files)
Пример #3
0
    def GET(self, req_path):
        req_path = cgi.escape(req_path)
        inputs = web.input()
        action = inputs.get("action", "read")

        assert action in ("edit", "read", "rename", "delete", "source")

        show_full_path = int(web.cookies().get("zw_show_full_path", conf.show_full_path))
        auto_toc = int(web.cookies().get("zw_auto_toc", conf.auto_toc))
        highlight = int(web.cookies().get("zw_highlight", conf.highlight))

        if action == "read":
            if req_path == "":
                req_path = "home"

            return wp_read(req_path = req_path,
                           show_full_path = show_full_path,
                           auto_toc = auto_toc,
                           highlight = highlight,
                           pages_path = conf.pages_path,
                           show_quick_links = conf.show_quick_links,
                           show_source_button = conf.show_source_button,
                           show_home_link = conf.show_home_link,
                           home_link_name = conf.home_link_name)

        elif action == "edit":
            return wp_edit(req_path)

        elif action == "rename":
            return wp_rename(req_path)

        elif action == "delete":
            return wp_delete(req_path)

        elif action == "source":
            return wp_source(req_path)

        raise web.BadRequest()
Пример #4
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()