"""
    MoinMoin - SecureInclude  macro

    This macro will do an include of the given page if the user has permission
    to view it. If the user has no permissions, nothing will be displayed. The
    page is displayed in a light-grey background with a dotted border to help
    indicate to the user they are viewing "internal information". By default
    a header is placed above the section saying
        "Internal - Internal - Internal"
    This can be overridden in the wikiconfig.py by setting the
    'SecureIncludeBanner' variable

    Example usage: <<SecureInclude(PageName)>>

    @license: GNU GPL, see COPYING for details.
    @author: Andy Doan <andy.doan@linaro.org>
"""

from MoinMoin import wikiutil
from MoinMoin.macro import Include

divfmt = """
<style type="text/css">
div.SecureInclude {border: 1px dashed; background-color: #F3F5F7; }
h2.SecureInclude {text-align: center; font-style: italic; font-size: 12pt; color: #aaaaaa;}
</style>
<div class="SecureInclude">
<h2 class="SecureInclude">%s</h2>
%s
</div>
"""

def macro_SecureInclude(macro, page):

    banner = 'Internal - Internal - Internal'
    banner = getattr(macro.request.cfg, 'SecureIncludeBanner', banner)

    html = Include.execute(macro, page)
    if not html:
    	#the user does not have permission
	return ""

    return macro.formatter.rawHTML(divfmt % (banner, html))
