changeset 200:7c5bba88937b

attachment methods for the text_xml and xml_docbook formatters imported from: moin--main--1.5--patch-202
author Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
date Tue, 08 Nov 2005 09:59:37 +0000
parents 4e9b5e9610da
children e3e087c3c6a3
files MoinMoin/formatter/text_xml.py MoinMoin/formatter/xml_docbook.py
diffstat 2 files changed, 55 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/formatter/text_xml.py	Sun Nov 06 19:29:10 2005 +0000
+++ b/MoinMoin/formatter/text_xml.py	Tue Nov 08 09:59:37 2005 +0000
@@ -67,6 +67,15 @@
         else: str = ''
         
         return ('<jump href="%s"%s>' % (self._escape(url), str), '</jump>') [not on]
+    # Attachments ######################################################
+
+    def attachment_link(self, url, text, **kw):
+        return '<attachment href="%s">%s</attachment>' % (url, text)
+    def attachment_image(self, url, **kw):
+        return '<attachmentimage href="%s"></attachmentimage>' % (url,)
+    def attachment_drawing(self, url, text, **kw):
+        return '<attachmentdrawing href="%s">%s</attachmentdrawing>' % (
+            url, text)
 
     def text(self, text):
         if self.in_pre:
--- a/MoinMoin/formatter/xml_docbook.py	Sun Nov 06 19:29:10 2005 +0000
+++ b/MoinMoin/formatter/xml_docbook.py	Tue Nov 08 09:59:37 2005 +0000
@@ -9,11 +9,12 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-import sys, traceback
+import sys, traceback, os
 
 from MoinMoin.formatter.base import FormatterBase
 from MoinMoin import wikiutil, config
 from MoinMoin.error import CompositeError
+from MoinMoin.action import AttachFile
 
 from xml.sax import saxutils
 from xml.dom import getDOMImplementation
@@ -385,6 +386,50 @@
 
         return self._handleNode("link", on, attrs)
 
+# Attachments ######################################################
+
+    def attachment_link(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)
+        target = AttachFile.getAttachUrl(pagename, filename, self.request)
+        if not os.path.exists(fpath):
+            return self.text("[attachment:%s]" % url)
+        else:
+            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, 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):
+            return self.text("[attachment:%s]" % url)
+        else:
+            return self.image(
+                title="attachment:%s" % url,
+                src=AttachFile.getAttachUrl(pagename, filename,
+                                            self.request, addts=1))
+
+    def attachment_drawing(self, url, text, **kw):
+        _ = self.request.getText
+        pagename, filename = AttachFile.absoluteName(url, self.page.page_name)
+        fname = wikiutil.taintfilename(filename)
+        drawing = fname
+        fname = fname + ".png"
+        filename = filename + ".png"
+        if not os.path.exists(fpath):
+            return self.text("[drawing:%s]" % url)
+        else:
+            return self.image(
+                alt=drawing,
+                src=AttachFile.getAttachUrl(pagename, filename, self.request,
+                                            addts=1),
+                html_class="drawing")
+
 
 ### Images and Smileys ##############################################
     def image(self, **kw):