]> git.ipfire.org Git - ipfire.org.git/commitdiff
wiki: Automatically redirect from /start pages
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 7 Oct 2019 15:55:17 +0000 (16:55 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 7 Oct 2019 16:09:58 +0000 (17:09 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/backend/wiki.py
src/web/wiki.py

index cc7bd167fa5a127beedd5d88b0508b9aac5163fe..4a90069333b20b8a36d25e46643cc3bb433f506c 100644 (file)
@@ -41,6 +41,12 @@ class Wiki(misc.Object):
                # Normalise links
                return os.path.normpath(path)
 
+       def page_exists(self, path):
+               page = self.get_page(path)
+
+               # Page must have been found and not deleted
+               return page and not page.was_deleted()
+
        def get_page_title(self, page, default=None):
                # Try to retrieve title from cache
                title = self.memcache.get("wiki:title:%s" % page)
index a8a4e907635a7b4aaa94a7afcca83e9f4d32d74c..dfb46a94afa44702f1e419571420ee6173dfdf99 100644 (file)
@@ -254,6 +254,16 @@ class PageHandler(auth.CacheMixin, base.BaseHandler):
 
                # 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