changeset 1985:eb5328be394e

AttachFile:destinguish between zip and other fileformats using zip archives
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Mon, 09 Apr 2007 14:52:56 +0000
parents efafd0dd3ff8
children 07aff6369476
files MoinMoin/action/AttachFile.py
diffstat 1 files changed, 5 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/AttachFile.py	Mon Apr 09 10:40:47 2007 +0000
+++ b/MoinMoin/action/AttachFile.py	Mon Apr 09 14:52:56 2007 +0000
@@ -305,6 +305,7 @@
         label_install = _("install")
 
         for file in files:
+            mt = wikiutil.MimeType(filename=file)
             st = os.stat(os.path.join(attach_dir, file).encode(config.charset))
             fsize = "%.1f" % (float(st.st_size) / 1024)
             fmtime = request.user.getFormattedDateTime(st.st_mtime)
@@ -342,11 +343,11 @@
             else:
                 viewlink = '<a href="%(baseurl)s/%(urlpagename)s?action=%(action)s&amp;do=view&amp;target=%(urlfile)s">%(label_view)s</a>' % parmdict
 
-            if (packages.ZipPackage(request, os.path.join(attach_dir, file).encode(config.charset)).isPackage() and
+            if (packages.ZipPackage(request, os.path.join(attach_dir, file).encode(config.charset)).isPackage() and mt.minor == 'zip' and
                 request.user.isSuperUser()):
                 viewlink += ' | <a href="%(baseurl)s/%(urlpagename)s?action=%(action)s&amp;do=install&amp;target=%(urlfile)s">%(label_install)s</a>' % parmdict
             elif (zipfile.is_zipfile(os.path.join(attach_dir, file).encode(config.charset)) and
-                request.user.may.read(pagename) and request.user.may.delete(pagename)
+                mt.minor == 'zip' and request.user.may.read(pagename) and request.user.may.delete(pagename)
                 and request.user.may.write(pagename)):
                 viewlink += ' | <a href="%(baseurl)s/%(urlpagename)s?action=%(action)s&amp;do=unzip&amp;target=%(urlfile)s">%(label_unzip)s</a>' % parmdict
 
@@ -990,11 +991,11 @@
         return
 
     package = packages.ZipPackage(request, fpath)
-    if package.isPackage():
+    if package.isPackage() and mt.minor == 'zip':
         request.write("<pre><b>%s</b>\n%s</pre>" % (_("Package script:"), wikiutil.escape(package.getScript())))
         return
 
-    if zipfile.is_zipfile(fpath):
+    if zipfile.is_zipfile(fpath) and mt.minor == 'zip':
         zf = zipfile.ZipFile(fpath, mode='r')
         request.write("<pre>%-46s %19s %12s\n" % (_("File Name"), _("Modified")+" "*5, _("Size")))
         for zinfo in zf.filelist: