def edit(): """Wiki page editor.""" title = request.args.get("name", "") body = "" history = True # Update History box is always checked by default note = request.args.get("note", "") # Editing an existing page? page = Wiki.get_page(title) if page: head = page["revisions"][0] body = head["body"] if request.method == "POST": # Submitting the form. action = request.form.get("action", "preview") title = request.form.get("name", "") body = request.form.get("body", "") history = request.form.get("history", "false") == "true" note = request.form.get("note", "") if action == "preview": # Just previewing it. g.info["preview"] = True # Render markdown g.info["rendered_body"] = Wiki.render_page(body) # Render emoticons. g.info["rendered_body"] = Emoticons.render(g.info["rendered_body"]) elif action == "publish": # Publishing! Validate inputs. invalid = False if len(title) == 0: invalid = True flash("You must have a page title.") if len(body) == 0: invalid = True flash("You must have a page body.") if not invalid: # Update the page. Wiki.edit_page( author=g.info["session"]["uid"], name=title, body=body, note=note, history=history, ) return redirect( url_for("wiki.view_page", name=Wiki.name_to_url(title))) g.info["title"] = title g.info["body"] = body g.info["note"] = note g.info["history"] = history return template("wiki/edit.html")
def edit(): """Wiki page editor.""" title = request.args.get("name", "") body = "" history = True # Update History box is always checked by default note = request.args.get("note", "") # Editing an existing page? page = Wiki.get_page(title) if page: head = page["revisions"][0] body = head["body"] if request.method == "POST": # Submitting the form. action = request.form.get("action", "preview") title = request.form.get("name", "") body = request.form.get("body", "") history = request.form.get("history", "false") == "true" note = request.form.get("note", "") if action == "preview": # Just previewing it. g.info["preview"] = True # Render markdown g.info["rendered_body"] = Wiki.render_page(body) # Render emoticons. g.info["rendered_body"] = Emoticons.render(g.info["rendered_body"]) elif action == "publish": # Publishing! Validate inputs. invalid = False if len(title) == 0: invalid = True flash("You must have a page title.") if len(body) == 0: invalid = True flash("You must have a page body.") if not invalid: # Update the page. Wiki.edit_page(author=g.info["session"]["uid"], name=title, body=body, note=note, history=history) return redirect(url_for("wiki.view_page", name=Wiki.name_to_url(title))) g.info["title"] = title g.info["body"] = body g.info["note"] = note g.info["history"] = history return template("wiki/edit.html")
def view_page(name): """Show a specific wiki page.""" link = name name = Wiki.url_to_name(name) g.info["link"] = link g.info["title"] = name # Look up the page. page = Wiki.get_page(name) if not page: # Page doesn't exist... yet! g.info["title"] = Wiki.url_to_name(name) return template("wiki/missing.html"), 404 # Which revision to show? version = request.args.get("revision", None) if version: # Find this one. rev = None for item in page["revisions"]: if item["id"] == version: rev = item break if rev is None: flash("That revision was not found for this page.") rev = page["revisions"][0] else: # Show the latest one. rev = page["revisions"][0] # Getting the plain text source? if request.args.get("source", None): g.info["markdown"] = render_markdown( "\n".join(["# Source: {}".format(name), "", "```markdown", rev["body"], "```"]) ) return template("markdown.inc.html") # Render it! g.info["rendered_body"] = Wiki.render_page(rev["body"]) g.info["rendered_body"] = Emoticons.render(g.info["rendered_body"]) g.info["pretty_time"] = pretty_time(Config.wiki.time_format, rev["time"]) # Author info g.info["author"] = User.get_user(uid=rev["author"]) return template("wiki/page.html")
def view_page(name): """Show a specific wiki page.""" link = name name = Wiki.url_to_name(name) g.info["link"] = link g.info["title"] = name # Look up the page. page = Wiki.get_page(name) if not page: # Page doesn't exist... yet! g.info["title"] = Wiki.url_to_name(name) return template("wiki/missing.html"), 404 # Which revision to show? version = request.args.get("revision", None) if version: # Find this one. rev = None for item in page["revisions"]: if item["id"] == version: rev = item break if rev is None: flash("That revision was not found for this page.") rev = page["revisions"][0] else: # Show the latest one. rev = page["revisions"][0] # Getting the plain text source? if request.args.get("source", None): g.info["markdown"] = render_markdown("\n".join([ "# Source: {}".format(name), "", "```markdown", rev["body"], "```" ])) return template("markdown.inc.html") # Render it! g.info["rendered_body"] = Wiki.render_page(rev["body"]) g.info["rendered_body"] = Emoticons.render(g.info["rendered_body"]) g.info["pretty_time"] = pretty_time(Config.wiki.time_format, rev["time"]) # Author info g.info["author"] = User.get_user(uid=rev["author"]) return template("wiki/page.html")