Attachment 'moinmoin_192_attachfile.patch'

Download

   1 --- AttachFile.py	2010-06-08 22:50:15.000000000 +0800
   2 +++ moin-1.9.2/MoinMoin/action/AttachFile.py	2010-02-28 23:28:45.000000000 +0800
   3 @@ -161,7 +161,7 @@
   4          @return: complete path/filename of attached file
   5      """
   6      if isinstance(filename, unicode):
   7 -        filename = wikiutil.quoteWikinameFS(filename)
   8 +        filename = filename.encode(config.charset)
   9      return os.path.join(getAttachDir(request, pagename, create=1), filename)
  10  
  11  
  12 @@ -211,11 +211,11 @@
  13          or an open file object (file content in e.g. a tempfile).
  14      """
  15      # replace illegal chars
  16 -    target = wikiutil.quoteWikinameFS(wikiutil.taintfilename(target))
  17 +    target = wikiutil.taintfilename(target)
  18  
  19      # get directory, and possibly create it
  20      attach_dir = getAttachDir(request, pagename, create=1)
  21 -    fpath = os.path.join(attach_dir, target)
  22 +    fpath = os.path.join(attach_dir, target).encode(config.charset)
  23  
  24      exists = os.path.exists(fpath)
  25      if exists:
  26 @@ -249,7 +249,7 @@
  27      # get directory, do not create it
  28      attach_dir = getAttachDir(request, pagename, create=0)
  29      # remove file
  30 -    fpath = os.path.join(attach_dir, wikiutil.quoteWikinameFS(target))
  31 +    fpath = os.path.join(attach_dir, target).encode(config.charset)
  32      try:
  33          filesize = os.path.getsize(fpath)
  34          os.remove(fpath)
  35 @@ -347,7 +347,7 @@
  36          html.append(fmt.bullet_list(1))
  37          for file in files:
  38              mt = wikiutil.MimeType(filename=file)
  39 -            fullpath = os.path.join(attach_dir, wikiutil.quoteWikinameFS(file))
  40 +            fullpath = os.path.join(attach_dir, file).encode(config.charset)
  41              st = os.stat(fullpath)
  42              base, ext = os.path.splitext(file)
  43              parmdict = {'file': wikiutil.escape(file),
  44 @@ -423,7 +423,7 @@
  45  def _get_files(request, pagename):
  46      attach_dir = getAttachDir(request, pagename)
  47      if os.path.isdir(attach_dir):
  48 -        files = [wikiutil.unquoteWikiname(fn)  for fn in os.listdir(attach_dir)]
  49 +        files = [fn.decode(config.charset) for fn in os.listdir(attach_dir)]
  50          files.sort()
  51      else:
  52          files = []
  53 @@ -588,10 +588,10 @@
  54          target, bytes = add_attachment(request, pagename, target, file_upload.stream, overwrite=overwrite)
  55          msg = _("Attachment '%(target)s' (remote name '%(filename)s')"
  56                  " with %(bytes)d bytes saved.") % {
  57 -                'target': wikiutil.unquoteWikiname(target), 'filename': file_upload.filename, 'bytes': bytes}
  58 +                'target': target, 'filename': file_upload.filename, 'bytes': bytes}
  59      except AttachmentAlreadyExists:
  60          msg = _("Attachment '%(target)s' (remote name '%(filename)s') already exists.") % {
  61 -            'target': wikiutil.unquoteWikiname(target), 'filename': file_upload.filename}
  62 +            'target': target, 'filename': file_upload.filename}
  63  
  64      # return attachment list
  65      upload_form(pagename, request, msg)
  66 @@ -673,9 +673,9 @@
  67      newpage = Page(request, new_pagename)
  68      if newpage.exists(includeDeleted=1) and request.user.may.write(new_pagename) and request.user.may.delete(pagename):
  69          new_attachment_path = os.path.join(getAttachDir(request, new_pagename,
  70 -                              create=1), wikiutil.quoteWikinameFS(new_attachment))
  71 +                              create=1), new_attachment).encode(config.charset)
  72          attachment_path = os.path.join(getAttachDir(request, pagename),
  73 -                          wikiutil.quoteWikinameFS(attachment))
  74 +                          attachment).encode(config.charset)
  75  
  76          if os.path.exists(new_attachment_path):
  77              upload_form(pagename, request,
  78 @@ -809,10 +809,7 @@
  79  
  80          # TODO: fix the encoding here, plain 8 bit is not allowed according to the RFCs
  81          # There is no solution that is compatible to IE except stripping non-ascii chars
  82 -        if 'MSIE' in request.http_user_agent:
  83 -            filename_enc = filename.encode('gbk')
  84 -        else:
  85 -            filename_enc = filename.encode(config.charset)
  86 +        filename_enc = filename.encode(config.charset)
  87  
  88          # for dangerous files (like .html), when we are in danger of cross-site-scripting attacks,
  89          # we just let the user store them to disk ('attachment').
  90 @@ -853,10 +850,7 @@
  91  
  92          # TODO: fix the encoding here, plain 8 bit is not allowed according to the RFCs
  93          # There is no solution that is compatible to IE except stripping non-ascii chars
  94 -        if 'MSIE' in request.http_user_agent:
  95 -            filename_enc = filename.encode('gbk')
  96 -        else:
  97 -            filename_enc = filename.encode(config.charset)
  98 +        filename_enc = filename.encode(config.charset)
  99  
 100          # for dangerous files (like .html), when we are in danger of cross-site-scripting attacks,
 101          # we just let the user store them to disk ('attachment').
 102 @@ -1162,7 +1156,7 @@
 103                  filepath = os.path.join(page_dir, filename)
 104                  data.addRow((
 105                      Page(request, pagename).link_to(request, querystr="action=AttachFile"),
 106 -                    wikiutil.escape(wikiutil.unquoteWikiname(filename)),
 107 +                    wikiutil.escape(filename.decode(config.charset)),
 108                      os.path.getsize(filepath),
 109                  ))
 110  

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2010-06-08 14:53:30, 5.2 KB) [[attachment:moinmoin_192_attachfile.patch]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.