def to_wiki_format(site, title, ignore_ns=False):
    """Convert a page title or username to 'canonical' wiki format.

    Wiki format uses spaces instead of underscores, and capitalizes the first
    letter. It also uses custom (not canonical) namespace names. The first
    parameter should be a Pywikibot Site object, and is used to look up
    namespace names.
    """
    def _format(title):
        title = title.replace("_", " ")
        return (title[0].upper() + title[1:]) if title else ""

    if ":" in title and not ignore_ns:
        ns_name, base_name = title.split(":", 1)
        if ns_name in site.namespaces:
            ns_name = site.namespaces[ns_name].custom_name
            return ns_name + ":" + _format(base_name)
    return _format(title)