You don't actually need to write an extension for that; there already is one, called
interhg, which comes with Mercurial.
interhg will look for text in commit messages that match a regex, and use those capture groups to make a URL—which sounds like exactly what you're trying to achieve.
To use it, in your main
Mercurial.ini file, add the lines
and then, in the relevant repository's
.hg/hgrc file, add lines like
fogbugz = s!bugzid: (\\d+)!<a href="http://your.fogbugz.com/?\\1">bugzid: \\1</a>!
adjusting the regex as appropriate. The value to the left of the
= doesn't really matter; all that matters is the substitution pattern on the right. In the case above, the regex looks for
bugzid: # and turns it into a FogBugz link.
Note that Kiln automatically bidirectionally links FogBugz cases to changesets whenever you commit message has any variant of "case 123", "bugzid 123", "review 123", etc., and is generally quite flexible (e.g., "CASES: 123, 456, and 789" will link as expected).