Ticket #278: AllowWikiNames.diff

File AllowWikiNames.diff, 1.5 KB (added by ilias@…, 6 years ago)

Patch which enables menu-selections on wiki names

  • tracnav.py

     
    7070ALLOWED_MACROS = ["image"] 
    7171 
    7272 
     73 
     74# CODE COPIED FROM TRAC PROJECT 
     75# http://trac.edgewall.org/browser/trunk/trac/wiki/api.py?rev=4760#L290 
     76# trac:source/trunk/trac/wiki/api.py?rev=4760#L290 
     77def check_unicode_camelcase(pagename): 
     78    if not pagename[0].isupper(): 
     79        return False 
     80    pagename = pagename.split('@', 1)[0].split('#', 1)[0] 
     81    if not pagename[-1].islower(): 
     82        return False 
     83    humps = 0 
     84    for a, b in pairwise(pagename): 
     85        if a.isupper(): 
     86            if b.islower(): 
     87                humps += 1 
     88            else: 
     89                return False 
     90    return humps > 1 
     91# END CODE COPIED FROM TRAC PROJECT 
     92 
     93#TODO: import the above function instead of duplicating code here 
     94#      currently not possible, as the function is a nested one 
     95#from trac.wiki.api import check_unicode_camelcase 
     96from trac.util import pairwise 
     97 
    7398class TocFormatter(OneLinerFormatter): 
    7499    """ 
    75100    Basically the OneLinerFormatter, but additionally remembers the 
     
    80105        self.lastlink = None 
    81106 
    82107    def format_toc(self, wikitext): 
     108        if not (wikitext.startswith("[wiki:")): 
     109            if (check_unicode_camelcase(wikitext)): 
     110                wikitext = u"[wiki:%s]" % wikitext 
    83111        self.lastlink = None 
    84112        out = StringIO() 
    85113        OneLinerFormatter.format(self, wikitext, out)