=== trac/Ticket.py
==================================================================
--- trac/Ticket.py  (revision 1140)
+++ trac/Ticket.py  (local)
@@ -401,7 +401,8 @@
         self.req.hdf.setValue('title', '#%d (%s)' % (id,ticket['summary']))
         self.req.hdf.setValue('ticket.description.formatted',
                               wiki_to_html(ticket['description'], self.req.hdf,
-                                           self.env, self.db))
+                                           self.env, self.db,
+                                           module=self._name, id=str(id)))
         self.req.hdf.setValue('ticket.opened', time.strftime('%c', time.localtime(int(ticket['time']))))
 
         changelog = ticket.get_changelog(self.db)
@@ -418,7 +419,8 @@
             hdf.setValue('ticket.changes.%d.old' % idx, util.escape(old))
             if field == 'comment':
                 hdf.setValue('ticket.changes.%d.new' % idx,
-                             wiki_to_html(new, self.req.hdf, self.env, self.db))
+                             wiki_to_html(new, self.req.hdf, self.env, self.db,
+                                          module=self._name, id=str(id)))
             else:
                 hdf.setValue('ticket.changes.%d.new' % idx, util.escape(new))
             idx = idx + 1
=== trac/Wiki.py
==================================================================
--- trac/Wiki.py  (revision 1140)
+++ trac/Wiki.py  (local)
@@ -336,7 +336,7 @@
         self.req.hdf.setValue('wiki.page_name', self.page.name)
         self.req.hdf.setValue('wiki.page_source', escape(self.page.text))
         out = StringIO.StringIO()
-        Formatter(self.req.hdf, self.env,self.db).format(self.page.text, out)
+        Formatter(self.req.hdf, self.env,self.db, module=self._name, id=self.page.name).format(self.page.text, out)
         self.req.hdf.setValue('wiki.page_html', out.getvalue())
 
     def display_txt(self):
=== trac/WikiFormatter.py
==================================================================
--- trac/WikiFormatter.py  (revision 1140)
+++ trac/WikiFormatter.py  (local)
@@ -265,7 +265,8 @@
               r"""(?P<imgurl>!?([a-z]+://[^ ]+)\.(PNG|png|JPG|jpg|JPEG|jpeg|GIF|gif)(\?\S+)?)""",
               r"""(?P<url>!?([a-z]+://[^ ]+[^\.,' \)\]\}]))""",
               r"""(?P<last_table_cell>\|\|$)""",
-              r"""(?P<table_cell>\|\|)"""]
+              r"""(?P<table_cell>\|\|)""",
+              r"""(?P<attachmentlink>!?(?P<a_type>img|attachment):(?P<a_file>[^? ]+))"""]
 
     _compiled_rules = re.compile('(?:' + string.join(_rules, '|') + ')')
     _processor_re = re.compile('#\!([a-zA-Z0-9/+-]+)')
@@ -275,10 +276,16 @@
     # RE patterns used by other patterna
     _helper_patterns = ('idepth', 'ldepth', 'hdepth', 'fancyurl',
                         'linkname', 'macroname', 'macroargs', 'inline',
-                        'modulename', 'moduleargs')
+                        'modulename', 'moduleargs',
+                        'a_type', 'a_file')
 
     _htmlproc_disallow_rule = re.compile('(?i)<(script|noscript|embed|object|iframe|frame|frameset|link|style|meta|param|doctype)')
 
+    def __init__(self, hdf, env, db, absurls=0, module=None, id=None):
+        CommonFormatter.__init__(self, hdf, env, db, absurls)
+        self.module = module
+        self.id = id
+
     def default_processor(hdf, text, env):
         return '<pre class="wiki">' + util.escape(text) + '</pre>'
     def asp_processor(hdf, text, env):
@@ -374,6 +381,18 @@
     def _imgurl_formatter(self, match, fullmatch):
         return '<img src="%s" alt="%s" />' % (match, match)
 
+    def _attachmentlink_formatter(self, match, fullmatch):
+        if match[0] != '!':
+            type = fullmatch.group('a_type')
+            file = fullmatch.group('a_file')
+            format = None
+            if type == 'img':
+                return '<img src="%s" alt="%s" />' % (
+                    self._href.attachment(self.module, self.id, file, 'raw'), file)
+            else:
+                return '<a href="%s" title="%s">%s</a>' % (
+                    self._href.attachment(self.module, self.id, file), file, match)
+
     def _indent_formatter(self, match, fullmatch):
         depth = int((len(fullmatch.group('idepth')) + 1) / 2)
         list_depth = len(self._list_stack)
@@ -587,9 +606,9 @@
         self.close_list()
 
 
-def wiki_to_html(wikitext, hdf, env, db, absurls=0):
+def wiki_to_html(wikitext, hdf, env, db, absurls=0, module=None, id=None):
     out = StringIO.StringIO()
-    Formatter(hdf, env, db, absurls).format(wikitext, out)
+    Formatter(hdf, env, db, absurls, module, id).format(wikitext, out)
     return out.getvalue()
 
 def wiki_to_oneliner(wikitext, hdf, env, db,absurls=0):
