#macro (contentIcon $content)
    #contentIconWithLinkPrefix($content $staticResourceUrlPrefix)
#end

#macro (contentIconWithLinkPrefix $content $prefix)
    #if ($content.type == "page")
    #if ($content.homePage)<img src="$prefix/images/icons/home_16.gif" height="16" width="16" border="0" align="absmiddle" title="$webwork.htmlEncode($content.title) ($action.getText('space.home.page'))"/>
    #elseif ($remoteUser && $content.isRecentlyUpdatedFor($remoteUser))<img src="$prefix/images/icons/new_16.gif" height="16" width="16" border="0" align="absmiddle" title="$webwork.htmlEncode($content.title) ($action.getText('updated.name'))"/>
    #else<img src="$prefix/images/icons/docs_16.gif" height="16" width="16" border="0" align="absmiddle" title="$webwork.htmlEncode($content.title)"/>
    #end
    #elseif ($content.type == "comment") <img src="$prefix/images/icons/comment_16.gif" height="16" width="16" border="0" align="absmiddle"/>
    #elseif ($content.type == "spacedesc")<img src="$prefix/images/icons/web_16.gif" height="16" width="16" border="0" align="absmiddle" title="$webwork.htmlEncode($content.space.name)"/>
    #elseif ($content.type == "personalspacedesc")<img src="$prefix/images/icons/personal_space_16.gif" height="16" width="16" border="0" align="absmiddle" title="$webwork.htmlEncode($content.space.name)"/>
    #elseif ($content.type == "userinfo")<img src="$prefix/images/icons/user_16.gif" height="16" width="16" border="0" align="absmiddle" title="$webwork.htmlEncode($action.getUserFullName($content.username))"/>
    #elseif ($content.type == "blogpost")<img src="$prefix/images/icons/blogentry_16.gif" height="16" width="16" border="0" align="absmiddle" title="$webwork.htmlEncode($content.title)"/>
    #elseif ($content.type == "trackback")<img src="$prefix/images/icons/document_exchange.gif" height="16" width="16" border="0" align="absmiddle" title="$content.title"/>
    #elseif ($content.type == "mail")<img src="$prefix/images/icons/mail_content_16.gif" height="16" width="16" border="0" align="absmiddle" title="$content.title"/>
    #elseif ($content.type == "attachment")#set ($attachment = $content)#parse ("/pages/includes/attachment_icon.vm")#end
#end

#macro (contentIcon2 $content $linkColor $linkHref $linkTitle)
    #if($content.type == "page")
    #if($content.homePage)<a $linkColor href="$linkHref" title="$linkTitle"><img src="$staticResourceUrlPrefix/images/icons/home_16.gif" height="16" width="16" border="0" align="absmiddle" title="$webwork.htmlEncode($content.title) ($action.getText('space.home.page'))"/></a>
    #elseif($remoteUser && $content.isRecentlyUpdatedFor($remoteUser))<a $linkColor href="$linkHref" title="$linkTitle"><img src="$staticResourceUrlPrefix/images/icons/new_16.gif" height="16" width="16" border="0" align="absmiddle" title="$webwork.htmlEncode($content.title) ($action.getText('updated.name'))"/></a>
    #else<a $linkColor href="$linkHref" title="$linkTitle"><img src="$staticResourceUrlPrefix/images/icons/docs_16.gif" height="16" width="16" border="0" align="absmiddle" title="$webwork.htmlEncode($content.title)"/></a>
    #end
    #elseif($content.type == "comment")<a $linkColor href="$linkHref" title="$linkTitle"><img src="$staticResourceUrlPrefix/images/icons/comment_16.gif" height="16" width="16" border="0" align="absmiddle"/></a>
    #elseif($content.type == "spacedesc")<a $linkColor href="$linkHref" title="$linkTitle"><img src="$staticResourceUrlPrefix/images/icons/web_16.gif" height="16" width="16" border="0" align="absmiddle" title="$webwork.htmlEncode($content.space.name)"/></a>
    #elseif($content.type == "personalspacedesc")<a $linkColor href="$linkHref" title="$linkTitle"><img src="$staticResourceUrlPrefix/images/icons/personal_space_16.gif" height="16" width="16" border="0" align="absmiddle" title="$webwork.htmlEncode($content.space.name)"/></a>
    #elseif($content.type == "userinfo")<a $linkColor href="$linkHref" title="$linkTitle"><img src="$staticResourceUrlPrefix/images/icons/user_16.gif" height="16" width="16" border="0" align="absmiddle" title="$webwork.htmlEncode($action.getUserFullName($content.username))"/></a>
    #elseif($content.type == "blogpost")<a $linkColor href="$linkHref" title="$linkTitle"><img src="$staticResourceUrlPrefix/images/icons/blogentry_16.gif" height="16" width="16" border="0" align="absmiddle" title="$webwork.htmlEncode($content.title)"/></a>
    #elseif($content.type == "trackback")<a $linkColor href="$linkHref" title="$linkTitle"><img src="$staticResourceUrlPrefix/images/icons/document_exchange.gif" height="16" width="16" border="0" align="absmiddle" title="$webwork.htmlEncode($content.title)"/></a>
    #elseif($content.type == "mail")<a $linkColor href="$linkHref" title="$linkTitle"><img src="$staticResourceUrlPrefix/images/icons/mail_content_16.gif" height="16" width="16" border="0" align="absmiddle" title="$webwork.htmlEncode($content.title)"/></a>
    #elseif($content.type == "status")<a $linkColor href="$linkHref" title="$linkTitle"><img src="$staticResourceUrlPrefix/images/icons/quotes.png" height="16" width="16" border="0" align="absmiddle" title="$webwork.htmlEncode($content.title)"/></a>
    #elseif($content.type == "attachment")#set ($attachment = $content)#parse ("/pages/includes/attachment_icon.vm")#end#end

#macro (typeIcon $type)
    #if ($type == "page")
        <img src="$staticResourceUrlPrefix/images/icons/docs_16.gif" height="16" width="16" border="0" align="absmiddle" />
    #elseif ($type == "comment")
        <img src="$staticResourceUrlPrefix/images/icons/comment_16.gif" height="16" width="16" border="0" align="absmiddle"/>
    #elseif ($type == "spacedesc")
        <img src="$staticResourceUrlPrefix/images/icons/web_16.gif" height="16" width="16" border="0" align="absmiddle" />
    #elseif ($type == "personalspacedesc")
        <img src="$staticResourceUrlPrefix/images/icons/personal_space_16.gif" height="16" width="16" border="0" align="absmiddle" />
    #elseif ($type == "userinfo")
        <img src="$staticResourceUrlPrefix/images/icons/user_16.gif" height="16" width="16" border="0" align="absmiddle" />
    #elseif ($type == "blogpost")
        <img src="$staticResourceUrlPrefix/images/icons/blogentry_16.gif" height="16" width="16" border="0" align="absmiddle" />
    #elseif ($type == "attachment")
        <img src="$staticResourceUrlPrefix/images/icons/attachments/file.gif" height="16" width="16" border="0" align="absmiddle" />
    #elseif ($type == "mail")
        <img src="$staticResourceUrlPrefix/images/icons/mail_content_16.gif" height="16" width="16" border="0" align="absmiddle" />
	#elseif ($type == "all")
		<img src="$staticResourceUrlPrefix/images/icons/list_pages_16.gif" height="16" width="16" border="0" align="absmiddle" />
	#end
#end

<!-- this macro draws a icon with the specified width. This saves us from specifying the img tag over and over again -->
#macro (icon $imageName $size $title)<img src="$staticResourceUrlPrefix/images/icons/${imageName}" height="$size" width="$size" border="0" align="absmiddle" #if($title != '')title="$title"#end/>#end

#macro (contentHref $content)
    #contentHrefWithLinkPrefix($content $req.contextPath)
#end

#macro (contentHrefWithLinkPrefix $content $prefix)
    #if ($content.type == "attachment")
        <a href="$prefix$content.content.urlPath">$webwork.htmlEncode($content.content.displayTitle)</a> &gt;
        <a href="$prefix$content.downloadPath">$webwork.htmlEncode($content.displayTitle)</a>
    #elseif ($content.type == "comment")
        <a href="$prefix$content.page.urlPath">$webwork.htmlEncode($content.page.displayTitle)</a> &gt;
        <a href="$prefix$content.urlPath">$webwork.htmlEncode($content.displayTitle)</a>
    #else
        <a href="$prefix$content.urlPath">$webwork.htmlEncode($content.displayTitle)</a>
    #end
#end

#macro (contentOther $content)
    #if ($content.type == "page" || $content.type == "blogpost")
        #if ($content.originalVersion)
            <span class="smalltext">v. $content.version ($webwork.htmlEncode($content.originalVersion.space.name))</span>
        #else
            <span class="smalltext">($webwork.htmlEncode($content.space.name))</span>
        #end
    #elseif ($content.type == "comment")
        <span class="smalltext">($webwork.htmlEncode($content.page.space.name))</span>
    #elseif ($content.type == "userinfo")
        <span class="smalltext">($content.username)</span>
    ## If the attachment is attached to a profile, the container text is different (CONF-4465)
    #elseif ($content.type == "attachment" && $content.content.type == "userinfo")
        <span class="smalltext">($content.content.username)</span>
    #elseif ($content.type == "attachment")
        <span class="smalltext">($webwork.htmlEncode($content.content.space.name))</span>
    #end
#end

#macro (contentLink2 $content $showIcon $showSpace)
    #contentLink2WithLinkPrefix($content $showIcon $showSpace $req.contextPath)
#end

#macro (contentLink2WithLinkPrefix $content $showIcon $showSpace $baseUrl)
    #if ($showIcon) #contentIconWithLinkPrefix($content $staticResourceUrlPrefix) #end
    #contentHrefWithLinkPrefix($content $baseUrl)
    #if ($showSpace) #contentOther($content) #end
#end

#macro (contentLink $content)
    #contentLink2($content true true)
#end

#macro (contentLinkWithLinkPrefix $content $prefix)
    #contentLink2WithLinkPrefix($content true false $prefix)
#end

#macro (contentLinkWithAnchor $content $anchor)
    #contentIcon($content)
    <a #if ($textUtil.stringSet($anchor)) name="$anchor" #end href="$req.contextPath$content.urlPath">$webwork.htmlEncode($content.displayTitle)</a>
#end

#* this can only be used with page titles that are safe to append to a URL *#
#* must check existance of page before $permissionCheckDispatcher, otherwise dispatcher will throw an IllegalStatementException *#
#macro (includePage $spaceKey $pageTitle)
    #if ($generalUtil.isAllAscii($pageTitle))
        #if ($renderBean.pageExists($spaceKey, $pageTitle))
            #if ($permissionCheckDispatcher.isPermitted("/pages/viewpage.action?spaceKey=$spaceKey&title=$pageTitle"))
                $renderBean.render($spaceKey, $pageTitle)
            #else
                <span class="error"><span class="errorMessage">$action.getText('insufficient.privelages.to.view.page')</span></span>
            #end
        #else
            <span class="error"><span class="errorMessage">$action.getText('page.not.found.error')</span></span>
        #end
    #else
        <span class="error"><span class="errorMessage">$action.getText('includepage.macro.only.ascii')</em></span></span>
    #end
#end

#macro (includePageWithId $pageId)
    #if ($renderBean.pageExists($pageId))
        #if ($permissionCheckDispatcher.isPermitted("/pages/viewpage.action?pageId=$pageId"))
            $renderBean.render($pageId)
        #else
            <span class="error"><span class="errorMessage">$action.getText('insufficient.privelages.to.view.page')</span></span>
        #end
    #else
        <span class="error"><span class="errorMessage">$action.getText('page.not.found.error')</span></span>
    #end
#end

#*
Link to a user's profile page, given their username. If the username doesn't exist, "Anonymous" is printed
*#
#macro (usernameLink $username)
#trim()
#if ("$!username" != "")
    #set($linkClasses = "url fn")
    #if($permissionHelper.canView($action.remoteUser, $action.getUser($username)))
        #set($linkClasses = "confluence-userlink username:$generalUtil.urlEncode($username) $linkClasses")
    #end
    #if ($action.getUserFullName($username))<a class="$linkClasses" href="$!req.contextPath/display/~$generalUtil.doubleUrlEncode($username)">$generalUtil.htmlEncode($action.getUserFullName($username))</a>#else<a href="$!req.contextPath/display/~$generalUtil.doubleUrlEncode($username)">$username</a>#end
    #else
        $action.getText('anonymous.name')
    #end
#end
#end

#macro (usernameLinkWithCustomBaseUrl $username $baseurl)
    #if ("$!username" != "")
        #if ($action.getUserFullName($username))<a href="$baseurl/display/~$generalUtil.doubleUrlEncode($username)">$generalUtil.htmlEncode($action.getUserFullName($username))</a>#else<a href="$baseurl/display/~$generalUtil.doubleUrlEncode($username)">$username</a>#end
    #else
        $action.getText('anonymous.name')
    #end
#end

#macro (usernameLinkParentWindow $username)
    #if ($username)
        <a href="javascript:window.opener.location='$!req.contextPath/display/~$generalUtil.doubleUrlEncode($username)'; window.close();">$generalUtil.htmlEncode($action.getUserFullName($username))</a>
    #else
        $action.getText('anonymous.name')
    #end
#end

#macro (emailUserLink $user $baseurl)
    #if ($user)
        <a href="$baseurl/display/~$generalUtil.doubleUrlEncode($user.name)">$generalUtil.htmlEncode($user.fullName)</a>
    #else
        $action.getText('anonymous.name')
    #end
#end

#macro (userNonLink $user)
#if($user && $user.name)$generalUtil.htmlEncode($action.getUserFullName($user.name))#else $action.getText('anonymous.name') #end
#end

#macro (fullNameOrAnonymous $user)#if ($user && $user.fullName)$user.fullName#else$action.getText('anonymous.name')#end#end

#macro (siteTitle)$settingsManager.globalSettings.siteTitle#end

#macro (paginationBase $paginationSupport $actionContext $showTotal)
    #requireResource("confluence.web.resources:pagination-styles")

    #set ($numberToShow = 7)

    #set ($previousIndexes = $paginationSupport.previousStartIndexes)
    #set ($nextIndexes = $paginationSupport.nextStartIndexes)

    <div class="pagination">
        #if( $paginationSupport.total > 0 )
            #set ($startIndex = $paginationSupport.startIndex + 1)
            #if ($showTotal)
                #set ($endPageNumber = $paginationSupport.total / $paginationSupport.countOnEachPage)
                #if( $paginationSupport.total % $paginationSupport.countOnEachPage != 0)
                #set ($endPageNumber = $endPageNumber + 1)
                #end



                #set ($endIndex  = $endPageNumber  * $paginationSupport.countOnEachPage)
                #set ($endIndex  = $endIndex  - $paginationSupport.countOnEachPage)

            #end
        #end
        <ul class="pagination">
        #if( $previousIndexes || $nextIndexes )

            #if($previousIndexes)
                #set ($startPageNumber = $generalUtil.arraySize($previousIndexes) - $numberToShow + 1)
                <li><a class="pagination-prev" href="${actionContext}startIndex=$paginationSupport.previousIndex">$action.getText('previous.name')</a></li>
            #end

            #set ($currentIndex = 1)

            #if ($previousIndexes && $startPageNumber > 0)
                <li><a href="${actionContext}startIndex=0">$currentIndex</a></li>

                #if ($startPageNumber > 1)
                        <li class="pagination-hellip">&hellip;</li>
                #end
            #end

            #if( $previousIndexes )
                #foreach( $index in $previousIndexes )
                    #if ($velocityCount > $startPageNumber)
                        <li><a href="${actionContext}startIndex=$index">$currentIndex</a></li>
                    #end
                    #set ($currentIndex = $currentIndex + 1)
                #end
            #end

            <li><strong class="pagination-curr">$currentIndex</strong></li>

            #if( $nextIndexes )
                #set ($lastNumberShown = $currentIndex)
                #foreach( $index in $nextIndexes )
                    #set ($currentIndex = $currentIndex + 1)
                    #if ($velocityCount < $numberToShow)
                        <li><a href="${actionContext}startIndex=$index">$currentIndex</a></li>
                        #set ($lastNumberShown = $lastNumberShown + 1)
					#elseif (!$showTotal && $velocityCount == $numberToShow)
                        <li class="pagination-hellip">&hellip;</li>
                    #end
                #end

                #if ($showTotal && $lastNumberShown < $endPageNumber)
                    #if ($lastNumberShown < $endPageNumber - 1)
                        <li class="pagination-hellip">&hellip;</li>
                    #end
                    <li><a href="${actionContext}startIndex=$endIndex">$endPageNumber</a></li>
                #end

                <li><a class="pagination-next" href="${actionContext}startIndex=$paginationSupport.nextIndex">$action.getText('next.name')</a></li>
            #end
        #end
        </ul>
    </div>
#end

#*
Prints the search result pagination info.
*#

#macro(pagination $paginationSupport $actionContext)
    #paginationBase($paginationSupport $actionContext true)
#end

#*
Prints the search result pagination info. for a pager object (i.e. with total size unknown).
*#

#macro(entityPagination $paginationSupport $actionContext)
    #paginationBase($paginationSupport $actionContext false)
#end


#*
    Prints the breadcrumbs
*#
#macro(breadcrumbs)
    $!sitemeshPage.getProperty("page.breadcrumbs")
#end

#macro(usernavbar)
    #if ($bootstrap.isSetupComplete())
        <ul id="user-control-panel">
        #if ($user)
            <li class="first">$action.getText('welcome.user', [$generalUtil.htmlEncode($user.fullName), $generalUtil.personalSpaceUrl($req.contextPath, $user.name)])</li>

            #set($webMenu = $webMenuManager.getMenu("user-menu-link", "system.user.concise", $action.webInterfaceContext))
            #if(!$webMenu.isEmpty())
                #foreach ($section in $webMenu.sections)
                    #foreach ($item in $section.items)
                        <li><a #if ($item.link.id) id="$item.link.id"#end href="$item.link.getDisplayableUrl($req, $helper)" #if ($context == $item.key)#end>$item.label.getDisplayableLabel($req, $helper)</a></li>
                    #end
                #end
            #end
        #else
            ##  for the login link, we want it to carry the current page the user is viewing anonymously, so that once they login they will be taken back
            ##  to this page. However, we do not want to do this if they are on the logout/signup page/forgot password pages

            <li class="first"><a href="$seraph.getLinkLoginURL($req)">$action.getText('login.name')</a></li>

            #if (!$settingsManager.getGlobalSettings().isExternalUserManagement())
                #if (!$settingsManager.getGlobalSettings().isDenyPublicSignup())
                <li><a href="$req.contextPath/signup.action">$action.getText('sign.up')</a></li>
                #end
            #end
        #end
        </ul>
    #end
#end

#macro(helpicon)
    <a href="$action.getText('url.confluence.atlassian')$action.getText('urlsuffix.doc.space')" title="$action.getText('get.help.from.confluence.website')" class="help icon">$action.getText('get.help.from.confluence.website')</a>
#end

#macro(printableicon)
    <a href="$generalUtil.escapeXml($req.requestURI)?#if ($textUtil.stringSet($req.queryString))$generalUtil.escapeXml(${req.queryString})&#end
decorator=printable" rel="nofollow" title="$action.getText('view.printable.version.of.page')" class="print icon">$action.getText('view.printable.version.of.page')</a>
#end

#macro(pdficon)
    #if (!$sitemeshPage.getProperty("page.suppressPdfLink"))
        #set ($pageId = $sitemeshPage.getProperty("page.pageId"))

            #if ($sitemeshPage && $req && $pageId != 0 && $permissionCheckDispatcher.isPermitted("/spaces/flyingpdf/pdfpageexport.action?pageId=$pageId&amp;${xsrfTokenGenerator.xsrfTokenName}=${xsrfTokenGenerator.generateToken($req)}"))
                <a href="$req.contextPath/spaces/flyingpdf/pdfpageexport.action?pageId=$pageId&amp;${xsrfTokenGenerator.xsrfTokenName}=${xsrfTokenGenerator.generateToken($req)}" rel="nofollow" title="$action.getText('export.as.pdf')" class="pdf icon">$action.getText('export.as.pdf')</a>
            ##$staticResourceUrlPrefix/images/icons/attachments/pdf.gif
        #end
    #end
#end

#macro(feedicon)
    #if ($sitemeshPage.getProperty("page.feedurl"))
        <a href="$req.contextPath$sitemeshPage.getProperty('page.feedurl')" rel="nofollow" title="Atom Feed" class="feed icon">Atom Feed</a>
        ##$staticResourceUrlPrefix/images/icons/feed-icon-16x16.png
    #end
#end

#macro(pagetitle $class)
    #if ($bootstrap.isSetupComplete() && $sitemeshPage.getProperty("page.spacename"))
        <div class="$class">#if ($sitemeshPage.getProperty("page.spacekey"))<a href="$req.contextPath/display/$sitemeshPage.getProperty("page.spacekey")">#end<img src="#logo($sitemeshPage.getProperty("page.spacekey"))" align="absmiddle" border="0">#if ($sitemeshPage.getProperty("page.spacekey"))</a>#end $sitemeshPage.getProperty("page.spacename")</div>
    #else
        <div class="$class"><a href="$req.contextPath/"><img src="$staticResourceUrlPrefix/images/confluence_logo.gif" border="0"></a> <a href="$req.contextPath/">CONFLUENCE</a></div>
    #end
#end

## deprecated - used only in old footer.vmd
#macro(bottomshadow)
        #if ($generalUtil.isSetupComplete())
            #set ($license = $licenseManager.getLicense("CONF") )
            #if ($license && $license.licenseType.niceName != "Confluence: Commercial Server")
                #if ($license.licenseType.niceName == "Confluence: Evaluation")
                    <p class="license license-eval">
                      <strong>#if ($generalUtil.isLicenseExpired()) LICENSE EXPIRED #else EVALUATION LICENSE #end</strong> &#8212; $action.getText('consider.purchasing',[$action.getText('url.atlassian'),$action.getText('hitcounter.consider.purchasing')])
                    </p>
                #elseif ($license.licenseType.niceName == "Confluence: Non-Profit / Open Source")
                    <p class="license license-nonprofit">
                    $action.getText('licensefooter.nonprofit',[$action.getText('url.atlassian'),$action.getText('hitcounter.nonprofit'), $license.organisation])
                    </p>
                #elseif ($license.licenseType.niceName == "Confluence: Personal Server")
                    <p class="license license-personal">
                      $action.getText('licensefooter.personal',[$action.getText('url.atlassian'),$action.getText('hitcounter.personal')])<br>
                    </p>
                #elseif ($license.licenseType.niceName == "Confluence: Community")
                    <p class="license license-community">
                      $action.getText('licensefooter.community',[$action.getText('url.atlassian'), $action.getText('hitcounter.community'), $license.organisation])<br>
                    </p>
                #elseif ($license.licenseType.niceName == "Confluence: Open Source")
                    <p class="license license-opensource">
                      $action.getText('licensefooter.opensource',[$action.getText('url.atlassian'), $action.getText('hitcounter.opensource'), $license.organisation])<br>
                    </p>
                #elseif ($license.licenseType.niceName == "Confluence: Developer")
                    <p class="license license-developer">
                      $action.getText('licensefooter.developer')<br>
                    </p>
                #elseif ($license.licenseType.niceName == "Confluence: Demonstration")
                    <p class="license license-demonstration">
                      $action.getText('licensefooter.demonstration', [$action.getText('url.atlassian'), $action.getText('hitcounter.demonstration')])<br>
                    </p>
                #end
            #elseif (!$license)
                <p class="license license-none">
                   $action.getText('licensing.error', [$action.getText('mailto.confluence.support')])
                </p>
            #end
        #end
#end

## deprecated - used only in old footer.vmd
#macro(poweredby)
    <ul id="poweredby">
        <li>$action.getText('powered.by.atlassian.confluence',[$action.getText('url.atlassian.software.confluence.footer'), "$generalUtil.versionNumber","${generalUtil.buildNumber}", "${generalUtil.buildDateString}"])</li>
        <li><a href="$action.getText('url.bug.feature.request')" class="smalltext">$action.getText('bug.feature.request')</a> &#8211;</li>
        <li><a href="$action.getText('url.footer.atlassian.news')" class="smalltext">$action.getText('footer.atlassian.news')</a> &#8211;</li>
        <li><a href="$req.contextPath/administrators.action">$action.getText('contact.administrators')</a></li>
    </ul>
#end

## deprecated - use breadcrumbs.vm
#macro(dashboardlink)
    #if ($req.getRequestURI().indexOf("dashboard.action") != -1)
        $action.getText("dashboard.name")
    #else
        <a href="$req.contextPath/dashboard.action">$action.getText("dashboard.name")</a>
    #end
#end

## deprecated - use breadcrumbs.vm
#macro (peopledirectorylink)
    <a href="$req.contextPath/peopledirectory.action">$action.getText('people.directory.name')</a>
#end

#macro (colourRow $name $colour $isDefault)
    <tr>
        <td nowrap width="40%" align="right"><strong>$action.getText($name)</strong></td>
        <td width="30"><div style="background-color: $colour; width: 30; border: 1px solid black">&nbsp;</div></td>
        <td><span class="monospaceInput">#if($isDefault)&lt;$action.getText('default')&gt;#else$colour#end</span></td>
    </tr>
#end

#macro (trackbackRdf $identifier $title $ping)
<!--
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:dc="http://purl.org/dc/elements/1.1/"
         xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
         #set($escapedId = $generalUtil.rdfEncode($identifier) )
         #set($escapedTitle = $generalUtil.rdfEncode($title) )
<rdf:Description
    rdf:about="$escapedId"
    dc:identifier="$escapedId"
    dc:title="$escapedTitle"
    trackback:ping="$ping"/>
</rdf:RDF>
-->
#end

#macro (onoff $test)
    #if ($test) <span class="on-label">$action.getText('on.name')</span> #else <span class="off-label">$action.getText('off.name')</span> #end
#end

#macro (yesno $test)
    #if ($test) <span class="yes-label">$action.getText('yes.name.caps')</span> #else <span class="no-label">$action.getText('no.name.caps')</span> #end
#end

## Expects a javascript function as a variable which can be excecuted in this script.
#macro (fielderrorExecuteFunction $fieldname $javascriptFunction)
    #set ($fieldErrors = $action.fieldErrors)
    #if ($fieldErrors)
      #if ($fieldErrors.get($fieldname))
          #foreach ($error in $fieldErrors.get($fieldname))
          <div class="error"><span class="errorMessage">
              <script>
                  $javascriptFunction
              </script>
            #set( $message = $action.getText(${error}) )
            #if( $message && $message != "" )
              $message
            #else
              $error
            #end
          </span></div>
          #end
      #end
    #end
#end

#macro (fielderror $fieldname)
    #set ($fieldErrors = $action.fieldErrors)
    #if ($fieldErrors)
      #if ($fieldErrors.get($fieldname))
          #foreach ($error in $fieldErrors.get($fieldname))
          <div id="${fieldname}-error" class="error"><span class="errorMessage">
            #set( $message = $action.getText(${error}) )
            #if( $message && $message != "" )
              $message
            #else
              $error
            #end
          </span></div>
          #end
      #end
    #end
#end

#macro (fielderrorRow $fieldname)
    #set ($fieldErrors = $stack.findValue("fieldErrors"))
    #if ($fieldErrors)
        #if ($fieldErrors.get($fieldname))
            #foreach ($error in $fieldErrors.get($fieldname))
                <tr>
                <td colspan="2" class="error"><span class="errorMessage">
                #set( $message = $i18n.getText($error) )
                #if( $message && $message != "" )
                  $message
                #else
                  $error
                #end
                </span></td>
                </tr>
            #end
        #end
    #end
#end



#*
    Sets up variables which are used to determine whether or not the help panel
    should be displayed.
*#

#macro(infoPanelInit)
    #if ($sitemeshPage.getProperty("meta.help-path"))
      #set ($helpPath = $sitemeshPage.getProperty("meta.help-path"))
    #end

    #if ($sitemeshPage.getProperty("page.help-content"))
      #set ($helpContent = $sitemeshPage.getProperty("page.help-content"))
    #end

    ## decide whether or not to include the right nav bar
    #if ($helpPath || $helpContent)
      #set ($helpAvailable = true)
    #end

    #if ($sitemeshPage.getProperty("meta.infopanel-width"))
      #set ($panelWidth = $sitemeshPage.getProperty("meta.infopanel-width"))
    #end

    #set ($infoPanelRequired = $helpAvailable)
#end

#*
    Sets up variables which are used to determine whether or not the help panel
    should be displayed, using the parameter object passed by the inline decorator
    directive: applyDecorator
*#

#macro(infoPanelInitFromParams)
    #if ($params.get("help-path"))
      #set ($helpPath = $params.get("help-path"))
    #end

    #if ($params.get("help-content"))
      #set ($helpContent = $params.get("help-content"))
    #end

    ## decide whether or not to include the right nav bar
    #if ($helpPath || $helpContent)
      #set ($helpAvailable = true)
    #end

    #if ($params.get("infopanel-width"))
      #set ($panelWidth = $params.get("infopanel-width"))
    #end

    #set ($infoPanelRequired = $helpAvailable)
#end

#* A header which will probably create a very ugly page but one suitable for when a user has to fix
   something urgently before Confluence will be in a good state e.g. renew license before upgrade
   tasks can run.
*#
#macro(fixonlyHeader)
    #if (!$sitemeshPage.getProperty("page.allowindex"))
        <meta name="robots" content="noindex,nofollow">
        <meta name="robots" content="noarchive">
    #end
    #if ($req.getAttribute("Confluence-Request-Time"))
        <meta name="confluence-request-time" content="$!req.getAttribute("Confluence-Request-Time")">
    #end
    #favicon()
#end

## deprecated since 2.8, parse header.vm instead
#macro(standardHeaderWithStylesheetAction $stylesheetAction)
    #parse ("/decorators/includes/header.vm")
#end

## deprecated since 2.8, parse header.vm instead
#macro(standardHeader)
    #standardHeaderWithStylesheetAction("main")
#end

## deprecated since 2.8, parse header.vm instead, setting stylesheetAction var to 'admin'
#macro(standardHeaderForAdmin)
    #standardHeaderWithStylesheetAction("admin")
#end

#macro(rssautodiscovery $rssDescriptor)
    #if($rssDescriptor)
        <content tag="rssautodiscovery">
        <link rel="alternate" type="application/rss+xml"
            title="RSS $!action.rssDescriptor.title"
            href="$req.contextPath$action.rssDescriptor.rssHref" />
        <link rel="alternate" type="application/atom+xml"
            title="ATOM $!action.rssDescriptor.title"
            href="$req.contextPath$action.rssDescriptor.atomHref" />
        </content>
        <content tag="feedurl">$action.rssDescriptor.atomHref</content>
    #end
#end

#macro(displayGlobalMessages $spaceKey)
    #set ($messages = $messageManager.getMessages($spaceKey, $username))
    #if ($messages && $messages.size() > 0)
        <ul id="messageContainer">
        #foreach ($message in $messages)
            #if ($message.isVisible())
                <li id="confluence-message-${message.id}" class="confluence-messages $message.cssClass">
                    #if ($message.isClosable()) <img class="message-close-button" src="$staticResourceUrlPrefix/images/icons/close_16.gif" title="$action.getText('close.name')">#end
                    $message.text
                </li>
            #end
        #end
        </ul>
    #end
#end

#macro(infoPanel $incomingLinks $trackbacks $referrers $externalReferences)
<div id="info-panel" class="rightpanel">
  #if ($helpAvailable)
      <h3 id="helpheading">$action.getText('help.tips')</h3>
      <div id="helpcontent">
          #if ($helpContent)
              $sitemeshPage.getProperty("page.help-content")
          #else
              #parse ($helpPath)
          #end
      </div>
  #else
      #if ($hasPageOperations)
          #if ($sitemeshPage.getProperty("page.operations.title"))
              <div class="menuheading">$sitemeshPage.getProperty("page.operations.title")</div>
          #else
              <div class="menuheading">$action.getText('operations.word')</div>
          #end
          <div class="menuitems">
              $!sitemeshPage.getProperty("page.operations")
              $!sitemeshPage.getProperty("page.incoming-links")
              $!sitemeshPage.getProperty("page.trackbacks")
              $!sitemeshPage.getProperty("page.referrers")
              $!sitemeshPage.getProperty("page.external-references")
          </div>
      #end
  #end
</div>
#end

#macro (nameList $names)
    #set($user = "")
    #foreach ($user in $names)
        #if ($velocityCount == $names.size())
            #usernameLink ($user)
        #else
            #usernameLink($user),
        #end
        #set($user = "")
    #end
#end

#* Put this macro back in for backward compatability
 * Use the blogPostsCalendarWithArrows from now on (it puts the correct arrows links whereas this one doesn't see CONF-6779)
 *#
#macro (blogPostsCalendar $cal)
    <table id="blogcalendar" class="blogcalendar" border="0" cellspacing="0" cellpadding="2" summary="$action.getText('monthly.calander.with.links.to.news.items')">
           <tr>
               <th class="calendarhead">
                   #if ($cal.lastPostInPreviousMonth)
                   <a href="$req.contextPath/display/$cal.spaceKey/$cal.previousMonth/" rel="nofollow"><span class="backArrow"><span>&lt;&lt;</span></span></a>
                   #else &nbsp; #end
               </th>
               <th class="calendarhead" colspan="5" align="center"><a class="calendarhead" href="$req.contextPath/display/$cal.spaceKey/$cal.currentMonth/">$cal.formatMonthYear()</a></th>
               <th class="calendarhead">
                   #if ($cal.firstPostInNextMonth)
                   <a href="$req.contextPath/display/$cal.spaceKey/$cal.nextMonth" rel="nofollow"><span class="fwdArrow"><span>&gt;&gt;</span></span></a>
                   #else &nbsp; #end
               </th>
           </tr>
           <tr>
               <th abbr="Sunday" align="center">$action.getText('sunday.abbr')</th>
               <th abbr="Monday" align="center">$action.getText('monday.abbr')</th>
               <th abbr="Tuesday" align="center">$action.getText('tuesday.abbr')</th>
               <th abbr="Wednesday" align="center">$action.getText('wednesday.abbr')</th>
               <th abbr="Thursday" align="center">$action.getText('thursday.abbr')</th>
               <th abbr="Friday" align="center">$action.getText('friday.abbr')</th>
               <th abbr="Saturday" align="center">$action.getText('saturday.abbr')</th>
           </tr>

        #set ( $weeks = ($cal.getDaysInMonth() + $cal.startingDayOfMonth)/7 )
        #foreach ( $week in [0..$weeks] )
           <tr>
           #foreach ($day in [1..7] )
              <td align="center">
              #set ($date = $week * 7 + $day - $cal.startingDayOfMonth)
              #if ($date < 1 || $date > $cal.getDaysInMonth())
                  &nbsp;
              #elseif ($cal.getPostsForDay($date).size() == 0)
                  $date
              #else
                  #set ($thePost = $cal.getPostsForDay($date).get(0))
                  <a href="$req.contextPath/display/$thePost.space.key/$thePost.datePath/">$date</a>
              #end
              </td>
           #end
           </tr>
        #end
    </table>
#end

#* Passes in the action and a flag to display the correct arrow links to blogs:
 *   true = link to the next/prev DATE post, with blog post date displayed
 *   false = link to the next/prev post, with blog post title displayed
 *#
#macro (blogPostsCalendarWithDateLinks $action $datePostArrows)

    #set ($cal = $action.calendarForThisMonth)

    <table class="blogcalendar" border="0" cellspacing="0" cellpadding="2" summary="$action.getText('monthly.calander.with.links.to.news.items')">
           <tr>
               <th class="calendarhead">
                   #if ($cal.lastPostInPreviousMonth)
                   <a href="$req.contextPath/display/$cal.spaceKey/$cal.previousMonth/" rel="nofollow"><img src="$staticResourceUrlPrefix/images/icons/back_16.gif" height=16 width=16 border=0 align=absmiddle title="$action.getText('previous.month')"></a>
                   #else &nbsp; #end
               </th>
               <th class="calendarhead" colspan="5" align="center"><a class="calendarhead" href="$req.contextPath/display/$cal.spaceKey/$cal.currentMonth/">$cal.formatMonthYear()</a></th>
               <th class="calendarhead">
                   #if ($cal.firstPostInNextMonth)
                   <a href="$req.contextPath/display/$cal.spaceKey/$cal.nextMonth" rel="nofollow"><img src="$staticResourceUrlPrefix/images/icons/forwd_16.gif" height=16 width=16 border=0 align=absmiddle title="$action.getText('next.month')"></a>
                   #else &nbsp; #end
               </th>
           </tr>
           <tr>
               <th abbr="Sunday" align="center">$action.getText('sunday.abbr')</th>
               <th abbr="Monday" align="center">$action.getText('monday.abbr')</th>
               <th abbr="Tuesday" align="center">$action.getText('tuesday.abbr')</th>
               <th abbr="Wednesday" align="center">$action.getText('wednesday.abbr')</th>
               <th abbr="Thursday" align="center">$action.getText('thursday.abbr')</th>
               <th abbr="Friday" align="center">$action.getText('friday.abbr')</th>
               <th abbr="Saturday" align="center">$action.getText('saturday.abbr')</th>
           </tr>

        #set ( $weeks = ($cal.getDaysInMonth() + $cal.startingDayOfMonth)/7 )
        #foreach ( $week in [0..$weeks] )
           <tr>
           #foreach ($day in [1..7] )
              <td align="center">
              #set ($date = $week * 7 + $day - $cal.startingDayOfMonth)
              #if ($date < 1 || $date > $cal.getDaysInMonth())
                  &nbsp;
              #elseif ($cal.getPostsForDay($date).size() == 0)
                  $date
              #else
                  #set ($thePost = $cal.getPostsForDay($date).get(0))
                  <a href="$req.contextPath/display/$thePost.space.key/$thePost.datePath/">$date</a>
              #end
              </td>
           #end
           </tr>
        #end
    </table><br/>

    #if ($datePostArrows)
        #if ($action.nextDatePost || $action.previousDatePost)
            #if ($action.nextDatePost && $permissionCheckDispatcher.isPermitted("/pages/viewblogposts.action?pageId=$action.nextDatePost.id") )
                <a href="$req.contextPath/display/$action.nextDatePost.space.key/$action.nextDatePost.datePath/"><img src="$staticResourceUrlPrefix/images/icons/forwd_16.gif" height=16 width=16 border=0 align=absmiddle title="Next Post"></a>
                <a href="$req.contextPath/display/$action.nextDatePost.space.key/$action.nextDatePost.datePath/">$generalUtil.format($action.nextDatePost.creationDate)</a><br/>
            #end
            #if ($action.previousDatePost && $permissionCheckDispatcher.isPermitted("/pages/viewblogposts.action?pageId=$action.previousDatePost.id") )
                <a href="$req.contextPath/display/$action.previousDatePost.space.key/$action.previousDatePost.datePath/"><img src="$staticResourceUrlPrefix/images/icons/back_16.gif" height=16 width=16 border=0 align=absmiddle title="Previous Post"></a>
                <a href="$req.contextPath/display/$action.previousDatePost.space.key/$action.previousDatePost.datePath/">$generalUtil.format($action.previousDatePost.creationDate)</a><br/>
            #end
            <br />
        #end
    #else
        #if ($action.nextPost || $action.previousPost)
             #if ($action.nextPost && $permissionCheckDispatcher.isPermitted("/pages/viewpage.action?pageId=$action.nextPost.id") )
                 <a href="$req.contextPath$generalUtil.getPageUrl($action.nextPost)"><img src="$staticResourceUrlPrefix/images/icons/forwd_16.gif" height=16 width=16 border=0 align=absmiddle title="Next Post"></a>
                 <a href="$req.contextPath$generalUtil.getPageUrl($action.nextPost)">$action.nextPost.title</a><br/>
             #end

             #if ($action.previousPost && $permissionCheckDispatcher.isPermitted("/pages/viewpage.action?pageId=$action.previousPost.id") )
                 <a href="$req.contextPath$generalUtil.getPageUrl($action.previousPost)"><img src="$staticResourceUrlPrefix/images/icons/back_16.gif" height=16 width=16 border=0 align=absmiddle title="Previous Post"></a>
                 <a href="$req.contextPath$generalUtil.getPageUrl($action.previousPost)">$action.previousPost.title</a><br/>
             #end
             <br />
         #end
    #end
#end

#* passes the url to the permissionDispatcher first. if user has permissions to see link, this macro will display it
 * $url: the url of the action. You must drop the contextPath off the url before passing it in here.
 * $linkTextKey: the i18n key for the name of the link
 *#
#macro (confluenceLink $url $linkTextKey)
    #if ($permissionCheckDispatcher.isPermitted($url))
        <a href="$req.contextPath/$url">$action.getText($linkTextKey)</a>
    #end
#end

#macro (confluenceLink2 $url $linkTextKey $prefix $suffix)
    #if ($permissionCheckDispatcher.isPermitted($url))
        $prefix <a href="$req.contextPath/$url">$action.getText($linkTextKey)</a> $suffix
    #end
#end

#macro (showPermissionsHeader)
        <tr>
            <th class="permissionHeading" width="25%">&nbsp;</th>
            <th class="permissionHeading">&nbsp;</th>
            <th colspan=4 class="permissionSuperTab">$action.getText('perms.pages')</th>
            <th colspan=2 class="permissionSuperTab">$action.getText('perms.news')</th>
            <th colspan=2 class="permissionSuperTab">$action.getText('perms.comments')</th>
            <th colspan=2 class="permissionSuperTab">$action.getText('perms.attachments')</th>
            <th class="permissionSuperTab">$action.getText('perms.mail')</th>
            <th colspan=2 class="permissionSuperTab">$action.getText('perms.space')</th>
        </tr>
        <tr>
            <th class="permissionHeading">&nbsp;</th>
            <th width="40" class="permissionSuperTab">$action.getText('perms.view')</th>
            <th width="40" class="permissionTab">$action.getText('perms.create')</th>
            <th width="40" class="permissionTab">$action.getText('perms.export')</th>
            <th width="40" class="permissionTab">$action.getText('perms.restrict')</th>
            <th width="40" class="permissionTab">$action.getText('perms.remove')</th>
            <th width="40" class="permissionTab">$action.getText('perms.create')</th>
            <th width="40" class="permissionTab">$action.getText('perms.remove')</th>
            <th width="40" class="permissionTab">$action.getText('perms.create')</th>
            <th width="40" class="permissionTab">$action.getText('perms.remove')</th>
            <th width="40" class="permissionTab">$action.getText('perms.create')</th>
            <th width="40" class="permissionTab">$action.getText('perms.remove')</th>
            <th width="40" class="permissionTab">$action.getText('perms.remove')</th>
            <th width="40" class="permissionTab">$action.getText('perms.export')</th>
            <th width="40" class="permissionTab">$action.getText('perms.admin')</th>
        </tr>
#end

#*
 * shows header for a global permissions table
 *#
#macro (showGlobalPermissionsHeader)
        <tr>
            <th width="230" class="permissionHeading">&nbsp;</th>
            <th width="120" class="permissionHeading">&nbsp;</th>
            <th width="88" class="permissionTab">$action.getText("permissions.PROFILEATTACHMENTS")</th>
            #if ($action.userStatusPluginEnabled)
            <th width="88" class="permissionTab">$action.getText("permissions.UPDATEUSERSTATUS")</th>
            #end
            <th width="88" class="permissionTab">$action.getText("permissions.PERSONALSPACE")</th>
            <th width="88" class="permissionTab">$action.getText("permissions.CREATESPACE")</th>
            <th width="88" class="permissionTab">$action.getText("permissions.ADMINISTRATECONFLUENCE")</th>
            <th width="88" class="permissionTab">$action.getText("permissions.SYSTEMADMINISTRATOR")</th>
        </tr>
#end

#*
 * Macro for getting the URL of a resource from within a themed decorator
 *#

#macro (themeResource $resourcePath)$req.contextPath$sitemeshPage.getProperty("theme.resource.path")$resourcePath#end

#*
 * This macro is quite messy but is neater than simply copying and pasting the HTML three times on two different
 * screens to represent view and edit views of permissions for groups, users, and anonymous entities.
 *
 * Note - this macro renders form elements when in edit mode but you must wrap it in a form element yourself.
 *
 * $who: list containing the following symbols - "g" (group), "u" (user), "a" (anonymous), "e" (everyone).
 * Each symbol is a directive to print out symbolized information in the order in which the symbols are expressed.
 * Note - "e" is actually ["g", "u", "a"]
 *
 * $action: an object carry functionality to support calls for group, user, and anonymous permissions; for example
 * com.atlassian.confluence.security.actions.EditSpacePermissionsAction .
 *
 * $edit: string literal; if set to "true" it will output input boxes for each permission listing, otherwise it will
 * use a tick or cross image for read-only.
 *#
#macro (showPermissions $who $action $edit )

    #if ($who == ["e"])
        #set ($who = ["g", "u", "a"])
    #end

    #foreach( $entity in $who )
       <table id="${entity}PermissionsTable" border="0" cellpadding=2 cellspacing=0 width="100%">

        #if ($entity == "g")
            #set ($groupRows = $action.groupPermissionRows)
            #if (!$groupRows.empty)
                #showPermissionsHeader()

                #foreach ($groupRow in $groupRows)
                    <tr #if($velocityCount % 2 == 0) style="background: #f0f0f0;" #end>
                        <td>
                            <img src="$staticResourceUrlPrefix/images/icons/group_16.gif" width=16 height=16 border=0 align=absmiddle>
                            $generalUtil.htmlEncode($groupRow.groupName)
                            #if (!$groupRow.entityExists())
                                <br/><span class="errorMessage">$action.getText("error.group.not.found")</span>
                            #elseif ($groupRow.caseInvalid)
                                <br/><span class="errorMessage">$action.getText('error.permission.incorrect.case', [$generalUtil.htmlEncode($groupRow.group.name)])</span>
                            #end
                        </td>
                        #foreach ($permission in ["viewspace", "editspace", "exportpage", "setpagepermissions", "removepage", "editblog", "removeblog", "comment", "removecomment", "createattachment", "removeattachment", "removemail", "exportspace", "setspacepermissions"])
                        <td align="center" class="permissionCell" valign="middle">
                            #if ($edit == "true")
                                #if ($groupRow.isTypeAllowed($permission))
                                    <input type="checkbox" name="$groupRow.buildCheckboxParameterName($permission)" checked="checked">
                                    <input type="hidden" name="$groupRow.buildHiddenParameterName($permission)" value="on">
                                #else
                                    <input type="checkbox" name="$groupRow.buildCheckboxParameterName($permission)">
                                #end
                            #else
                                #if ($groupRow.isTypeAllowed($permission))
                                    <img src="$staticResourceUrlPrefix/images/icons/emoticons/check.gif" width=16 height=16 align=absmiddle border=0>
                                #else
                                    <img src="$staticResourceUrlPrefix/images/icons/emoticons/error.gif" width=16 height=16 align=absmiddle border=0>
                                #end
                            #end
                        </td>
                        #end
                    </tr>
                #end
            #else
                <tr><td colspan=5>$action.getText('no.groups.have.access') </td></tr>
            #end
        #end
        #if ($entity == "u")
            #set ($userRows = $action.userPermissionRows)
            #if (!$userRows.empty)
                #showPermissionsHeader()

                #foreach ($userRow in $userRows)

                    <tr #if ($velocityCount % 2 == 0)style="background: #f0f0f0;" #end>
                        <td>
                            <img src="$staticResourceUrlPrefix/images/icons/user_16.gif" width=16 height=16 border=0 align=absmiddle>
                            #if ($userRow.entityExists())
                                $generalUtil.htmlEncode($userRow.user.fullName)
                            #end
                            <span class="grey">($generalUtil.htmlEncode($userRow.username))</span>
                            #if (!$userRow.entityExists())
                                <br/><span class="errorMessage">$action.getText("error.user.not.found")</span>
                            #elseif ($userRow.caseInvalid)
                                <br/><span class="errorMessage">$action.getText('error.permission.incorrect.case', [$generalUtil.htmlEncode($userRow.user.name)])</span>
                            #end
                        </td>
                        #foreach ($permission in ["viewspace", "editspace", "exportpage", "setpagepermissions", "removepage", "editblog", "removeblog", "comment", "removecomment", "createattachment", "removeattachment", "removemail", "exportspace", "setspacepermissions"])
                            <td align="center" class="permissionCell" valign="middle">
                                ## Don't show checkboxes for owners of personal spaces
                                #if ($edit == "true" && !($action.getSpace().getType().toString() == "personal" && $userRow.getUsername() == $action.getSpace().getCreatorName()) )
                                    #if ($userRow.isTypeAllowed($permission))
                                        <input type="checkbox" name="$userRow.buildCheckboxParameterName($permission)" checked="checked">
                                        <input type="hidden" name="$userRow.buildHiddenParameterName($permission)" value="on">
                                    #else
                                        <input type="checkbox" name="$userRow.buildCheckboxParameterName($permission)">
                                    #end
                                #else
                                    #if ($userRow.isTypeAllowed($permission))
                                        <img src="$staticResourceUrlPrefix/images/icons/emoticons/check.gif" width=16 height=16 align=absmiddle border=0>
                                    #else
                                        <img src="$staticResourceUrlPrefix/images/icons/emoticons/error.gif" width=16 height=16 align=absmiddle border=0>
                                    #end
                                #end
                            </td>
                        #end
                    </tr>
                #end

            #else
                <tr><td colspan=5>$action.getText('no.users.have.rights.to.this.space')</td></tr>
            #end
        #end
        #if ($entity == "a")
            #showPermissionsHeader()
            #set ($anonymousRow = $action.anonymousPermissionRow)
            <tr>
                <td>
                    <img src="$staticResourceUrlPrefix/images/icons/group_anyone_16.gif" width=16 height=16 border=0 align=absmiddle>
                    <strong>$action.getText('anonymous.name')</strong>
                </td>
                #foreach ($permission in ["viewspace", "editspace", "exportpage", "setpagepermissions", "removepage", "editblog", "removeblog", "comment", "removecomment", "createattachment", "removeattachment", "removemail", "exportspace", "setspacepermissions"])
                <td align="center" class="permissionCell">
                    #if ($edit == "true")
                        #if ($anonymousRow.isTypeAllowed($permission))
                            <input type="checkbox" name="$anonymousRow.buildCheckboxParameterName($permission)" checked="checked">
                            <input type="hidden" name="$anonymousRow.buildHiddenParameterName($permission)" value="on">
                        #else
                            <input type="checkbox" name="$anonymousRow.buildCheckboxParameterName($permission)">
                        #end
                    #else
                        #if ($anonymousRow.isTypeAllowed($permission))
                            <img src="$staticResourceUrlPrefix/images/icons/emoticons/check.gif" width=16 height=16 align=absmiddle border=0>
                        #else
                            <img src="$staticResourceUrlPrefix/images/icons/emoticons/error.gif" width=16 height=16 align=absmiddle border=0>
                        #end
                    #end
                </td>
            #end
            </tr>
        #end
        </table>
    #end
#end

## use this function in tr's to alternate the row colors when displaying a list of items.
#macro (alternateRowColors)
    #if ($velocityCount % 2 == 0)
        class="rowAlternate"
    #end
#end

#macro (spaceTitleLink)
    #if ($sitemeshPage.getProperty("page.spacename"))
        #if($sitemeshPage.getProperty("page.spacekey"))<a href="$req.contextPath/display/$sitemeshPage.getProperty("page.spacekey")">#end$webwork.htmlEncode($sitemeshPage.getProperty("page.spacename"))#if($sitemeshPage.getProperty("page.spacekey"))</a>#end
    #else
        &nbsp;
    #end
#end

#macro (pageTitleLink)
    #if ($sitemeshPage.getProperty("page.pageTitle"))
        $sitemeshPage.getProperty("page.pageTitle")
    #else
        $title
    #end
#end

#macro (quickSearch)
    <form id="quick-search" class="quick-search" method="get" action="$req.contextPath/dosearchsite.action">
        #set ($quickSearchPlaceholder = $action.getText('search.name'))
        <fieldset>
            <legend>$action.getText('quick.search.legend')</legend>
            <input class="quick-search-query" id="quick-search-query" type="text" accessKey="$action.getTextStrict('search-pages-action.accesskey')" autocomplete="off" name="queryString" size="25" />
            <input class="quick-search-submit" id="quick-search-submit" type="submit" value="$quickSearchPlaceholder" />
        </fieldset>
        <fieldset class="hidden parameters">
            <input type="hidden" class="quickSearchPlaceholder" id="quickSearchPlaceholder" value="$quickSearchPlaceholder" />

            <input type="hidden" id="quickNavEnabled" value="$!settingsManager.globalSettings.enableQuickNav" />
            #if ($settingsManager) <!-- Quick nav disabled. SettingsManager could not be found --> #end
        </fieldset>
    </form>
#end

## Deprecated since 2.8 - Use a web section.
#macro (watchLink )

    #set ($action = $helper.action)

    #if(!$action.anonymousUser && !$action.isPrintableVersion() && $actionErrors.size() == 0)
        #if(!$action.userWatchingSpace)
            #if($action.userWatchingPage)
              #if( $permissionCheckDispatcher.isPermitted("/pages/removepagenotification.action?pageId=$helper.page.id") )
                    <a href="$req.contextPath/pages/removepagenotification.action?pageId=$helper.page.id" title="$action.getText('stop.watching.page')"><img border="0" src="$staticResourceUrlPrefix/images/icons/watch_cancel_16.gif" align="absmiddle"></a>
              #end
            #else
                #if( $permissionCheckDispatcher.isPermitted("/pages/addpagenotification.action?pageId=$helper.page.id") )
                    <a href="$req.contextPath/pages/addpagenotification.action?pageId=$helper.page.id" title="$action.getText('watch.this.page')"><img border="0" src="$staticResourceUrlPrefix/images/icons/watch_16.gif" align="absmiddle"></a>
                #end
            #end
        #else
                    <a href="$req.contextPath/spaces/viewspacecontent.action?key=$helper.spaceKey" title="$action.getText('you.are.currently.watching.space',[$!page.space.name])"><img border="0" src="$staticResourceUrlPrefix/images/icons/add_space_notification_16.gif" align="absmiddle"></a>
        #end
    #end
#end

## Deprecated since 2.8 - Use a web section.
#macro (favouriteLink )

    #set ($action = $helper.action)

    #if(!$action.anonymousUser && !$action.isPrintableVersion() && $actionErrors.size() == 0)
        #if($action.favouritePage)
          #if( $permissionCheckDispatcher.isPermitted("/labels/removefavourite.action?entityId=$helper.page.id") )
                <a href="$req.contextPath/labels/removefavourite.action?entityId=$helper.page.id&#url_xsrfToken()" title="$helper.getText("favourite.remove.page")"><img border="0" src="$staticResourceUrlPrefix/images/icons/star_yellow.gif" width="16" height="16" align="absmiddle"></a>
          #end
        #else
            #if( $permissionCheckDispatcher.isPermitted("/labels/addfavourite.action?entityId=$helper.page.id") )
                <a href="$req.contextPath/labels/addfavourite.action?entityId=$helper.page.id&#url_xsrfToken()" title="$helper.getText("favourite.add.page")"><img border="0" src="$staticResourceUrlPrefix/images/icons/star_grey.gif" width="16" height="16" align="absmiddle"></a>
            #end
        #end
    #end
#end

#*
    Renders an edit link with image, for a blog.
*#
#macro (editBlogPostWithImageLink )

    #set ($page = $helper.page)

   #if ($permissionCheckDispatcher.isPermitted("/pages/editblogpost.action?pageId=$page.id"))
       <a href="$req.contextPath/pages/editblogpost.action?pageId=$page.id"><img border="0" src="$staticResourceUrlPrefix/images/icons/edit_16.gif" align="absmiddle"></a>
       <a href="$req.contextPath/pages/editblogpost.action?pageId=$page.id">Edit</a>
   #end
#end


#macro (renderChildren)
    #set ($page = $helper.page)
    #if ($helper.action.getPermittedChildren().size() > 0 && $page.latestVersion)
        <div id="children-section" class="pageSection">
        #if (!$helper.childrenShowing)
            #set ($extraHeaderClass="summary")
        #end

        <div class="section-header $!extraHeaderClass">
            <h2 id="children-section-title" class="section-title">
                <a name="children">$action.getText("children.count", [$helper.action.getPermittedChildren().size()])</a>
            </h2>
            <span class="noprint">
                &nbsp;
                #if ($helper.childrenShowing)
                    <a id="hide-children-link" class="grey" href="$req.contextPath$generalUtil.customGetPageUrl($page)showChildren=false&#0035;children">$action.getText('hide.children')</a>
                #else
                    <a id="show-children-link" class="grey" href="$req.contextPath$generalUtil.customGetPageUrl($page)showChildren=true&#0035;children">$action.getText('show.children')</a>
                #end

                &nbsp;|&nbsp; <a class="grey" href="$req.contextPath/pages/listpages-dirview.action?key=$page.space.key&amp;openId=$page.id#selectedPageInHierarchy">$action.getText('view.in.hierarchy')</a>
                #if ($page.type == "page" && $permissionHelper.canCreatePage($remoteUser, $space))
                    &nbsp;|&nbsp;
                    <a class="grey" href="$req.contextPath/pages/createpage.action?spaceKey=$generalUtil.urlEncode($space.key)&amp;fromPageId=$page.id">$helper.getText("action.add.page.child")</a>
                #end
            </span>
        </div>
        #if ($helper.childrenShowing)
            <div id="page-children" class="pageSectionBody">
                #foreach ($child in $helper.action.getPermittedChildren())
                    #contentLink2 ($child true false) ## space key after the link is redundant
                    <br>
                #end
            </div>
        #end
        </div>
    #end
#end

#macro (renderComments)
    #applyDecorator("root")
        #decoratorParam("sitemeshPage" $sitemeshPage)
        #decoratorParam("page" $page)
        #decoratorParam("context" "sharedcomments")
    #end
#end

## Deprecated since 2.8. Inline this code.
#macro (renderCommentsWithProfilePics $page $sitemeshPage)
    #applyDecorator("root")
        #decoratorParam("sitemeshPage" $sitemeshPage)
        #decoratorParam("page" $page)
        #decoratorParam("context" "comments")
    #end
#end

## Deprecated sinse 3.0. Use onLoadAttr instead.
#macro (onLoad)
    #if (!$textUtil.stringSet($sitemeshPage.getProperty("page.bodyOnLoad")))
        <body onload="placeFocus()" id="com-atlassian-confluence">
    #else
        <body onload="$sitemeshPage.getProperty('page.bodyOnLoad')" id="com-atlassian-confluence">
    #end
#end

#macro (onLoadAttr)
    #if (!$textUtil.stringSet($sitemeshPage.getProperty("page.bodyOnLoad")))
        onload="placeFocus()"
    #else
        onload="$sitemeshPage.getProperty('page.bodyOnLoad')"
    #end
#end

#macro (versionInfo)
  <div class="version-info noteMacro padded">
        #if ($helper.historicalVersion)
      <img src="$staticResourceUrlPrefix/images/icons/emoticons/warning.gif" align="absmiddle" height=16 width=16> <strong>$action.getText('viewing.old.version',["$page.version"])</strong>
        #else
        <strong>$action.getText('viewing.current.version', ["$page.version"])</strong>
        #end
      <br>
      <div class="smallfont">
          #if ($helper.historicalVersion)
        $action.getText('latest.version.is',["$req.contextPath$generalUtil.getPageUrl($page.originalVersion)","$page.originalVersion.version","$action.dateFormatter.format(${page.originalVersion.lastModificationDate})"])
        (<a href="$req.contextPath/pages/diffpagesbyversion.action?pageId=$page.originalVersion.id&amp;originalVersion=$page.version&amp;revisedVersion=$page.originalVersion.version">$action.getText('view.differences')</a>
        |
        #if ($permissionCheckDispatcher.isPermitted("/pages/revertpagebacktoversion.action?pageId=$page.originalVersion.id&version=${page.version}"))
          <a href="revertpagebacktoversion.action?pageId=$page.originalVersion.id&amp;version=${page.version}">$action.getText('restore.this.version.smalls')</a>
        #end)<br>#end
        #if ($action.hasPreviousVersion($page))
          <a href="$req.contextPath/pages/viewpage.action?pageId=$action.getPageIdOfVersionBefore($page)&amp;navigatingVersions=true">&lt;&lt; $action.getText('view.previous.version')</a> |
        #end
          <a href="$req.contextPath/pages/viewpreviousversions.action?pageId=$page.latestVersion.id">$action.getText('view.page.history.smalls')</a>
        #if ($action.hasNextVersion($page))
          | <a href="$req.contextPath/pages/viewpage.action?pageId=$action.getPageIdOfVersionAfter($page)&amp;navigatingVersions=true">$action.getText('view.next.version') &gt;&gt;</a>
        #end
      </div>
    </div>
#end


#macro (versionComment)
  <div id="versionComment" class="noteMacro" style="display:none; padding: 5px;">
      <strong>$action.getText('comment.name'):</strong>
      $page.renderedVersionComment<br />
  </div>

    <script>
      var show = document.getElementById('show');
      var hide = document.getElementById('hide');
      var versionComment = document.getElementById('versionComment');

      function showComment(){
        show.style.display = 'none';
        hide.style.display = 'inline';
        versionComment.style.display = 'block';
      }

      function hideComment(){
        show.style.display = 'inline';
        hide.style.display = 'none';
        versionComment.style.display = 'none';
      }

    </script>
#end

## Deprecated - use /decorators/includes/page-metadata.vm
#macro (editReport)
    #if ($page.isLatestVersion() == true)
        $action.getText('added.by.user.last.edited.on.date', ["#usernameLink ($page.creatorName)","#usernameLink ($page.lastModifierName)","$action.dateFormatter.format( $page.lastModificationDate )"])
    #else
        $action.getText('added.by.user.edited.on.date', ["#usernameLink ($page.creatorName)","#usernameLink ($page.lastModifierName)","$action.dateFormatter.format( $page.lastModificationDate )"])
    #end
    #if ($page.isLatestVersion())
      #set ($previousPage = $action.getPreviousVersion($page.previousVersion))
      #if ($!previousPage)
        &nbsp;(<a class="noprint" href="$req.contextPath/pages/diffpages.action?pageId=${page.id}&originalId=$previousPage.id">$action.getText('view.change')</a>)
      #end
    #end
    #if ($page.isVersionCommentAvailable())
        <span id="show" class="inline-control-link"><a href="#" onclick="showComment(); return false;">$action.getText('show.comment')</a></span>
        <span id="hide" class="inline-control-link" style="display:none;"><a href="#" onclick="hideComment(); return false;">$action.getText('hide.comment')</a></span>
        #versionComment()
    #end

#end

#macro (labelsWithNone $labels $showNone)
    #if ($labels && !$labels.isEmpty()) #foreach($label in $labels)#if($velocityCount > 1), #end #labelLink($label)#end
    #elseif ($showNone) (None) #end
#end

#*
    Renders a comma seperated list of labels limited by a max amount.
    If there are more than max labels it shows: ... x $message.
*#
#macro (labelsMax $labels $max $message)
    #if ($labels.size() > 0)
    #set($remaining = $labels.size() - $max)
        #foreach($label in $labels)#if($velocityCount <= $max)#if($velocityCount > 1), #end #labelLink($label)#end#end
        #if($remaining > 0)
        ... $remaining $message
        #end
    #end
#end

#macro (labels $labels)
    #labelsWithNone ($labels true)
#end

## Label links shown in the context of a space should take the user to a page that contains content for that space only
## to do this, we need to pull the space key either from the $helper or from the $action.
## The getUrlPath() method on label should be able to handle null/empty spacekeys.
#macro (labelLinkUrl $label)
#trim()
    #if($helper.spaceKey)
        $req.contextPath$label.getUrlPath($helper.spaceKey)
    #else
        $req.contextPath$label.getUrlPath($spaceKey)
    #end
#end
#end

#macro (labelLink $label)<a class="label" rel="nofollow" href="#labelLinkUrl($label)">$generalUtil.htmlEncode($label.realTitle)</a>#end

## Displays the label link without the namespace
#macro (labelLinkBasic $label)<a rel="nofollow" href="#labelLinkUrl($label)">$label.name</a>#end

#macro (labelString $labelable)#if ($labelable.labels.size() > 0) #foreach($label in $labelable.labels)#if($velocityCount > 1), #end$label.name#end#end#end

#macro (mailOperations $helper)

    <div class="menuheading">
        $action.getText('mail.operations')
    </div>
    <div class="menuitems">
        <div class="operations">
            #if ($helper.action.inThread || $helper.action.nextMail || $helper.action.previousMail)
                <ul style="list-style: none;">
                    #if ($helper.action.inThread)
                        <li>
                            <a href="$req.contextPath/spaces/viewthread.action?key=$helper.action.key&id=$helper.action.mail.id" title="$helper.getText("view.mail.thread.title")"><img src="$staticResourceUrlPrefix/images/icons/mail_thread_16.gif" border="0" height=16 width=16 alt="" align="absmiddle"></a>
                            <a href="$req.contextPath/spaces/viewthread.action?key=$helper.action.key&id=$helper.action.mail.id" title="$helper.getText("view.mail.thread.title")"><span class="label">$helper.getText("view.mail.thread.desc")</span></a>
                        </li>
                    #end

                    #if( $helper.action.nextMail && $permissionCheckDispatcher.isPermitted("/spaces/viewmail.action?key=$helper.action.nextMail.space.key&id=$helper.action.nextMail.id"))
                        <li>
                            <a href="${req.contextPath}$helper.action.nextMail.urlPath"><img src="$staticResourceUrlPrefix/images/icons/forwd_16.gif" height=16 width=16 border=0 align=absmiddle title="$generalUtil.escapeXml($helper.action.nextMail.title)"></a><span class="label">
                            <a href="${req.contextPath}$helper.action.nextMail.urlPath" title="$generalUtil.escapeXml($helper.action.nextMail.title)">$helper.getText("next.mail")</a></span>
                        </li>
                    #end

                    #if( $helper.action.previousMail && $permissionCheckDispatcher.isPermitted("/spaces/viewmail.action?key=$helper.action.previousMail.space.key&id=$helper.action.previousMail.id"))
                        <li>
                            <a href="${req.contextPath}$helper.action.previousMail.urlPath"><img src="$staticResourceUrlPrefix/images/icons/back_16.gif" height=16 width=16 border=0 align=absmiddle title="$generalUtil.escapeXml($helper.action.previousMail.title)"></a><span class="label">
                            <a href="${req.contextPath}$helper.action.previousMail.urlPath" title="$generalUtil.escapeXml($helper.action.previousMail.title)">$helper.getText("previous.mail")</a></span>
                        </li>
                    #end
                </ul>
            #end

            <ul style="list-style: none;">
                #if( $mail && $permissionCheckDispatcher.isPermitted("/spaces/removemail.action?key=$mail.space.key&id=$mail.id") )
                    <li>
                        <a href="$req.contextPath/spaces/removemail.action?key=$mail.space.key&id=$mail.id"><img src="$staticResourceUrlPrefix/images/icons/trash_16.gif" height=16 width=16 border=0 align=absmiddle title="$i18n.getText('remove.mail.name')}"></a><span class="label">
                        <a href="$req.contextPath/spaces/removemail.action?key=$mail.space.key&id=$mail.id">$helper.getText("remove.mail.name")</a></span>
                    </li>
                #end

                #if( $permissionCheckDispatcher.isPermitted("/spaces/viewmailarchive.action?key=$mail.space.key") )
                    <li>
                    #if ($mail)
                        <a href="$req.contextPath/spaces/viewmailarchive.action?key=$mail.space.key"><img src="$staticResourceUrlPrefix/images/icons/list_mail_content_16.gif" width="16" height="16" border="0" align="absmiddle" title="$i18n.getText('mail.archive.name')"></a><span class="label">
                        <a href="$req.contextPath/spaces/viewmailarchive.action?key=$mail.space.key">$helper.getText("mail.archive.name")</a></span>
                    #else
                        <a href="$req.contextPath/spaces/viewmailarchive.action?key=$helper.action.key"><img src="$staticResourceUrlPrefix/images/icons/list_mail_content_16.gif" width="16" height="16" border="0" align="absmiddle" title="$i18n.getText('mail.archive.name')"></a><span class="label">
                        <a href="$req.contextPath/spaces/viewmailarchive.action?key=$helper.action.key">$helper.getText("mail.archive.name")</a></span>
                    #end
                    </li>
                #end
            </ul>

        </div>
    </div>
#end


#* ----------------------------------------------- LOGO MACROS ----------------------------------------------- *#

## only returns the image url of the appropriate logo
## this method is deprecated. Use LogoBlock instead, it delegates to newer and more efficient macros.
#macro (logo $spaceKeyOrUsername)
#trim()
	## Firstly, if it's a username, look for user profile picture
	#if ($textUtil.stringSet($spaceKeyOrUsername) && $spaceKeyOrUsername.startsWith("~"))
        ##This may still lead to bugs (VELOCITY-186) but for now I am leaving this unchanged. TODO examine this
        #set ($userProfilePicture = $userAccessor.getUserProfilePicture($spaceKeyOrUsername.substring(1)))
		#if ($userProfilePicture)
			$req.contextPath$userProfilePicture.downloadPath
		#else
			$staticResourceUrlPrefix/images/logo/confluence_48_white.png
		#end

	## Otherwise, it's not a username, so let's check if the space has a set logo
	#elseif ($textUtil.stringSet($spaceKeyOrUsername) && $spaceManager.getSpace($spaceKeyOrUsername) && $attachmentManager.getAttachment($spaceManager.getSpace($spaceKeyOrUsername).description, $spaceKeyOrUsername))
		$generalUtil.htmlEncode("${req.contextPath}$attachmentManager.getAttachment($spaceManager.getSpace($spaceKeyOrUsername).description, $spaceKeyOrUsername).downloadPath")

	## No space logo, let's look for a global logo
	#elseif ($settingsManager.globalDescription && $attachmentManager.getAttachment($settingsManager.globalDescription,"global.logo"))
		#set($attachment=$attachmentManager.getAttachment($settingsManager.globalDescription,"global.logo"))
		$generalUtil.htmlEncode("${req.contextPath}$attachment.downloadPath")

	## No global logo, let's use the default Confluence logo
    #else
		$staticResourceUrlPrefix/images/logo/confluence_48_white.png
    #end

#end
#end

## checks if space preferences to determine if the logo has been disabled, and then displays it.
## include href link just in case we want to customize this part based on some preference in the future (without breaking people's stuff again)
#macro (logoBlock $spaceKeyOrUsername)
#trim()
    #if ($textUtil.stringSet($spaceKeyOrUsername))
		#if ($spaceKeyOrUsername.startsWith("~"))
			#userLogoBlock($spaceKeyOrUsername.substring(1))
		#else
			#spaceLogoBlock($spaceKeyOrUsername)
		#end
	#else
        #globalLogoBlock()
    #end
#end
#end



## private - use #logoBlock.
#macro (spaceLogoBlock $spaceKey)
#trim()
     #if ($settingsManager.getSpaceSettings($spaceKey).isDisableLogo()) ## render nothing
     #else
       #set ($spaceLogo=$spaceManager.getLogoForSpace($spaceKey))
       #set($cssClass="logo")
       #if ($spaceLogo.isCustomLogo())
           #set($cssClass="$cssClass space custom")
       #else
           #set($cssClass="$cssClass global")
           #if ($spaceLogo.isGlobalLogo())
               #set($cssClass="$cssClass custom")
           #end
       #end

       <a href="$req.contextPath/display/$spaceKey"><img class="$cssClass" src="${req.contextPath}$spaceLogo.getDownloadPath()" alt=""></a>

    #end
#end
#end




## private - use #logoBlock
#macro (userLogoBlock $username)
#trim()
   #set ($userProfilePicture=$userAccessor.getUserProfilePicture($username))
    #if($permissionHelper.canView($action.remoteUser, $action.getUser($username)))
        #set($linkClasses = "userLogoLink username:$generalUtil.urlEncode($username)")
    #else
        #set($linkClasses = "")
    #end
     ## if the user profile stil has the default picture, AND the usericon getting displayed is the current user, THEN generate a link to set the profile picture

     #if ($userProfilePicture.isDefault() && "$action.remoteUser.name" == $username)
    <a class="$linkClasses" href="$req.contextPath/users/editmyprofilepicture.action" title="$action.getText("add.a.profile.picture")"><img class="userLogo logo" src="$staticResourceUrlPrefix/images/icons/profilepics/add_profile_pic.png" alt="$action.getText("add.a.profile.picture")"></a>
#else
    ## otherwise, the default case is to display the logo as is

  ## the title is usually the user name, but for the anonymous user we want the proper translation for anonymous users
  #if ($userProfilePicture.isAnonymous())
       <img class="userLogo logo anonymous" src="$staticResourceUrlPrefix/images/icons/profilepics/anonymous.png" alt="" title="$action.getText("user.icon.anonymous.title")">
  #else
       <a class="$linkClasses" href="$req.contextPath/display/~$generalUtil.urlEncode($username)"><img class="userLogo logo" src="$req.contextPath$userProfilePicture.downloadPath" alt="" title="$generalUtil.htmlEncode($username)"></a>
  #end
#end
#end
#end





## private - use #logoBlock.
#macro (globalLogoBlock)
  #trim()
      #if ($settingsManager.getGlobalSettings().isDisableLogo())
      #else
          #set ($globalLogo=$spaceManager.getLogoForGlobalcontext())

          #set ($completeDownloadPath=$generalUtil.htmlEncode("$req.contextPath$globalLogo.getDownloadPath()"))


          #if ($globalLogo.isCustomLogo())
             <a href="$req.contextPath/homepage.action"><img class="global logo custom"  src="$completeDownloadPath" alt=""></a>
          #else
             <a href="$req.contextPath/homepage.action"><img class="global logo"  src="$completeDownloadPath" alt=""></a>
          #end
      #end
  #end
  #end






## shows the user's profile picture if they have one, otherwise _shows nothing_ (not a Confluence logo like logoBlock)
#macro (logoForUserIfExists $username)
    #userLogoBlockOtherwise("~$username" "")
#end

## Render a user logo if not the default one, otherwise evaluate the provided expression
#macro (userLogoBlockOtherwise $username $otherwiseHtml)
    #if (!$generalUtil.isDefaultUserProfilePicture($username.substring(1)) || "~$action.remoteUser.name" == $username)
        #userLogoBlock($username.substring(1))
    #else
        $otherwiseHtml
    #end
#end

#macro (logoForUserOrSpacer $username)
    #userLogoBlockOtherwise("~$username" "#profilePictureSpacer()")
#end

#macro (profilePictureSpacer)
    <img class="userLogo logo anonymous" src="$staticResourceUrlPrefix/images/icons/profilepics/anonymous.png" alt="" title="$action.getText("user.icon.anonymous.title")">
#end

#macro (addProfilePictureHint)
    <a class="userLogoLink" href="$req.contextPath/users/editmyprofilepicture.action" title="$action.getText("add.a.profile.picture")"><img class="userLogo logo" src="$staticResourceUrlPrefix/images/icons/profilepics/add_profile_pic.png" alt="$action.getText("add.a.profile.picture")"></a>
#end

#* DEPRECATED *#
#macro (userLogo $username)
    <a class="userLogoLink" href="$req.contextPath/display/$username"><img class="userLogo logo" src="#logo($username)" alt="" title="$username"></a>
#end

#* ----------------------------------------------- SIMPLE LINK MACROS -----------------------------------------------
 Store macros which render a one line link here.
*#

#macro (tinyLink )
    <a href="$helper.domainName/x/$helper.tinyUrl">$helper.domainName/x/$helper.tinyUrl</a>
#end

#*
    Renders a link and image for removing the current page.
*#
#macro (removePageLinkAndImage )
    <a href="$req.contextPath/pages/removepage.action?pageId=$helper.page.id"><img src="${req.contextPath}/images/icons/trash_16.gif" width="16" height="16" border="0px" align="absmiddle" title="$helper.getText("remove.name")"></a>
#end

#*
    Renders a link and image and text label for removing the current page.
*#
#macro (removePageLinkAndImageAndText )
    #if ($permissionHelper.canRemove($remoteUser, $page))
    <a href="$req.contextPath/pages/removepage.action?pageId=$helper.page.id"><img src="${req.contextPath}/images/icons/trash_16.gif" width="16" height="16" border="0px" align="absmiddle" title="$helper.getText("remove.name")"></a>&nbsp;<a href="$req.contextPath/pages/removepage.action?pageId=$helper.page.id">$helper.getText("remove.page.name")</a>
    #end
#end

#*
    Renders a link for removing the current page.
*#
#macro (removePageLink)
    <a href="$req.contextPath/pages/removepage.action?pageId=$helper.page.id">$action.getText('remove.page.name')</a>
#end

#*
    Renders a link and image and text label for removing the current blogpost.
*#
#macro (removeBlogPostLinkAndImageAndText )
    <a href="$req.contextPath/pages/removeblogpost.action?pageId=$helper.page.id">$helper.getText("remove.news.name")</a>&nbsp;<a href="$req.contextPath/pages/removeblogpost.action?pageId=$helper.page.id"><img src="${req.contextPath}/images/icons/trash_16.gif" width="16" height="16" border="0px" align="absmiddle" title="$helper.getText("remove.name")"></a>
#end

#*
    Renders a link and image for removing the current blogpost.
*#
#macro (removeBlogPostLinkAndImage )
    <a href="$req.contextPath/pages/removeblogpost.action?pageId=$helper.page.id"><img src="${req.contextPath}/images/icons/trash_16.gif" width="16" height="16" border="0px" align="absmiddle" title="$helper.getText("remove.name")"></a>
#end

#*
    Renders a link for removing the current blogpost.
*#
#macro (removeBlogPostLink )
    <a href="$req.contextPath/pages/removeblogpost.action?pageId=$helper.page.id">$action.getText('remove.news.name')</a>
#end

#macro (browseSpaceLinkAndImage)
    #set ($spaceKey = $helper.spaceKey)
    #if (!$spaceKey && $space)
        #set ($spaceKey = $space.key)
    #end

    #if ($permissionCheckDispatcher.isPermitted("/pages/listpages.action?key=$spaceKey"))
        <a href="$req.contextPath/pages/listpages.action?key=$generalUtil.urlEncode($spaceKey)"><img src="$staticResourceUrlPrefix/images/icons/browse_space.gif" height="16" width="16" border="0" align="absmiddle" title="$action.getText('find.content')"></a>
        <a href="$req.contextPath/spaces/browsespace.action?key=$generalUtil.urlEncode($spaceKey)">$action.getText('browse.space')</a>
    #end
#end

#macro (browseSpaceLink)
    #set ($spaceKey = $helper.spaceKey)

    #if ($permissionCheckDispatcher.isPermitted("/pages/listpages.action?key=$spaceKey"))
        <a href="$req.contextPath/spaces/browsespace.action?key=$generalUtil.urlEncode($spaceKey)">$action.getText('browse.space')</a>
    #end
#end

#macro (addPageLinkAndImage)
    #set ($spaceKey = $helper.spaceKey)

    #if ($permissionHelper.canCreatePage($remoteUser, $space))
        ## if user currently viewing a page, add page automatically creates a new page with that page is the parent
        #if ($helper.page.id && !$helper.page.postingDay)
            <a href="$req.contextPath/pages/createpage.action?spaceKey=$generalUtil.urlEncode($spaceKey)&fromPageId=$helper.page.id"><img src="$staticResourceUrlPrefix/images/icons/add_page_16.gif" height=16 width=16 border=0 align=absmiddle title="$action.getText('add.page')"></a>
            <a href="$req.contextPath/pages/createpage.action?spaceKey=$generalUtil.urlEncode($spaceKey)&fromPageId=$helper.page.id">$action.getText('add.page')</a>
        #else
            <a href="$req.contextPath/pages/createpage.action?spaceKey=$generalUtil.urlEncode($spaceKey)"><img src="$staticResourceUrlPrefix/images/icons/add_page_16.gif" height=16 width=16 border=0 align=absmiddle title="$action.getText('add.page')"></a>
            <a href="$req.contextPath/pages/createpage.action?spaceKey=$generalUtil.urlEncode($spaceKey)">$action.getText('add.page')</a>
        #end
    #end
#end

#macro (addPageLink)
    #set ($spaceKey = $helper.spaceKey)

    #if ($permissionHelper.canCreatePage($remoteUser, $space))
        ## if user currently viewing a page, add page automatically creates a new page with that page is the parent
        #if ($helper.page.pageId && !$helper.page.postingDay)
            <a href="$req.contextPath/pages/createpage.action?spaceKey=$generalUtil.urlEncode($spaceKey)&fromPageId=$helper.page.id">$action.getText('add.page')</a>
        #else
            <a href="$req.contextPath/pages/createpage.action?spaceKey=$generalUtil.urlEncode($spaceKey)">$action.getText('add.page')</a>
        #end
    #end
#end


#macro (addNewsLinkAndImage)
    #set ($spaceKey = $helper.spaceKey)

    #if ($permissionHelper.canCreateBlogPost($remoteUser, $space))
        #if ($helper.page.id)
          #set ($fromPageParam = "&fromPageId=$helper.page.id")
        #else
          #set ($fromPageParam = "")
        #end
        <a href="$req.contextPath/pages/createblogpost.action?spaceKey=$generalUtil.urlEncode($spaceKey)$fromPageParam"><img src="$staticResourceUrlPrefix/images/icons/add_blogentry_16.gif" height=16 width=16 border=0 align=absmiddle title="$action.getText('add.news')"></a>
        <a href="$req.contextPath/pages/createblogpost.action?spaceKey=$generalUtil.urlEncode($spaceKey)$fromPageParam">$action.getText('add.news')</a>
    #end
#end

#macro (addNewsLink)
    #set ($spaceKey = $helper.spaceKey)

    #if ($permissionHelper.canCreateBlogPost($remoteUser, $space))
        #if ($helper.page.id)
          #set ($fromPageParam = "&fromPageId=$helper.page.id")
        #else
          #set ($fromPageParam = "")
        #end
        <a href="$req.contextPath/pages/createblogpost.action?spaceKey=$generalUtil.urlEncode($spaceKey)$fromPageParam">$action.getText('add.news')</a>
    #end
#end

#macro (createPersonalSpaceLink)
    #if ($permissionHelper.canCreatePersonalSpace($remoteUser) && $action.viewingMyProfile)
        <a href="$req.contextPath/spaces/createpersonalspace.action">
            <img src="$staticResourceUrlPrefix/images/icons/personal_space_16.gif" height=16 width=16 border=0 align=absmiddle title="$action.getText('create.personal.space')">
            <span>$action.getText('create.personal.space')</span>
        </a>
    #end
#end

#macro (personalSpaceLink)
    #set ( $personalSpaceLink = "$req.contextPath/display/~$!generalUtil.doubleUrlEncode($helper.space.creatorName)" )
    #if ($action.viewingMyProfile)
        <a href="$personalSpaceLink"><img src="$staticResourceUrlPrefix/images/icons/personal_space_16.gif" height="16" width="16" border="0" align="absmiddle" title="$action.getText('your.personal.space')"></a>
        <a href="$personalSpaceLink">$action.getText('your.personal.space')</a>
    #else
        <a href="$personalSpaceLink"><img src="$staticResourceUrlPrefix/images/icons/personal_space_16.gif" height="16" width="16" border="0" align="absmiddle" title="$action.getText('open.personal.space')"></a>
        <a href="$personalSpaceLink">$action.getText('open.personal.space')</a>
    #end
#end


#macro (viewPageLink )
    #if ($helper.page.id)
        #if ( $permissionCheckDispatcher.isPermitted("/pages/viewpage.action?pageId=$pageId") )
            <a href="$req.contextPath/pages/viewpage.action?pageId=$pageId" #if ($tool == "view") class="current" #end>$action.getText('view.name')</a>
        #end
    #end
#end

#macro (attachmentsLink)
    #if ( $permissionCheckDispatcher.isPermitted("/pages/viewattachments.action?pageId=$pageId") )
        <a href="$req.contextPath/pages/viewattachments.action?pageId=$pageId" #if ($tool == "attachments") class="current" #end>$action.getText('attachments.link', ["$!helper.numberOfAttachments"])</a>
    #end
#end

#macro (recentlyUpdatedListLink)
    <a href="$req.contextPath/pages/recentlyupdated.action?key=$generalUtil.urlEncode($key)">$action.getText('recently.updated')</a>
#end

#macro (alphabeticalListLink)
    <a href="$req.contextPath/pages/listpages-alphaview.action?key=$generalUtil.urlEncode($key)">$action.getText('alphabetical.name')</a>
#end

#macro (contentTreeLink)
    <a href="$req.contextPath/pages/listpages-dirview.action?key=$generalUtil.urlEncode($key)">$action.getText('tree.heirarchy')</a>
#end

## this macro is now deprecated. Plugin stylesheets do not have to be explicitly included anymore
#macro (pluginStylesheet $pluginCompleteKey $stylesheetName)
    #pluginSpaceStylesheet($pluginCompleteKey $stylesheetName "")
#end

## this macro is now deprecated. Plugin stylesheets do not have to be explicitly included anymore
#macro (pluginSpaceStylesheet $pluginCompleteKey $stylesheetName $spaceKey)
    <!-- You do not have to explicitly include your custom plugin stylesheets anymore. As long as you declare them in the
    theme module, Confluence will automatically pick them up and append them to the end of the default stylesheet.
    Please see this page (http://confluence.atlassian.com/x/-0kC) for details on the new configuration -->
    <!--link rel="stylesheet" href="$req.contextPath/styles/main-action.css?$styleParams" type="text/css" /-->
#end

## src - path to js file _without_ context path
#macro (includeJavascript $src)
    #if ($src && !$src.startsWith("/"))
        #set ($src = "/${src}")
    #end

    #if ($webResourceManager)
        <script type="text/javascript" src="$webResourceManager.getStaticResourcePrefix()$src"></script>
    #else
        <script type="text/javascript" src="$req.contextPath$src"></script>
    #end
#end

## Use this macro to request a Javascript or CSS plugin resource be added to the HTML header.
## This macro doesn't generate any actual markup.
#macro (requireResource $resourceModuleKey)
    $webResourceManager.requireResource($resourceModuleKey)
#end

## Use this macro to request all Javascript or CSS plugin resources belonging to the given context
## added to the HTML header. This macro doesn't generate any actual markup.
#macro (requireResourcesForContext $context)
    ## These explicit calls are because we can't define dependencies
    ## for our contexts.
    ## See: http://jira.atlassian.com/browse/CONF-13739
    #requireResource("confluence.web.resources:ajs")
    $webResourceManager.requireResourcesForContext($context)
#end

## use this macro to include javascript resources in plugins
## this macro appends a special prefix to the normal script URL (effectively enabling caching on the serving of this javascript)
#macro (includePluginJavascript $pluginCompleteKey $scriptName)
    #if ($webResourceManager)
        <script type="text/javascript" src="$webResourceManager.getStaticPluginResource($pluginCompleteKey, $scriptName)"></script>
    #else
        <script type="text/javascript" src="$req.contextPath/download/resources/$pluginCompleteKey/$scriptName"></script>
    #end
#end


#macro (node $p $idsToExpandAsList $openId)
    #if ($action.hasPermittedChildren($p))
        <a href="#if($idsToExpandAsList.contains($p.id))$action.generateCollapseNodeLinkForNonJSUsers($p)#else $!action.generateExpandNodeLinkForNonJSUsers($p)#end" onClick="toggleChildren('$p.id'); return false;">
        #if($idsToExpandAsList.contains($p.id))
            <img border="0" onClick="togglePlusMinus(this)" src="$staticResourceUrlPrefix/images/icons/tree_minus.gif"></a>
        #else
            <img border="0" onClick="togglePlusMinus(this)" src="$staticResourceUrlPrefix/images/icons/tree_plus.gif"></a>
        #end
    #else
        <img border="0" src="$staticResourceUrlPrefix/images/icons/tree_square.gif">
    #end
    #if ($p.id == $openId)
        <span class="openPageHighlight">#contentLinkWithAnchor($p 'selectedPageInHierarchy')</span>
    #else
        #contentLink2 ($p true false)
    #end
    <div id="children$p.id" style="border: 1px solid white">
        #if ($idsToExpandAsList.contains($p.id))
            <ul style="list-style-type: none">
            #foreach ($child in $action.getPermittedChildren($p))
                <li>#node($child $idsToExpandAsList $openId)</li>
            #end
            </ul>
        #end
    </div>
#end

#macro (permitSearchEngines)
    <content tag="allowindex">true</content>
#end

## Old school comments (pre-2.6)
#macro (viewPageComment $comment $rootDepth)
    #set ($depth = $comment.depth - $rootDepth)
    #set ($page = $comment.page)
    <div style="padding: 0 0 0 #if ($depth && $depth > 0) 20px #else 0 #end">
        <a name="comment-$comment.id"></a>
        #if ($focusedCommentId == $comment.id && $action.editComment && $permissionHelper.canEdit($remoteUser, $comment ))
        <div align="left">
            <div style="padding: 10px; width: 75%">
                <div style="width:720px;">
                    <form name="editcommentform" method="POST" action="$req.contextPath/pages/doeditcomment.action?pageId=$page.id&amp;commentId=$comment.id">
                        #bodytag ("Component" "name='content'" "theme='notable'" "template='wiki-textarea.vm'")
                            #param ("formname" "editcommentform")
                            #param ("spaceKey" "$generalUtil.urlEncode($spaceKey)")
                            #param ("rows" 15)
                            #param ("cols" 70)
                            #param ("width" "100%")
                            #param ("tabindex" "4")
                            #param ("tdcolor" "f0f0f0")
                            #param ("toolbarExpanded" "false")
                            #param ("initialFocus" "false")
                            #param ("edit" "true")
                            #param ("heartbeat" "false")
                            #param ("wikiContent" "$comment.content")
                            #param ("wysiwygContent" "$action.getCommentAsXHtmlForWysiwyg()")
                            #param ("contentId" "$comment.id")
                            #param ("contentType" "comment")
                        #end
                        #commentSubmission()
                    </form>
                </div>
            </div>
        </div>
        #else
        <div #if ($comment.id == $focusedCommentId) class="focusedComment" #else class="commentBox" style="background-color: #if ($depth%2 == 1) f0f0f0#end"#end>
            <div class="commentblock">$action.xHtmlComments.get($comment)</div>
            <div align="left" class="smallfont" style="color: #666666; width: 98%">
                #contentIcon($comment)

                #if ($action.helper.shouldRenderCommentAsUpdated($comment))
                    #set ($creationDateHtml = $action.dateFormatter.formatDateTime( $comment.creationDate ))
                #else
                    #set ($creationDateHtml = "<a href='$req.contextPath$comment.urlPath'>$action.dateFormatter.formatDateTime( $comment.creationDate )</a>")
                #end

                #set ($postedHtml = $action.getText('comment.posted.by',["#usernameLink ($comment.creatorName)", $creationDateHtml]))

                #if ($action.helper.shouldRenderCommentAsUpdated($comment))
                    #if ($comment.creatorName == $comment.lastModifierName)
                        $postedHtml $action.getText("comment.updated.by.author", ["#usernameLink ($comment.lastModifierName)", "<a href='$req.contextPath$comment.urlPath'>$action.dateFormatter.formatDateTime( $comment.lastModificationDate )</a>"])
                    #else
                        $postedHtml $action.getText("comment.updated.by.non.author", ["#usernameLink ($comment.lastModifierName)", "<a href='$req.contextPath$comment.urlPath'>$action.dateFormatter.formatDateTime( $comment.lastModificationDate )</a>"])
                    #end
                #else
                    $postedHtml
                #end

                #if (!$action.printableVersion)
                  #if ( $permissionHelper.canEdit($remoteUser, $comment ))
                  | <a id="edit-$comment.id" href="$req.contextPath$generalUtil.customGetPageUrl($page)showComments=true&amp;editComment=true&amp;focusedCommentId=$comment.id#comment-$comment.id">$action.getText('edit.name')</a>
                  #end
                  #if ( $permissionHelper.canRemove($remoteUser, $comment ))
                    | <a id="remove-$comment.id" href="$req.contextPath/pages/removecomment.action?pageId=$page.id&amp;commentId=$comment.id"
                       onClick="javascript:if( confirm( '$i18n.getText('remove.comment.confirmation.message')' )) { this.href = this.href + '&confirm=yes'; return true; } else return false;">$action.getText('remove.name')</a>
                  #end
                  #if ($threadComments && $permissionHelper.canComment($remoteUser, $page))
                    | <a id="reply-$comment.id" href="$req.contextPath$generalUtil.customGetPageUrl($page)replyToComment=$comment.id#comment-$comment.id">$action.getText("reply.to.comment")</a>
                  #end
                #end
            </div>

            #trackbackRdf ($trackbackUtils.getContentIdentifier($comment) $comment.title $trackbackUtils.getPingUrl($comment))

            #if ( $threadComments && $replyToComment == $comment.id && $permissionCheckDispatcher.isPermitted("/pages/doaddcomment.action?pageId=$page.id") && $action.isPrintableVersion()==false )
                <div align="left">
                    #if( !$remoteUser )
                        #parse ("/includes/alert-anonymous.vm")
                    #end

                    <div style="padding: 10px; width: 75%">
                        <div style="width:720px;">
                            <form name="threadedcommentform" method="POST" action="$req.contextPath/pages/doaddcomment.action?pageId=${page.id}&parentId=${comment.id}">
                                #bodytag ("Component" "name='content'" "theme='notable'" "template='wiki-textarea.vm'")
                                    #param ("formname" "threadedcommentform")
                                    #param ("spaceKey" "$generalUtil.urlEncode($spaceKey)")
                                    #param ("rows" 15)
                                    #param ("cols" 70)
                                    #param ("width" "100%")
                                    #param ("tabindex" "4")
                                    #param ("tdcolor" "f0f0f0")
                                    #param ("toolbarExpanded" "false")
                                    #param ("initialFocus" "false")
                                    #param ("edit" "true")
                                    #param ("heartbeat" "false")
                                    #param ("contentId" "0")
                                    #param ("contentType" "comment")
                                #end
                                #commentSubmission()
                            </form>
                        </div>
                    </div>
                </div>
            #end
        </div>
        #end

        #if ($threadComments)
            #if ($comment.children.size() > 0)
                #if ($depth < 3 || $comment.descendantsCount == 1)
                    #foreach ($childComment in $comment.children)
                        #viewPageComment($childComment $rootDepth)
                    #end
                #else
                        <div style="padding-left: 60px; color: #666666" class="smallfont">
                            <a href="$req.contextPath$generalUtil.customGetPageUrl($page)rootCommentId=$comment.id#comments">$action.getText('view.the.rest.of.this.thread')</a>. $action.getText('most.recent.comment') #if ($generalUtil.isInLastDays($comment.threadChangedDate, 60)) $generalUtil.getRelativeTime($comment.threadChangedDate) #else $action.dateFormatter.format($comment.threadChangedDate) #end<br/>
                            $comment.descendantsCount more comments by: #nameList($comment.descendantAuthors)<br/>
                        </div>
                #end
            #end
        #end
    </div>
#end

#macro (searchResultContentLink $searchResult)
    #contentIcon($searchResult)

	#if ($searchResult.type == "attachment")
		<a href="$req.contextPath$searchResult.extraFields.attachmentDownloadPath">$generalUtil.htmlEncode($searchResult.displayTitle)</a>
	#else
		<a href="$req.contextPath$searchResult.urlPath">$generalUtil.htmlEncode($searchResult.displayTitle)</a>
	#end

	#if ($searchResult.type == "page" || $searchResult.type == "blogpost")
		<span class="smalltext">(<a href="$req.contextPath/display/$generalUtil.urlEncode($searchResult.spaceKey)">$generalUtil.htmlEncode($searchResult.spaceName)</a>)</span>
	#elseif ($searchResult.type == "attachment")
		<span class="smalltext">
			(<a href="$req.contextPath/display/$generalUtil.urlEncode($searchResult.spaceKey)">$generalUtil.htmlEncode($searchResult.spaceName)</a>
			&gt; <a href="$req.contextPath$searchResult.extraFields.containingContentUrlPath">$generalUtil.htmlEncode($searchResult.extraFields.containingContentDisplayTitle)</a>)
		</span>
	#elseif ($searchResult.type == "comment")
		<span class="smalltext">
			(<a href="$req.contextPath/display/$generalUtil.urlEncode($searchResult.spaceKey)">$generalUtil.htmlEncode($searchResult.spaceName)</a>
			&gt; <a href="$req.contextPath$searchResult.extraFields.containingPageUrlPath">$generalUtil.htmlEncode($searchResult.extraFields.containingPageDisplayTitle)</a>)
		</span>
    #end
#end

#macro (searchResult $searchResult $showExcerpts $queryString)

	## ensure we check for null here to avoid trying to assign null (CONF-12141)
	#if ($searchResult.content)
		#set ($contentBody = $searchResult.content)
	#else
		#set ($contentBody = '')
	#end

	#searchResultContentLink($searchResult)
    #if ('true' == $showExcerpts && $stringUtils.isNotBlank($contentBody) && $stringUtils.isNotBlank($queryString))
		#if ($searchResult.type != "attachment")
            #set ($summary = $generalUtil.makeSummary($contentBody, $queryString))
        #elseif ($searchResult.type == "attachment" && $contentBody)
            #set ($summary = $generalUtil.makeSummary($contentBody, $queryString))
        #elseif ($searchResult.type == "attachment" && $searchResult.comment)
            #set ($summary = $generalUtil.makeSummary($searchResult.comment, $queryString))
        #end

        #if ($summary)
            <br/>
            ## this is all one one line so that fragments are concatenated properly without spaces
            #foreach ($fragment in $summary.fragments)#if ($fragment.isHighlight() == true)<span class="search-highlight"><strong>$generalUtil.htmlEncode($fragment.toString())</strong></span>#else$generalUtil.htmlEncode($fragment.toString())#end#end
        #end

        ## clear the summary after displaying it to avoid Velocity scope problems
        #set ($summary = '')
    #end

    <br />
    <span class="smalltext">
        #if ($searchResult.type == 'attachment')
            #if ($searchResult.extraFields.attachmentTypeDescription)
                $searchResult.extraFields.attachmentTypeDescription -
            #end
            $searchResult.extraFields.attachmentReadableFileSize -
        #end

        $action.dateFormatter.format($searchResult.lastModificationDate)

        #if ($searchResult.type == 'attachment')
            - <a href="$req.contextPath$searchResult.extraFields.attachmentDownloadPath">$action.getText('download.name')</a>
            - <a href="$req.contextPath$searchResult.urlPath">$action.getText('all.attachments')</a>
        #elseif ($searchResult.type == 'comment')
			- <a href="$req.contextPath${searchResult.extraFields.containingPageUrlPath}#comments">$action.getText('all.comments')</a>
        #elseif ($searchResult.type == 'blogpost')
            - <a href="$req.contextPath/pages/viewrecentblogposts.action?key=$generalUtil.urlEncode($searchResult.spaceKey)">$action.getText('all.news')</a>
        #elseif ($searchResult.type == 'mail')
            - <a href="$req.contextPath/spaces/viewmailarchive.action?key=$generalUtil.urlEncode($searchResult.spaceKey)">$action.getText('all.mail')</a>
        #end
    </span>

	#if ($searchResult.hasLabels())

        #set ($labels = $searchResult.getLabels($remoteUser))
		#set ($max = 5)

		#if ($labels.size() > 0)
			<br />
        	<span class="smalltext">
        	$action.getText('labels.name'):
			#set($remaining = $labels.size() - $max)
			#foreach($label in $labels)#if($velocityCount <= $max)#if($velocityCount > 1), #end <a href="$req.contextPath/label/$generalUtil.urlEncode($label)" rel="nofollow">$label</a>#end#end
			#if($remaining > 0)
			... $action.getText('search.x.more.labels', [$remaining]).
			#end
			</span>
		#end

    #end

#end

#macro (commaDelimitedList $list)
    #foreach($item in $list)#if($velocityCount != 1), #end$!item#end
#end

#macro (doc $link $body)
    <a href="$action.getText('url.confluence.atlassian')/$link" target="_blank">$body</a>
#end

## Deprecated macro. Maintained for classic theme.
#macro (spaceActionLinks $mode $browseSpace)
	#foreach ($item in $webInterfaceManager.getDisplayableItems("system.space.actions", $action.webInterfaceContext))
		#set ($itemRenderedUrl = $item.link.getDisplayableUrl($req, $action.webInterfaceContext))
		#set ($itemLabel = $item.label.getDisplayableLabel($req, $action.webInterfaceContext))

        #set ($currentAction = false)

        #if (($mode == "create-page" && $item.key == "add-page") || ($mode == "create-blogpost" && $item.key == "add-news"))
            #set ($currentAction = true)
        #end

        #if ($item.icon)
			#set ($icon = $item.icon)
            <a #if($currentAction) class="current"#end href="$itemRenderedUrl"><img src="$icon.url.getDisplayableUrl($req, $action.webInterfaceContext)" height="$icon.height" width="$icon.width" border="0" align="absmiddle" title="$itemLabel">&nbsp;<span>$itemLabel</span></a>
		#else
            <a #if($currentAction) class="current"#end href="$itemRenderedUrl">$itemLabel</a>
		#end
    #end
#end

#macro (addClassName $existingClass $newClass)
    #set ($existingClass = "$existingClass $newClass")
#end

#macro (captchaImage)
    <img src="$req.contextPath/jcaptcha" width="200" height="100" class="captcha-image"/>
#end

#macro (commentSubmission)
    #if ($action.editComment)
        #set ($submitLabel = "update.name")
    #else
        #set ($submitLabel = "post.name")
    #end

	#parse ("/pages/includes/captcha-form-elements.vm")

	<br />
	#bodytag ("Submit" "name='confirm'" "value='$submitLabel'" "theme='notable'")
		 #param ("accessKey" "s")
		#param ("tabindex" "201")
	#end

	#bodytag ("Submit" "name='cancel'" "value='cancel.name'" "theme='notable'" )
		#param ("tabindex" "202")
	#end

	#if ($remoteUser && !$action.userWatchingPage && !$action.userWatchingSpace)
		#bodytag ("Checkbox" "name='watchPageAfterComment'" "theme='notable'" "label='comment.notification.enable'" "value='false'")
			#param ("tabindex" "203")
		#end
	#end
#end

#macro (displayContentPermission $perm)
    #if ($perm.isUserPermission())
        <img src="$staticResourceUrlPrefix/images/icons/user_16.gif">&nbsp;$perm.userName
    #else
        <img src="$staticResourceUrlPrefix/images/icons/group_16.gif">&nbsp;$perm.groupName
    #end
#end

#macro (favicon)
    <link rel="shortcut icon" href="$req.contextPath/favicon.ico">
    <link rel="icon" type="image/png" href="$staticResourceUrlPrefix/images/logo/confluence_16.png">
#end


#macro(dashboard_renderGlobalActions $menuId $webSectionKeys)
    #set($webMenu = $webMenuManager.getMenu($menuId, $webSectionKeys, $action.webInterfaceContext))

    ## don't display if there are no sections - only expect one section for this location
    #if(!$webMenu.isEmpty())
        #foreach ($section in $webMenu.sections)
            #foreach ($item in $section.items)
                #set ($itemRenderedUrl = '')
                #set ($itemRenderedUrl = $item.link.getDisplayableUrl($req, $action.webInterfaceContext))
                #set ($itemLabel = $item.label.getDisplayableLabel($req, $action.webInterfaceContext))
                #set ($itemClass = $item.styleClass)
                #set ($itemIcon = $item.icon)
                #set ($itemDescription = $item.description)
                #set ($itemIconUrl = $itemIcon.url.getDisplayableUrl($req, $action.webInterfaceContext))
                #set ($itemTooltip = $item.tooltip.getDisplayableLabel($req, $action.webInterfaceContext))
                #set ($linkId = $item.link.id)

                <img src="$itemIconUrl" align='absmiddle' height="$itemIcon.height" width="$itemIcon.width"> <strong><a id="$linkId" class="$!itemClass" href="$itemRenderedUrl"> $itemLabel</a></strong><span class="smalltext"> - $!itemTooltip</span><br>
            #end
        #end
    #end
#end

#macro(form_xsrfToken)
    <input type="hidden" name="${xsrfTokenGenerator.xsrfTokenName}" value="${xsrfTokenGenerator.generateToken($req)}">
#end

#macro(url_xsrfToken)
#trim()
   ${xsrfTokenGenerator.xsrfTokenName}=${xsrfTokenGenerator.generateToken($req)}
#end
#end

#macro (showCacheStatistics $cacheStatistics)
    <table class="grid" width="100%">
        <tr>
            <th class="smalltext">$action.getText("name.word")</th>
            <th class="smalltext">$action.getText("cache.percentused")</th>
            <th class="smalltext">$action.getText("cache.effectiveness")</th>
            #if ($action.showDistributions)
                <th class="smalltext">$action.getText("cache.objects") / $action.getText("size.name")</th>
                <th class="smalltext">$action.getText("cache.hit") / $action.getText("cache.miss") / $action.getText("cache.expired")</th>
                <th class="smalltext">$action.getText("adjust.size.name")</th>
            #end
            <th class="smalltext">$action.getText("flush.name")</th>
        </tr>
        #foreach($cacheStatistic in $cacheStatistics)
            #if ($action.showDistributions || $cacheStatistic.hasContents())
            <tr>
                <td title="$cacheStatistic.name">$cacheStatistic.niceName</td>
                <td align="center">${cacheStatistic.usagePercent}%</td>
                <td align="center" #if ($cacheStatistic.hitPercent != 0 && $cacheStatistic.hitPercent < 25) bgcolor="#FFDDDD"#end>${cacheStatistic.hitPercent}%</td>

                #if ($action.showDistributions)
                    <td align="center">$cacheStatistic.size / $cacheStatistic.maxSize</td>
                    <td align="center">$cacheStatistic.hitCount / $cacheStatistic.missCount / $cacheStatistic.expiredCount</td>
                    <td align="center">
                        <form method="POST" id="$cacheStatistic.name" action="adjustcachesize.action">
                            #form_xsrfToken()
                            <input name="cacheSize" size="5" type="text" value="$cacheStatistic.maxSize"/>
                            <input type="hidden" name="cacheName" value="$cacheStatistic.name" />
                            <input type="hidden" name="showDistributions" value="true" />
                            <input type="submit" value="Adjust Size"/>
                        </form>
                    </td>
                #end

                <td align="center">
                    <a id="flush-$cacheStatistic.name" href="$req.contextPath/admin/flushcache.action?cache=$cacheStatistic.name&redirectUrl=cachestatistics.action%3FshowDistributions%3D$action.showDistributions&#url_xsrfToken()">$action.getText('flush.name')</a>
                </td>
            </tr>
            #end
        #end
        <tr>
            <td #if ($action.showDistributions) colspan="7" #else colspan="4" #end align="right">
                <a id="flush-all" href="$req.contextPath/admin/flushcache.action?#url_xsrfToken()&redirectUrl=cachestatistics.action%3FshowDistributions%3D$action.showDistributions">$action.getText('flush.all')</a>
            </td>
        </tr>
    </table>
#end