changeset 5244:9730c2936db7

language_setup, packages: new method ReplaceUnderlayAttachment introduced. This is used to package attachments for underlay pages. For language packs always attachments have to been first packaged. This ensures that they can be unpacked before acls of the page protects this.
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sun, 01 Nov 2009 12:21:16 +0100
parents b8b4e75c9ca1
children 55de22afaff3 c9d372df60a9
files MoinMoin/action/language_setup.py MoinMoin/packages.py MoinMoin/script/maint/mkpagepacks.py
diffstat 3 files changed, 32 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/language_setup.py	Sun Nov 01 00:55:31 2009 +0100
+++ b/MoinMoin/action/language_setup.py	Sun Nov 01 12:21:16 2009 +0100
@@ -47,9 +47,7 @@
         package = packages.ZipPackage(request, targetpath)
         if package.isPackage():
             if package.installPackage():
-                msg = package.msg
-                if not msg:
-                    msg = _("Attachment '%(filename)s' installed.") % {'filename': target}
+                msg = _("Attachment '%(filename)s' installed.") % {'filename': target}
             else:
                 msg = _("Installation of '%(filename)s' failed.") % {'filename': target}
         else:
--- a/MoinMoin/packages.py	Sun Nov 01 00:55:31 2009 +0100
+++ b/MoinMoin/packages.py	Sun Nov 01 12:21:16 2009 +0100
@@ -343,6 +343,30 @@
         else:
             self.msg += u"action delete page: not enough rights - nothing done \n"
 
+    def do_replaceunderlayattachment(self, zipname, filename, pagename, author=u"Scripting Subsystem", comment=u""):
+        """
+        overwrite underlay attachments
+
+        @param pagename: Page where the file is attached. Or in 2.0, the file itself.
+        @param zipname: Filename of the attachment from the zip file
+        @param filename: Filename of the attachment (just applicable for MoinMoin < 2.0)
+        """
+        if self.request.user.may.write(pagename):
+            _ = self.request.getText
+            filename = wikiutil.taintfilename(filename)
+            zipname = wikiutil.taintfilename(zipname)
+            page = PageEditor(self.request, pagename, do_editor_backup=0, uid_override=author)
+            pagedir = page.getPagePath(use_underlay=1, check_create=1)
+            attachments = os.path.join(pagedir, 'attachments')
+            if not os.path.exists(attachments):
+                os.mkdir(attachments)
+            target = os.path.join(attachments, filename)
+            self._extractToFile(zipname, target)
+            if os.path.exists(target):
+                os.chmod(target, config.umask )
+        else:
+            self.msg += u"action replace underlay attachment: not enough rights - nothing done \n"
+
     def do_replaceunderlay(self, filename, pagename):
         """
         Overwrites underlay pages. Implementational detail: This needs to be
@@ -368,7 +392,6 @@
 
         pagefile = os.path.join(revdir, revstr)
         self._extractToFile(filename, pagefile)
-
         # Clear caches
         # TODO Code from MoinMoin/script/maint/cleancache.py may be used
 
--- a/MoinMoin/script/maint/mkpagepacks.py	Sun Nov 01 00:55:31 2009 +0100
+++ b/MoinMoin/script/maint/mkpagepacks.py	Sun Nov 01 12:21:16 2009 +0100
@@ -106,17 +106,18 @@
             page = Page(request, pagename)
             cnt += 1
             files = _get_files(request, pagename)
+            for attname in files:
+                cnt += 1
+                zipname = "%d_attachment" % cnt
+                script.append(packLine(["ReplaceUnderlayAttachment", zipname, attname, pagename, userid, "Created by the PackagePages action."]))
+                filename = AttachFile.getFilename(request, pagename, attname)
+                zf.write(filename, zipname)
+
             script.append(packLine([function, str(cnt), pagename]))
             timestamp = wikiutil.version2timestamp(page.mtime_usecs())
             zi = zipfile.ZipInfo(filename=str(cnt), date_time=datetime.fromtimestamp(timestamp).timetuple()[:6])
             zi.compress_type = COMPRESSION_LEVEL
             zf.writestr(zi, page.get_raw_body().encode("utf-8"))
-            for attname in files:
-                cnt += 1
-                zipname = "%d_attachment" % cnt
-                script.append(packLine(["AddAttachment", zipname, attname, pagename, userid, "Created by the PackagePages action."]))
-                filename = AttachFile.getFilename(request, pagename, attname)
-                zf.write(filename, zipname)
 
         script += [packLine(['Print', 'Installed MoinMaster page bundle %s.' % os.path.basename(filename)])]