Edgewall Software

Ticket #40: interwiki.patch

File interwiki.patch, 2.4 kB (added by bje@…, 4 years ago)

Patch against 0.7.1 to support InterWiki links

  • Wiki.py

     
    5858              r"""(?P<tickethref>#\d+)""", 
    5959              r"""(?P<changesethref>\[\d+\])""", 
    6060              r"""(?P<reporthref>\{\d+\})""", 
    61               r"""(?P<modulehref>((?P<modulename>bug|ticket|browser|source|repos|report|changeset|wiki|search):(?P<moduleargs>(&#34;(.*?)&#34;|'(.*?)')|([^ ]*[^\., \)]))))""", 
    6261              r"""(?P<wikilink>(^|(?<=[^A-Za-z]))[!]?[A-Z][a-z0-9/.]+(?:[A-Z][a-z0-9/.]*[a-z0-9/])+(?=\Z|\s|,|\.|:))""", 
    6362              r"""(?P<fancylink>\[(?P<fancyurl>([a-z]+:[^ ]+)) (?P<linkname>.*?)\])"""] 
    6463 
     
    158157                       '%s:%s#%s' % (module, args, rev), 0 
    159158            else: 
    160159                return self.env.href.browser(args), '%s:%s' % (module, args), 0 
     160        elif self.env.get_config('interwiki', module): 
     161            p = self.env.get_config('interwiki', module) 
     162            return p.replace('$page', args), '%s:%s' % (module, args), 0 
    161163        else: 
    162164            return None, None, 0 
    163165         
     
    180182            return '<a href="%s">%s</a>' % (self.env.href.wiki(match), match) 
    181183 
    182184    def _url_formatter(self, match, fullmatch): 
    183         return '<a href="%s">%s</a>' % (match, match) 
     185        link, text, missing = self._expand_module_link(match) 
     186        if link and missing: 
     187            return '<a class="missing" href="%s">%s?</a>' % (link, text) 
     188        elif link: 
     189            return '<a href="%s">%s</a>' % (link, text) 
     190        else: 
     191            return '<a href="%s">%s</a>' % (match, match) 
    184192 
    185193    def _fancylink_formatter(self, match, fullmatch): 
    186194        link = fullmatch.group('fancyurl') 
     
    203211    """ 
    204212     
    205213    _rules = CommonFormatter._rules + \ 
    206              [r"""(?P<url>([a-z]+://[^ ]+[^\., ]))"""] 
     214             [r"""(?P<url>([a-z]+:[A-Za-z0-9\$\-_@\.\&+\%]+))"""] 
    207215     
    208216    _compiled_rules = re.compile('(?:' + string.join(_rules, '|') + ')') 
    209217 
     
    232240              r"""(?P<list>^(?P<ldepth>\s+)(?:\*|[0-9]+\.) )""", 
    233241              r"""(?P<indent>^(?P<idepth>\s+)(?=\S))""", 
    234242              r"""(?P<imgurl>([a-z]+://[^ ]+)\.(PNG|png|JPG|jpg|JPEG|jpeg|GIF|gif)(\?\S+)?)""", 
    235               r"""(?P<url>([a-z]+://[^ ]+[^\., \)\]\}]))""", 
     243              r"""(?P<url>([a-z]+:[/A-Za-z0-9\$\-_@\.\&+\%]+))""", 
    236244              r"""(?P<last_table_cell>\|\|$)""", 
    237245              r"""(?P<table_cell>\|\|)"""] 
    238246