def make_info_page(data, preview=False):
    """
    Given a data entry from a make_info output, create a file description page.

    This includes the template and any formatted categories.

    Preview mode adds the final filename to the top of the page and makes the
    categories visible instead of categorising the page.

    @param data: dict with the keys {cats, meta_cats, info, filename}
    @param preview: if output should be done in preview mode
    @return: str
    """
    # handle categories
    separator = '\n\n'  # standard separation before categories
    cats_as_text = ''

    if data['meta_cats']:
        cats_as_text += separator
        cats_as_text += '<!-- Metadata categories -->\n'
        cats_as_text += '\n'.join(sorted(
            ['[[Category:{}]]'.format(cat) for cat in data.get('meta_cats')]))

    if data['cats']:
        cats_as_text += separator
        cats_as_text += '<!-- Content categories -->\n'
        cats_as_text += '\n'.join(sorted(
            ['[[Category:{}]]'.format(cat) for cat in data.get('cats')]))

    if preview:
        text = 'Filename: {filename}.<ext>\n{template}{cats}'.format(
            filename=data['filename'],
            template=data['info'],
            cats=cats_as_text.replace('[[Category:', '* [[:Category:')
                             .replace('<!-- ', "''")
                             .replace(' -->', ":''"))
    else:
        text = '{template}{cats}'.format(
            template=data['info'],
            cats=cats_as_text)

    return text.strip()