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):
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)