]> git.ipfire.org Git - ipfire.org.git/blobdiff - src/web/wiki.py
wiki: Add file gallery and allow uploading files
[ipfire.org.git] / src / web / wiki.py
index 90da993c030af123d9e068caa3614b9d8b3f5ce3..2afe1ea7c3db502aedc1ec6347bc3b527174ba96 100644 (file)
@@ -6,6 +6,48 @@ from . import auth
 from . import base
 from . import ui_modules
 
+class ActionUploadHandler(auth.CacheMixin, base.BaseHandler):
+       @tornado.web.authenticated
+       def post(self):
+               path = self.get_argument("path")
+
+               try:
+                       filename, data, mimetype = self.get_file("file")
+
+                       # XXX check valid mimetypes
+
+                       with self.db.transaction():
+                               file = self.backend.wiki.upload(path, filename, data,
+                                       mimetype=mimetype, author=self.current_user,
+                                       address=self.get_remote_ip())
+
+               except TypeError as e:
+                       raise e
+
+               self.redirect("%s/files" % path)
+
+
+class FilesHandler(auth.CacheMixin, base.BaseHandler):
+       @tornado.web.authenticated
+       def get(self, path):
+               files = self.backend.wiki.get_files(path)
+
+               self.render("wiki/files/index.html", path=path, files=files)
+
+
+class FileHandler(auth.CacheMixin, base.BaseHandler):
+       def get(self, path):
+               file = self.backend.wiki.get_file_by_path(path)
+               if not file:
+                       raise tornado.web.HTTPError(404, "Could not find %s" % path)
+
+               # Set headers
+               self.set_header("Content-Type", file.mimetype or "application/octet-stream")
+               self.set_header("Content-Length", file.size)
+
+               self.finish(file.blob)
+
+
 class PageHandler(auth.CacheMixin, base.BaseHandler):
        @property
        def action(self):
@@ -102,9 +144,15 @@ class WikiListModule(ui_modules.UIModule):
 
 class WikiNavbarModule(ui_modules.UIModule):
        def render(self, suffix=None):
+               _ = self.locale.translate
+
                breadcrumbs = self.backend.wiki.make_breadcrumbs(self.request.path)
 
-               title = self.backend.wiki.get_page_title(self.request.path)
+               # Don't search for a title for the file manager
+               if self.request.path.endswith("/files"):
+                       title = _("Files")
+               else:
+                       title = self.backend.wiki.get_page_title(self.request.path)
 
                return self.render_string("wiki/modules/navbar.html",
                        breadcrumbs=breadcrumbs, page_title=title, suffix=suffix)