from . import auth
from . import blog
from . import boot
+from . import docs
from . import donate
from . import downloads
from . import fireinfo
(r"/blog/([0-9a-z\-\._]+)/edit", blog.EditHandler),
(r"/blog/([0-9a-z\-\._]+)/publish", blog.PublishHandler),
+ # Docs
+ (r"/docs([A-Za-z0-9\-_\/]+)?", docs.PageHandler),
+
# Downloads
(r"/downloads", downloads.IndexHandler),
(r"/downloads/mirrors", downloads.MirrorsHandler),
--- /dev/null
+#!/usr/bin/python3
+
+import difflib
+import tornado.web
+
+from . import base
+
+class PageHandler(base.BaseHandler):
+ @property
+ def action(self):
+ return self.get_argument("action", None)
+
+ def write_error(self, status_code, **kwargs):
+ # Render a custom page for 404
+ if status_code == 404:
+ self.render("wiki/404.html", **kwargs)
+ return
+
+ # Otherwise raise this to one layer above
+ super().write_error(status_code, **kwargs)
+
+ @tornado.web.removeslash
+ def get(self, path):
+ if path is None:
+ path = "/"
+
+ # Check permissions
+ if not self.backend.wiki.check_acl(path, self.current_user):
+ raise tornado.web.HTTPError(403, "Access to %s not allowed for %s" % (path, self.current_user))
+
+ # Check if we are asked to render a certain revision
+ revision = self.get_argument("revision", None)
+
+ # Fetch the wiki page
+ page = self.backend.wiki.get_page(path, revision=revision)
+
+ # Diff
+ if self.action == "diff":
+ # Get both revisions
+ a = self.get_argument("a")
+ b = self.get_argument("b")
+
+ # Fetch both versions of the page
+ a = self.backend.wiki.get_page(path, revision=a)
+ b = self.backend.wiki.get_page(path, revision=b)
+ if not a or not b:
+ raise tornado.web.HTTPError(404)
+
+ # Cannot render a diff for the identical page
+ if a == b:
+ raise tornado.web.HTTPError(400)
+
+ # Make sure that b is newer than a
+ if a > b:
+ a, b = b, a
+
+ self.render("wiki/diff.html", page=page, a=a, b=b)
+ return
+
+ # Restore
+ elif self.action == "restore":
+ self.render("wiki/confirm-restore.html", page=page)
+ return
+
+ # Revisions
+ elif self.action == "revisions":
+ self.render("wiki/revisions.html", page=page)
+ return
+
+ # If the page does not exist, we send 404
+ if not page or page.was_deleted():
+ # Handle /start links which were in the format of DokuWiki
+ if path.endswith("/start"):
+ # Strip /start from path
+ path = path[:-6] or "/"
+
+ # Redirect user to page if it exists
+ page = self.backend.wiki.page_exists(path)
+ if page:
+ self.redirect(path)
+
+ raise tornado.web.HTTPError(404)
+
+ # Fetch the latest revision
+ latest_revision = page.get_latest_revision()
+
+ # Render page
+ self.render("wiki/page.html", page=page, latest_revision=latest_revision)