Edgewall Software

Ticket #944: attachment.1073.diff

File attachment.1073.diff, 4.6 KB (added by cboos@…, 19 years ago)

Proposed implementation of the feature

  • trac/Ticket.py

    === trac/Ticket.py
    ==================================================================
     
    401401        self.req.hdf.setValue('title', '#%d (%s)' % (id,ticket['summary']))
    402402        self.req.hdf.setValue('ticket.description.formatted',
    403403                              wiki_to_html(ticket['description'], self.req.hdf,
    404                                            self.env, self.db))
     404                                           self.env, self.db,
     405                                           module=self._name, id=str(id)))
    405406        self.req.hdf.setValue('ticket.opened', time.strftime('%c', time.localtime(int(ticket['time']))))
    406407
    407408        changelog = ticket.get_changelog(self.db)
     
    418419            hdf.setValue('ticket.changes.%d.old' % idx, util.escape(old))
    419420            if field == 'comment':
    420421                hdf.setValue('ticket.changes.%d.new' % idx,
    421                              wiki_to_html(new, self.req.hdf, self.env, self.db))
     422                             wiki_to_html(new, self.req.hdf, self.env, self.db,
     423                                          module=self._name, id=str(id)))
    422424            else:
    423425                hdf.setValue('ticket.changes.%d.new' % idx, util.escape(new))
    424426            idx = idx + 1
  • trac/Wiki.py

    === trac/Wiki.py
    ==================================================================
     
    336336        self.req.hdf.setValue('wiki.page_name', self.page.name)
    337337        self.req.hdf.setValue('wiki.page_source', escape(self.page.text))
    338338        out = StringIO.StringIO()
    339         Formatter(self.req.hdf, self.env,self.db).format(self.page.text, out)
     339        Formatter(self.req.hdf, self.env,self.db, module=self._name, id=self.page.name).format(self.page.text, out)
    340340        self.req.hdf.setValue('wiki.page_html', out.getvalue())
    341341
    342342    def display_txt(self):
  • trac/WikiFormatter.py

    === trac/WikiFormatter.py
    ==================================================================
     
    265265              r"""(?P<imgurl>!?([a-z]+://[^ ]+)\.(PNG|png|JPG|jpg|JPEG|jpeg|GIF|gif)(\?\S+)?)""",
    266266              r"""(?P<url>!?([a-z]+://[^ ]+[^\.,' \)\]\}]))""",
    267267              r"""(?P<last_table_cell>\|\|$)""",
    268               r"""(?P<table_cell>\|\|)"""]
     268              r"""(?P<table_cell>\|\|)""",
     269              r"""(?P<attachmentlink>!?(?P<a_type>img|attachment):(?P<a_file>[^? ]+))"""]
    269270
    270271    _compiled_rules = re.compile('(?:' + string.join(_rules, '|') + ')')
    271272    _processor_re = re.compile('#\!([a-zA-Z0-9/+-]+)')
     
    275276    # RE patterns used by other patterna
    276277    _helper_patterns = ('idepth', 'ldepth', 'hdepth', 'fancyurl',
    277278                        'linkname', 'macroname', 'macroargs', 'inline',
    278                         'modulename', 'moduleargs')
     279                        'modulename', 'moduleargs',
     280                        'a_type', 'a_file')
    279281
    280282    _htmlproc_disallow_rule = re.compile('(?i)<(script|noscript|embed|object|iframe|frame|frameset|link|style|meta|param|doctype)')
    281283
     284    def __init__(self, hdf, env, db, absurls=0, module=None, id=None):
     285        CommonFormatter.__init__(self, hdf, env, db, absurls)
     286        self.module = module
     287        self.id = id
     288
    282289    def default_processor(hdf, text, env):
    283290        return '<pre class="wiki">' + util.escape(text) + '</pre>'
    284291    def asp_processor(hdf, text, env):
     
    374381    def _imgurl_formatter(self, match, fullmatch):
    375382        return '<img src="%s" alt="%s" />' % (match, match)
    376383
     384    def _attachmentlink_formatter(self, match, fullmatch):
     385        if match[0] != '!':
     386            type = fullmatch.group('a_type')
     387            file = fullmatch.group('a_file')
     388            format = None
     389            if type == 'img':
     390                return '<img src="%s" alt="%s" />' % (
     391                    self._href.attachment(self.module, self.id, file, 'raw'), file)
     392            else:
     393                return '<a href="%s" title="%s">%s</a>' % (
     394                    self._href.attachment(self.module, self.id, file), file, match)
     395
    377396    def _indent_formatter(self, match, fullmatch):
    378397        depth = int((len(fullmatch.group('idepth')) + 1) / 2)
    379398        list_depth = len(self._list_stack)
     
    587606        self.close_list()
    588607
    589608
    590 def wiki_to_html(wikitext, hdf, env, db, absurls=0):
     609def wiki_to_html(wikitext, hdf, env, db, absurls=0, module=None, id=None):
    591610    out = StringIO.StringIO()
    592     Formatter(hdf, env, db, absurls).format(wikitext, out)
     611    Formatter(hdf, env, db, absurls, module, id).format(wikitext, out)
    593612    return out.getvalue()
    594613
    595614def wiki_to_oneliner(wikitext, hdf, env, db,absurls=0):