changeset 2755:7c8e3ce74202

wiki parser: using <object> for client side page transclusion
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Thu, 23 Aug 2007 21:15:32 +0200
parents 907b9e60c232
children bdb12fb39b00
files MoinMoin/parser/text_moin_wiki.py
diffstat 1 files changed, 36 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/parser/text_moin_wiki.py	Thu Aug 23 10:34:28 2007 +0200
+++ b/MoinMoin/parser/text_moin_wiki.py	Thu Aug 23 21:15:32 2007 +0200
@@ -26,7 +26,7 @@
 
 import re
 from MoinMoin import config, wikiutil, macro
-
+from MoinMoin.Page import Page
 
 Dependencies = ['user'] # {{{#!wiki comment ... }}} has different output depending on the user's profile settings
 
@@ -298,7 +298,6 @@
 )|(?P<sgml_entity>  # must come AFTER entity rule!
     [<>&]  # needs special treatment for html/xml
 )"""  % {
-
         'url_scheme': url_scheme,
         'url_rule': url_rule,
         'punct': punct_pattern,
@@ -595,6 +594,16 @@
                 if scheme.startswith('http'): # can also be https
                     # currently only supports ext. image inclusion
                     return self.formatter.image(src=target, alt=desc, title=desc, css_class='external_image')
+                    # FF2 has a bug with target mimetype detection, it looks at the url path
+                    # and expects to find some "filename extension" there (like .png) and this
+                    # (not the response http headers) will set the default content-type of
+                    # the object. This will often work for staticly served files, but
+                    # fails for MoinMoin attachments (they don't have the filename.ext in the
+                    # path, but in the query string). FF3 seems to have this bug fixed, opera 9.2
+                    # also works.
+                    #return (self.formatter.transclusion(1, data=target) +
+                    #        desc +
+                    #        self.formatter.transclusion(0))
 
             elif m.group('attach_scheme'):
                 scheme = m.group('attach_scheme')
@@ -608,6 +617,15 @@
                     elif mt.major == 'image':
                         return self.formatter.attachment_image(url, alt=desc, title=desc, css_class='image')
                     else:
+                        from MoinMoin.action import AttachFile
+                        pagename = self.formatter.page.page_name
+                        href = AttachFile.getAttachUrl(pagename, url, self.request, escaped=0)
+                        return (self.formatter.transclusion(1, data=href, type=mt.spoil()) +
+                                desc +
+                                self.formatter.transclusion(0))
+
+                        #NOT USED CURRENTLY:
+
                         # use EmbedObject for other mimetypes
                         from MoinMoin.macro.EmbedObject import EmbedObject
                         from MoinMoin.action import AttachFile
@@ -623,14 +641,26 @@
                 elif scheme == 'drawing':
                     return self.formatter.attachment_drawing(url, desc)
 
-            elif m.group('page_name'): # TODO
+            elif m.group('page_name'):
+                # experimental client side transclusion
                 page_name = m.group('page_name')
-                return u"Error: <<Include(%s,%s)>> emulation missing..." % (page_name, args)
+                url = Page(self.request, page_name).url(self.request, querystr={'action': 'content', }, relative=False)
+                return (self.formatter.transclusion(1, data=url, type='text/html', width="100%") +
+                        desc +
+                        self.formatter.transclusion(0))
+                #return u"Error: <<Include(%s,%s)>> emulation missing..." % (page_name, args)
 
-            elif m.group('inter_wiki'): # TODO
+            elif m.group('inter_wiki'):
+                # experimental client side transclusion
                 wiki_name = m.group('inter_wiki')
                 page_name = m.group('inter_page')
-                return u"Error: <<RemoteInclude(%s:%s,%s)>> still missing." % (wiki_name, page_name, args)
+                wikitag, wikiurl, wikitail, err = wikiutil.resolve_interwiki(self.request, wiki_name, page_name)
+                url = wikiutil.join_wiki(wikiurl, wikitail)
+                url += '?action=content' # XXX moin specific
+                return (self.formatter.transclusion(1, data=url, type='text/html', width="100%") +
+                        desc +
+                        self.formatter.transclusion(0))
+                #return u"Error: <<RemoteInclude(%s:%s,%s)>> still missing." % (wiki_name, page_name, args)
 
             else:
                 if not desc: