#
# Patch for ViewVC to allow the magic identifiers in ViewVC interface.
#

--- viewvc-1.0.0-orig/lib/viewvc.py
+++ viewvc-1.0.0/lib/viewvc.py
@@ -970,10 +970,38 @@
 # addresses.  Note that the regexps assume the text is already HTML-encoded.
 _re_rewrite_url = re.compile('((http|https|ftp|file|svn|svn\+ssh)(://[-a-zA-Z0-9%.~:_/]+)((\?|\&amp;)([-a-zA-Z0-9%.~:_]+)=([-a-zA-Z0-9%.~:_])+)*(#([-a-zA-Z0-9%.~:_]+)?)?)')
 _re_rewrite_email = re.compile('([-a-zA-Z0-9_.\+]+)@(([-a-zA-Z0-9]+\.)+[A-Za-z]{2,4})')
+_re_buglink = re.compile('(BugID:)\s?(\d+)', re.M)
+_re_vcslink = re.compile('(VCS:)\s?([0-9A-Za-z_/\-.]*)', re.M)
+_re_wikilink = re.compile('(Wiki:)\s?([A-Za-z_\-:]*)', re.M)
+
+def bug_linkify(m):
+    url = """<a href="/bugzilla/show_bug.cgi?id=%s">%s</a>"""
+    ref = m.group(1)
+    bug = m.group(2)
+    text = ref + " " + url % (bug, bug)
+    return text
+
+def vcs_linkify(m):
+    url = """<a href="/cgi-bin/viewvc.cgi/%s/">%s</a>"""
+    ref = m.group(1)
+    vcs = m.group(2)
+    text = ref + " " + url % (vcs, vcs)
+    return text
+
+def wiki_linkify(m):
+    url = """<a href="/wiki/index.php/%s">%s</a>"""
+    ref = m.group(1)
+    wiki = m.group(2)
+    text = ref + " " + url % (wiki, wiki)
+    return text
+
 def htmlify(html):
   html = cgi.escape(html)
   html = re.sub(_re_rewrite_url, r'<a href="\1">\1</a>', html)
   html = re.sub(_re_rewrite_email, r'<a href="mailto:\1&#64;\2">\1&#64;\2</a>', html)
+  html = re.sub(_re_buglink, bug_linkify, html)
+  html = re.sub(_re_vcslink, vcs_linkify, html)
+  html = re.sub(_re_wikilink, wiki_linkify, html)
   return html
 
 def format_log(log, cfg):

