<%--
/**
 * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
 *
 * The contents of this file are subject to the terms of the Liferay Enterprise
 * Subscription License ("License"). You may not use this file except in
 * compliance with the License. You can obtain a copy of the License by
 * contacting Liferay, Inc. See the License for the specific language governing
 * permissions and limitations under the License, including but not limited to
 * distribution rights of the Software.
 *
 *
 *
 */
--%>

<%
try {
	formattedContent = WikiUtil.getFormattedContent(wikiEngineRenderer, renderRequest, renderResponse, wikiPage, viewPageURL, editPageURL, title, preview);
%>

	<div class="wiki-body">
		<c:choose>
			<c:when test="<%= !followRedirect && (redirectPage != null) %>">
				<div class="alert alert-info">
					<liferay-ui:message arguments="<%= redirectPage.getTitle() %>" key="this-page-is-currently-redirected-to-x" translateArguments="<%= false %>" />
				</div>

				<c:if test="<%= WikiPagePermission.contains(permissionChecker, wikiPage, ActionKeys.UPDATE) %>">
					<portlet:renderURL var="removeRedirectURL">
						<portlet:param name="mvcRenderCommandName" value="/wiki/edit_page" />
						<portlet:param name="nodeId" value="<%= String.valueOf(node.getNodeId()) %>" />
						<portlet:param name="title" value="<%= title %>" />
						<portlet:param name="removeRedirect" value="<%= Boolean.TRUE.toString() %>" />
					</portlet:renderURL>

					<div class="btn-toolbar">

						<%
						String taglibRemoveRedirect = "location.href = '" + removeRedirectURL + "';";
						%>

						<aui:button onClick="<%= taglibRemoveRedirect %>" value="remove-redirect" />
					</div>
				</c:if>
			</c:when>
			<c:when test="<%= Validator.isNull(formattedContent) && WikiPagePermission.contains(permissionChecker, wikiPage, ActionKeys.UPDATE) %>">
				<div class="alert alert-info">
					<aui:a href="<%= editPageURL.toString() %>" label="this-page-is-empty-edit-it-to-add-some-text" />
				</div>
			</c:when>
			<c:otherwise>
				<%= formattedContent %>
			</c:otherwise>
		</c:choose>
	</div>

<%
}
catch (WikiFormatException wfe) {
	if (_log.isDebugEnabled()) {
		_log.debug("Unable to get wiki engine for " + wikiPage.getFormat());
	}
%>

	<div class="alert alert-danger">
		<liferay-ui:message key="the-format-of-this-page-is-not-supported-the-page-content-will-be-shown-unformatted" />
	</div>

	<div class="wiki-body">
		<pre><%= wikiPage.getContent() %></pre>
	</div>

<%
}
catch (Exception e) {
	_log.error("Error formatting the wiki page " + wikiPage.getPageId() + " with the format " + wikiPage.getFormat(), e);
%>

	<div class="alert alert-danger">
		<liferay-ui:message key="an-error-occurred-while-formatting-the-wiki-page" />
	</div>

<%
}
%>

<%!
private static Log _log = LogFactoryUtil.getLog("com_liferay_wiki_web.wiki.view_page_content_jspf");
%>