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()
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)
def _check_acl(req_obj, req_path): inputs = web.input() action = inputs.get("action", "read") if conf.readonly: if action not in ("read", "source"): return False return True
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()
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()