changeset 143:11df1156d432

fixed MoinMoinBugs/BrokenAttachmentPaths imported from: moin--main--1.5--patch-145
author Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
date Thu, 27 Oct 2005 09:15:20 +0000
parents 0b1b06737340
children 1f5a2312b215
files MoinMoin/action/AttachFile.py MoinMoin/formatter/text_html.py MoinMoin/parser/wiki.py
diffstat 3 files changed, 26 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/AttachFile.py	Thu Oct 27 02:00:48 2005 +0000
+++ b/MoinMoin/action/AttachFile.py	Thu Oct 27 09:15:20 2005 +0000
@@ -64,6 +64,16 @@
 
     return attach_dir
 
+def absoluteName(url, pagename):
+    """ Get (pagename, filename) of an atatchment: link
+    """
+
+    pieces = url.rsplit('/', 1)
+    if len(pieces)==1:
+        return pagename, pieces[0]
+    else:
+        print pieces
+        return pieces[0], pieces[1]
 
 def getAttachUrl(pagename, filename, request, addts=0, escaped=0):
     """ Get URL that points to attachment `filename` of page `pagename`.
--- a/MoinMoin/formatter/text_html.py	Thu Oct 27 02:00:48 2005 +0000
+++ b/MoinMoin/formatter/text_html.py	Thu Oct 27 09:15:20 2005 +0000
@@ -301,8 +301,8 @@
 
     def attachment_link(self, url, text, **kw):
         _ = self.request.getText
-        pagename = self.page.page_name
-        fname = wikiutil.taintfilename(url)
+        pagename, filename = AttachFile.absoluteName(url, self.page.page_name)
+        fname = wikiutil.taintfilename(filename)
         fpath = AttachFile.getFilename(self.request, pagename, fname)
         if not os.path.exists(fpath):
             linktext = _('Upload new attachment "%(filename)s"')
@@ -312,15 +312,15 @@
                           (wikiutil.quoteWikinameURL(pagename),
                            wikiutil.url_quote_plus(fname))),
                 linktext % {'filename': self.text(fname)})
-        target = AttachFile.getAttachUrl(pagename, url, self.request)
+        target = AttachFile.getAttachUrl(pagename, filename, self.request)
         return (self.url(1, target, title="attachment:%s" % url) +
                 self.text(text) +
                 self.url(0))
     
     def attachment_image(self, url, **kw):
         _ = self.request.getText
-        pagename = self.page.page_name
-        fname = wikiutil.taintfilename(url)
+        pagename, filename = AttachFile.absoluteName(url, self.page.page_name)
+        fname = wikiutil.taintfilename(filename)
         fpath = AttachFile.getFilename(self.request, pagename, fname)
         if not os.path.exists(fpath):
             linktext = _('Upload new attachment "%(filename)s"')
@@ -332,23 +332,23 @@
                 linktext % {'filename': self.text(fname)})
         return self.image(
             title="attachment:%s" % url,
-            src=AttachFile.getAttachUrl(pagename, url, self.request, addts=1))
+            src=AttachFile.getAttachUrl(pagename, filename, self.request, addts=1))
     
     def attachment_drawing(self, url, text, **kw):
         _ = self.request.getText
-        pagename = self.page.page_name
-        fname = wikiutil.taintfilename(url)
+        pagename, filename = AttachFile.absoluteName(url, self.page.page_name)
+        fname = wikiutil.taintfilename(filename)
         drawing = fname
         fname = fname + ".png"
-        url = url + ".png"
+        filename = filename + ".png"
         # fallback for old gif drawings (1.1 -> 1.2)
         fpath = AttachFile.getFilename(self.request, pagename, fname)
         if not os.path.exists(fpath):
             gfname = fname[:-4] + ".gif"
-            gurl = url[:-4] + ".gif"
+            gfilename = filename[:-4] + ".gif"
             gfpath = AttachFile.getFilename(self.request, pagename, gfname)
             if os.path.exists(gfpath):
-                fname, url, fpath = gfname, gurl, gfpath
+                fname, filename, fpath = gfname, gfilename, gfpath
 
         # check whether attachment exists, possibly point to upload form
         if not os.path.exists(fpath):
@@ -389,23 +389,23 @@
                 return (map + self.image(
                     alt=drawing,
                     src=AttachFile.getAttachUrl(
-                    pagename, url, self.request,
+                    pagename, filename, self.request,
                     addts=1),
                     usemap='#'+mapid, html_class="drawing"))
         else:
             return wikiutil.link_tag(self.request,
                                      edit_link,
                                      self.image(alt=url,
-                                                src=AttachFile.getAttachUrl(pagename, url, self.request, addts=1), html_class="drawing"),
+                                                src=AttachFile.getAttachUrl(pagename, filename, self.request, addts=1), html_class="drawing"),
                                      attrs='title="%s"' % (_('Edit drawing %(filename)s') % {'filename': self.text(fname)}))
         
     
     def attachment_inlined(self, url, text, **kw):
         _ = self.request.getText
-        pagename = self.page.page_name
-        fname = wikiutil.taintfilename(url)
+        pagename, filename = AttachFile.absoluteName(url, self.page.page_name)
+        fname = wikiutil.taintfilename(filename)
         fpath = AttachFile.getFilename(self.request, pagename, fname)
-        base, ext = os.path.splitext(url)
+        base, ext = os.path.splitext(filename)
         Parser = wikiutil.getParserForExtension(self.request.cfg, ext)
         if Parser is not None:
             try:
--- a/MoinMoin/parser/wiki.py	Thu Oct 27 02:00:48 2005 +0000
+++ b/MoinMoin/parser/wiki.py	Thu Oct 27 09:15:20 2005 +0000
@@ -208,12 +208,6 @@
         url = wikiutil.url_unquote(url, want_unicode=False)
         text = text or url
 
-        parts = url.split('/')
-        if len(parts) > 1:
-            # get attachment from other page
-            pagename = '/'.join(parts[:-1])
-            url = parts[-1]
-
         from MoinMoin.action import AttachFile
         if drawing:
             return self.formatter.attachment_drawing(url, text)