Christian Boos avatar Christian Boos committed 6747a7a

Merge fix for #10196 from 0.12-stable

Comments (0)

Files changed (3)

trac/wiki/formatter.py

                    escape(match)
 
     def _make_intertrac_link(self, ns, target, label):
+        res = self.get_intertrac_url(ns, target)
+        if res:
+            return self._make_ext_link(res[0], label, res[1])
+
+    def get_intertrac_url(self, ns, target):
         intertrac = self.env.config['intertrac']
         url = intertrac.get(ns + '.url')
         if not url and ns == 'trac':
             url = 'http://trac.edgewall.org'
         if url:
-            name = intertrac.get(ns+'.title', 'Trac project %s' % ns)
-            compat = intertrac.getbool(ns+'.compat', 'false')
+            name = intertrac.get(ns + '.title', 'Trac project %s' % ns)
+            compat = intertrac.getbool(ns + '.compat', 'false')
             # set `compat` default to False now that 0.10 is widely used
             # TODO: remove compatibility code completely for 1.0 release
             if compat:
                 title = _('%(target)s in %(name)s', target=target, name=name)
             else:
                 title = name
-            return self._make_ext_link(url, label, title)
-        else:
-            return None
+            return (url, title)
 
     def shorthand_intertrac_helper(self, ns, target, label, fullmatch):
         if fullmatch: # short form

trac/wiki/macros.py

 from trac.util.datefmt import format_date, from_utimestamp, user_time
 from trac.util.html import escape, find_element
 from trac.util.presentation import separated
-from trac.util.text import unquote, to_unicode
+from trac.util.text import unicode_quote, unquote, to_unicode
 from trac.util.translation import _, dgettext, cleandoc_
 from trac.wiki.api import IWikiMacroProvider, WikiSystem, parse_args
 from trac.wiki.formatter import format_to_html, format_to_oneliner, \
         attr = {}
         style = {}
         link = ''
+        # helper for the special case `source:`
+        #
+        from trac.versioncontrol.web_ui import BrowserModule
+        # FIXME: somehow use ResourceSystem.get_known_realms()
+        #        ... or directly trac.wiki.extract_link
+        try:
+            browser_links = [res[0] for res in
+                             BrowserModule(self.env).get_link_resolvers()]
+        except Exception:
+            browser_links = []
         while args:
             arg = args.pop(0).strip()
             if size_re.match(arg):
             # use href, but unquote to allow args (use default html escaping)
             raw_url = url = desc = unquote(formatter.href(filespec))
         elif len(parts) == 3:                 # realm:id:attachment-filename
+            #                                 # or intertrac:realm:id 
             realm, id, filename = parts
-            attachment = Resource(realm, id).child('attachment', filename)
+            intertrac_target = "%s:%s" % (id, filename)
+            it = formatter.get_intertrac_url(realm, intertrac_target)
+            if it:
+                url, desc = it
+                raw_url = url + unicode_quote('?format=raw')
+            else:
+                attachment = Resource(realm, id).child('attachment', filename)
         elif len(parts) == 2:
-            # FIXME: somehow use ResourceSystem.get_known_realms()
-            #        ... or directly trac.wiki.extract_link
-            from trac.versioncontrol.web_ui import BrowserModule
-            try:
-                browser_links = [res[0] for res in
-                                 BrowserModule(self.env).get_link_resolvers()]
-            except Exception:
-                browser_links = []
-            if parts[0] in browser_links:   # source:path
+            realm, filename = parts
+            if realm in browser_links:   # source:path
                 # TODO: use context here as well
-                realm, filename = parts
                 rev = None
                 if '@' in filename:
-                    filename, rev = filename.split('@')
+                    filename, rev = filename.rsplit('@', 1)
                 url = formatter.href.browser(filename, rev=rev)
                 raw_url = formatter.href.browser(filename, rev=rev,
                                                  format='raw')

trac/wiki/tests/macros.py

 </p>
 ------------------------------
 [[Image(...)]]
+============================== intertrac:source: Image, no other arguments
+[[Image(trac:source:/trunk/doc/images/bkgnd_pattern.png)]]
+------------------------------
+<p>
+<a style="padding:0; border:none" href="http://trac.edgewall.org/intertrac/source%3A/trunk/doc/images/bkgnd_pattern.png"><img src="http://trac.edgewall.org/intertrac/source%3A/trunk/doc/images/bkgnd_pattern.png%3Fformat%3Draw" alt="source:/trunk/doc/images/bkgnd_pattern.png in Trac's Trac" title="source:/trunk/doc/images/bkgnd_pattern.png in Trac's Trac" /></a>
+</p>
+------------------------------
+[[Image(...)]]
 ============================== source: Image, nolink
 [[Image(source:test.png, nolink)]]
 ------------------------------
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.