changeset 1800:e8a309cad6b7

merged main
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 23 Feb 2007 22:04:30 +0100
parents 06ce4843b9b5 (current diff) cabab80d9597 (diff)
children 3369445b4aa8
files
diffstat 3 files changed, 22 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/AttachFile.py	Fri Feb 23 22:04:08 2007 +0100
+++ b/MoinMoin/action/AttachFile.py	Fri Feb 23 22:04:30 2007 +0100
@@ -165,6 +165,9 @@
 
 def add_attachment(request, pagename, target, filecontent, overwrite=0):
     # replace illegal chars
+
+    _ = request.getText
+
     target = wikiutil.taintfilename(target)
 
     # set mimetype from extension, or from given mimetype
--- a/MoinMoin/action/Load.py	Fri Feb 23 22:04:08 2007 +0100
+++ b/MoinMoin/action/Load.py	Fri Feb 23 22:04:30 2007 +0100
@@ -27,19 +27,6 @@
         self.method = 'POST'
         self.enctype = 'multipart/form-data'
 
-    def is_allowed(self):
-        # this is not strictly necessary because the underlying storage code checks
-        # as well
-        may = self.request.user.may
-        return may.write(self.pagename) and may.delete(self.pagename)
-
-    def check_condition(self):
-        _ = self._
-        if not self.page.exists():
-            return _("You are not allowed to change this page.")
-        else:
-            return None
-
     def do_action(self):
         """ Load """
         status = False
@@ -48,6 +35,7 @@
         author = self.request.user.name
 
         rename = form.get('rename', [u''])[0]
+
         filename = None
         if form.has_key('file__filename__'):
             filename = form['file__filename__']
@@ -55,13 +43,6 @@
         filecontent = form['file'][0]
         bytes = len(filecontent)
 
-        # if possible do decode
-        try:
-            filecontent = unicode(filecontent, config.charset)
-            is_decoded = True
-        except:
-            is_decoded = False
-
         overwrite = False
         if form.has_key('overwrite'):
             overwrite = True
@@ -77,22 +58,23 @@
             if bsindex >= 0:
                 target = target[bsindex+1:]
 
-        msg = _('Please enable the attachment checkbox')
-        if self.request.form.has_key('attachment'):
+        if self.request.form.has_key('attachment') and self.request.user.may.write(self.pagename):
             attach_dir = AttachFile.getAttachDir(self.request, self.pagename, create=1)
             fpath = os.path.join(attach_dir, target).encode(config.charset)
             exists = os.path.exists(fpath)
-
             if exists and not overwrite:
                 msg = _("Attachment '%(target)s' (remote name '%(filename)s') already exists.") % {
                          'target': target, 'filename': filename}
                 return status, msg
 
-            if exists:
+            if exists and self.request.user.may.delete(self.pagename):
                 try:
                     os.remove(fpath)
                 except:
                     pass
+            else:
+                msg = _("You are not allowed to delete attachments on this page.")
+                return status, msg
 
             AttachFile.add_attachment(self.request, self.pagename, target, filecontent)
             bytes = len(filecontent)
@@ -100,17 +82,20 @@
                    'target': target, 'filename': filename, 'bytes': bytes}
             status = True
 
-        elif is_decoded:
-            target = wikiutil.escape(target)
-            page = PageEditor(self.request, target, do_editor_backup=0, uid_override=author)
+        else:
+            filecontent = unicode(filecontent, config.charset)
+            self.pagename = wikiutil.escape(target)
+            page = Page(self.request, self.pagename)
+            pagedir = page.getPagePath("", check_create=0)
+            rev = Page.get_current_from_pagedir(page, pagedir)
+            pg = PageEditor(self.request, self.pagename, do_editor_backup=0, uid_override=author)
             try:
-                page.saveText(filecontent, 0)
-                msg = _("%(pagename)s added") % {"pagename": self.pagename}
+                msg = pg.saveText(filecontent, rev)
                 status = True
-                self.pagename = target
-            except PageEditor.Unchanged:
-                pass
-            page.clean_acl_cache()
+            except pg.EditConflict, e:
+                msg = e.message
+            except pg.SaveError, msg:
+                msg = unicode(msg)
 
         return status, msg
 
--- a/MoinMoin/filter/EXIF.py	Fri Feb 23 22:04:08 2007 +0100
+++ b/MoinMoin/filter/EXIF.py	Fri Feb 23 22:04:30 2007 +0100
@@ -1184,8 +1184,7 @@
             print
             continue
         print filename+':'
-        # data=process_file(file, 1) # with debug info
-        data = process_file(file, name, 0) # XXX undefined variable "name"
+        data = process_file(file, 1) # with debug info
         if not data:
             print 'No EXIF information found'
             continue