Commits

Anonymous committed d3e15ed

[svn r9818] XmlRpcPlugin: Fix for rendering wiki HTML in proper context for correct links and references to relative resources (such as image attachment reference).

Added test for absolute and relative attachment, but test only passes on Trac 0.11 - Trac 0.12 seems to have a bug here...

References #8466

Comments (0)

Files changed (2)

trunk/tracrpc/tests/wiki.py

         self.admin.wiki.deletePage('WikiOne')
         self.admin.wiki.deletePage('WikiTwo')
 
+    def test_getPageHTMLWithImage(self):
+        # Create the wiki page (absolute image reference)
+        self.admin.wiki.putPage('ImageTest',
+                        '[[Image(wiki:ImageTest:feed.png, nolink)]]\n', {})
+        # Create attachment
+        image_url = os.path.join(rpc_testenv.trac_src, 'trac',
+                             'htdocs', 'feed.png')
+        self.admin.wiki.putAttachmentEx('ImageTest', 'feed.png', 'test image',
+            xmlrpclib.Binary(open(image_url, 'r').read()))
+        # Check rendering absolute
+        markup_1 = self.admin.wiki.getPageHTML('ImageTest')
+        self.assertEquals('<html><body><p>\n<img src="http://127.0.0.1:8765'
+                '/raw-attachment/wiki/ImageTest/feed.png" alt="test image" '
+                'title="test image" />\n</p>\n</body></html>', markup_1)
+        # Change to relative image reference and check again
+        self.admin.wiki.putPage('ImageTest',
+                        '[[Image(feed.png, nolink)]]\n', {})
+        markup_2 = self.admin.wiki.getPageHTML('ImageTest')
+        self.assertEquals(markup_2, markup_1)
+
+
 def test_suite():
     return unittest.makeSuite(RpcWikiTestCase)
 

trunk/tracrpc/wiki.py

 
 from trac.attachment import Attachment
 from trac.core import *
+from trac.mimeview import Context
 from trac.resource import Resource, ResourceNotFound
 from trac.wiki.api import WikiSystem
 from trac.wiki.model import WikiPage
-from trac.wiki.formatter import wiki_to_html
+from trac.wiki.formatter import wiki_to_html, format_to_html
 
 from tracrpc.api import IXMLRPCHandler, expose_rpc, Binary
 from tracrpc.util import StringIO, to_utimestamp, from_utimestamp
     def getPageHTML(self, req, pagename, version=None):
         """ Return page in rendered HTML, latest version. """
         text = self.getPage(req, pagename, version)
-        html = wiki_to_html(text, self.env, req, absurls=1)
+        resource = Resource('wiki', pagename, version)
+        context = Context.from_request(req, resource, absurls=True)
+        html = format_to_html(self.env, context, text)
         return '<html><body>%s</body></html>' % html
 
     def getAllPages(self, req):