comparison MoinMoin/action/AttachFile.py @ 1952:8ab85e3711dc

AttachFile:send_viewfile extended for mimetypes presentable by EmbedObject
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Fri, 06 Apr 2007 19:01:36 +0000
parents b06ef2a53efa
children 3bc30cdc4555
comparison
equal deleted inserted replaced
1951:a05a3b447db5 1952:8ab85e3711dc
19 19
20 @copyright: 2001 by Ken Sugino (sugino@mediaone.net), 20 @copyright: 2001 by Ken Sugino (sugino@mediaone.net),
21 2001-2004 by Juergen Hermann <jh@web.de>, 21 2001-2004 by Juergen Hermann <jh@web.de>,
22 2005 MoinMoin:AlexanderSchremmer, 22 2005 MoinMoin:AlexanderSchremmer,
23 2005 DiegoOngaro at ETSZONE (diego@etszone.com), 23 2005 DiegoOngaro at ETSZONE (diego@etszone.com),
24 2005-2006 MoinMoin:ReimarBauer, 24 2005-2007 MoinMoin:ReimarBauer,
25 2007 MoinMoin:ThomasWaldmann 25 2007 MoinMoin:ThomasWaldmann
26 @license: GNU GPL, see COPYING for details. 26 @license: GNU GPL, see COPYING for details.
27 """ 27 """
28 28
29 import os, time, zipfile 29 import os, time, zipfile, mimetypes
30 from MoinMoin import config, wikiutil, packages 30 from MoinMoin import config, wikiutil, packages
31 from MoinMoin.Page import Page 31 from MoinMoin.Page import Page
32 from MoinMoin.util import filesys, timefuncs 32 from MoinMoin.util import filesys, timefuncs
33 33
34 action_name = __name__.split('.')[-1] 34 action_name = __name__.split('.')[-1]
63 if create and not os.path.isdir(attach_dir): 63 if create and not os.path.isdir(attach_dir):
64 os.makedirs(attach_dir) 64 os.makedirs(attach_dir)
65 else: 65 else:
66 # send file via CGI, from page storage area 66 # send file via CGI, from page storage area
67 if request.page and pagename == request.page.page_name: 67 if request.page and pagename == request.page.page_name:
68 page = request.page # reusing existing page obj is faster 68 page = request.page # reusing existing page obj is faster
69 else: 69 else:
70 page = Page(request, pagename) 70 page = Page(request, pagename)
71 attach_dir = page.getPagePath("attachments", check_create=create) 71 attach_dir = page.getPagePath("attachments", check_create=create)
72 72
73 return attach_dir 73 return attach_dir
1001 date = "%d-%02d-%02d %02d:%02d:%02d" % zinfo.date_time 1001 date = "%d-%02d-%02d %02d:%02d:%02d" % zinfo.date_time
1002 request.write(wikiutil.escape("%-46s %s %12d\n" % (zinfo.filename, date, zinfo.file_size))) 1002 request.write(wikiutil.escape("%-46s %s %12d\n" % (zinfo.filename, date, zinfo.file_size)))
1003 request.write("</pre>") 1003 request.write("</pre>")
1004 return 1004 return
1005 1005
1006 request.write('<p>' + _("Unknown file type, cannot display this attachment inline.") + '</p>') 1006 # reuse class tmp from Despam to define macro
1007 request.write('<a href="%s">%s</a>' % ( 1007 from MoinMoin.action.Despam import tmp
1008 getAttachUrl(pagename, filename, request, escaped=1), wikiutil.escape(filename))) 1008 macro = tmp()
1009 macro.request = request
1010 macro.formatter = request.html_formatter
1011
1012 # use EmbedObject to view valid mime types
1013 from MoinMoin.macro.EmbedObject import EmbedObject
1014 mime_type, enc = mimetypes.guess_type(filename)
1015 if mime_type is None:
1016 request.write('<p>' + _("Unknown file type, cannot display this attachment inline.") + '</p>')
1017 request.write('For using an external program follow this link <a href="%s">%s</a>' % (
1018 getAttachUrl(pagename, filename, request, escaped=1), wikiutil.escape(filename)))
1019 return
1020
1021 url = getAttachUrl(pagename, filename, request, escaped=1)
1022
1023 request.write(request.formatter.rawHTML(EmbedObject.embed(EmbedObject(macro, wikiutil.escape(filename)), mime_type, url)))
1024 return
1009 1025
1010 1026
1011 def view_file(pagename, request): 1027 def view_file(pagename, request):
1012 _ = request.getText 1028 _ = request.getText
1013 1029