changeset 163:b19525bf0cf6

fixed MoinMoinBugs/HighlightingBreaksAttachmentLink and some more attachment bugs imported from: moin--main--1.5--patch-165
author Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
date Sun, 30 Oct 2005 17:31:59 +0000
parents e8da71f39a92
children c6655cd44cef
files MoinMoin/formatter/base.py MoinMoin/formatter/text_html.py MoinMoin/formatter/text_plain.py
diffstat 3 files changed, 57 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/formatter/base.py	Sun Oct 30 12:11:27 2005 +0000
+++ b/MoinMoin/formatter/base.py	Sun Oct 30 17:31:59 2005 +0000
@@ -88,6 +88,38 @@
     def url(self, on, url=None, css=None, **kw):
         raise NotImplementedError
 
+    # Attachments ######################################################
+
+    def attachment_link(self, url, text, **kw):
+        raise NotImplementedError
+    def attachment_image(self, url, **kw):
+        raise NotImplementedError
+    def attachment_drawing(self, url, text, **kw):
+        raise NotImplementedError
+
+    def attachment_inlined(self, url, text, **kw):
+        from MoinMoin.action import AttachFile
+        import os
+        _ = self.request.getText
+        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(filename)
+        Parser = wikiutil.getParserForExtension(self.request.cfg, ext)
+        if Parser is not None:
+            try:
+                content = file(fpath, 'r').read()
+                # Try to decode text. It might return junk, but we don't
+                # have enough information with attachments.
+                content = wikiutil.decodeUnknownInput(content)
+                colorizer = Parser(content, self.request)
+                colorizer.format(self)
+            except IOError:
+                pass
+
+        return self.attachment_link(url, text)
+
+
     def anchordef(self, name):
         return ""
 
--- a/MoinMoin/formatter/text_html.py	Sun Oct 30 12:11:27 2005 +0000
+++ b/MoinMoin/formatter/text_html.py	Sun Oct 30 17:31:59 2005 +0000
@@ -310,9 +310,9 @@
             linktext = _('Upload new attachment "%(filename)s"')
             return wikiutil.link_tag(
                 self.request,
-                self.text('%s?action=AttachFile&rename=%s' %
-                          (wikiutil.quoteWikinameURL(pagename),
-                           wikiutil.url_quote_plus(fname))),
+                ('%s?action=AttachFile&rename=%s' %
+                 (wikiutil.quoteWikinameURL(pagename),
+                  wikiutil.url_quote_plus(fname))),
                 linktext % {'filename': self.text(fname)})
         target = AttachFile.getAttachUrl(pagename, filename, self.request)
         return (self.url(1, target, title="attachment:%s" % url) +
@@ -328,9 +328,9 @@
             linktext = _('Upload new attachment "%(filename)s"')
             return wikiutil.link_tag(
                 self.request,
-                self.text('%s?action=AttachFile&rename=%s' %
-                          (wikiutil.quoteWikinameURL(pagename),
-                           wikiutil.url_quote_plus(fname))),
+                ('%s?action=AttachFile&rename=%s' %
+                 (wikiutil.quoteWikinameURL(pagename),
+                  wikiutil.url_quote_plus(fname))),
                 linktext % {'filename': self.text(fname)})
         return self.image(
             title="attachment:%s" % url,
@@ -355,15 +355,16 @@
         # check whether attachment exists, possibly point to upload form
         if not os.path.exists(fpath):
             linktext = _('Create new drawing "%(filename)s"')
-            return wikiutil.link_tag(self.request,
-                self.text('%s?action=AttachFile&rename=%s%s' % (
-                    wikiutil.quoteWikinameURL(pagename),
-                    wikiutil.url_quote_plus(fname),
-                    drawing and ('&drawing=%s' % wikiutil.url_quote(drawing)) or '')),
+            return wikiutil.link_tag(
+                self.request,
+                ('%s?action=AttachFile&rename=%s%s' %
+                 (wikiutil.quoteWikinameURL(pagename),
+                  wikiutil.url_quote_plus(fname),
+                  drawing and ('&drawing=%s' % wikiutil.url_quote(drawing)) or '')),
                 linktext % {'filename': self.text(fname)})
 
         mappath = AttachFile.getFilename(self.request, pagename, drawing + '.map')
-        edit_link = self.text('%s?action=AttachFile&rename=%s&drawing=%s' % (
+        edit_link = ('%s?action=AttachFile&rename=%s&drawing=%s' % (
             wikiutil.quoteWikinameURL(pagename),
             wikiutil.url_quote_plus(fname),
             wikiutil.url_quote(drawing)))
@@ -402,25 +403,8 @@
                                      attrs='title="%s"' % (_('Edit drawing %(filename)s') % {'filename': self.text(fname)}))
         
     
-    def attachment_inlined(self, url, text, **kw):
-        _ = self.request.getText
-        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(filename)
-        Parser = wikiutil.getParserForExtension(self.request.cfg, ext)
-        if Parser is not None:
-            try:
-                content = file(fpath, 'r').read()
-                # Try to decode text. It might return junk, but we don't
-                # have enough information with attachments.
-                content = wikiutil.decodeUnknownInput(content)
-                colorizer = Parser(content, self.request)
-                colorizer.format(self)
-            except IOError:
-                pass
-
-        return self.attachment_link(url, text)
+    # def attachment_inlined(self, url, text, **kw):
+    # moved to MoinMoin/formatter/base.py
 
 
     # Text ##############################################################
--- a/MoinMoin/formatter/text_plain.py	Sun Oct 30 12:11:27 2005 +0000
+++ b/MoinMoin/formatter/text_plain.py	Sun Oct 30 17:31:59 2005 +0000
@@ -69,6 +69,16 @@
                 self._text = None
                 return u' [%s]' % (self._url)
 
+    # Attachments ######################################################
+
+    def attachment_link(self, url, text, **kw):
+        return "[%s]" % text
+    def attachment_image(self, url, **kw):
+        return "[image:%s]" % url
+
+    def attachment_drawing(self, url, text, **kw):
+        return "[drawing:%s]" % text
+    
     def text(self, text):
         self._did_para = 0
         if self._text is not None: