<!DOCTYPE html>
<!-- Page: wiki view -->
<html lang="fr">

	<?php include('blocks/d.head.html'); ?>

	<body>

		<?php include('blocks/d.nav.html'); ?>

		<?php
			$isArchiveOrPrivate = $wikiPage->is_archive == "t" || $wikiPage->is_public == "f";
			$canViewHistory = $user->rankIsHigher('premium');
			$canModerate = $user->rankIsHigher('moderator');
			$hasHistory = isset($wikiHistory);
		?>

		<!-- Wiki content -->
		<section id="wiki_page" <?=$isArchiveOrPrivate ? 'class="archive"' : ''?>>
			<h1><?=$wikiPage->name?></h1>
				<?php if ($canViewHistory) { ?>
					<!-- History and actions -->
					<span class="subtitle">
					<?php if ($hasHistory) { ?>
						<select id="wikihistory">
							<?php $historyIndex = 0; ?>
							<?php foreach ($wikiHistory->objs as $row) { ?>
								<?php
									$isSelected = $row->version_id == $wikiPage->version_id ? 'selected' : '';
									$isActive = $row->is_archive == "f" ? '&bull; ' : '';
									$formattedDate = datefmt_format(
										$user->datetimeshort_format,
										date_create($row->update_date, new DateTimeZone("UTC"))
									);
								?>
								<option <?=$isSelected?> value="<?=$historyIndex?>"><?=$isActive?><?=$formattedDate?></option>
								<?php $historyIndex++; ?>
							<?php } ?>
						</select>
					<?php }
					if ($canModerate && $hasHistory) { ?>
						 &mdash; 
					<?php }
					if ($canModerate) { ?>
						<a href="<?=$config['rel_root_folder']?>wiki/<?=$wikiPage->permalink?>/edit"><i class="fas fa-pencil-alt"></i> Éditer la page</a> &mdash; 
						<?php if ($wikiPage->is_public=="t") { ?>
							<a href="<?=$config['rel_root_folder']?>wiki/<?=$wikiPage->permalink?>/delete"><i class="fas fa-trash"></i> Effacer la page</a>
						<?php } else { ?>
							<a href="<?=$config['rel_root_folder']?>wiki/<?=$wikiPage->permalink?>/restore"><i class="fas fa-eye"></i> Restaurer la page</a>
						<?php }?>
					<?php } ?>
					</span>
				<?php } ?>

			<!-- Page body -->
			<div id="wikiContent">
				<?=$wikiPage->content_html?>
			</div>

			<!-- Timestamp -->
			<p id="wikiTimestamp">Page mise à jour le <?php echo datefmt_format($user->datetime_format,date_create($wikiPage->update_date, new DateTimeZone("UTC"))) ?></p>

			<div style="clear: both;"> </div>
		</section>

<?php if ($canViewHistory) { ?>
		<!-- History selector -->
		<script type="text/javascript">
			$( "#wikihistory" ).change(function() {
				window.location.href = "<?=$config['rel_root_folder']?>wiki/<?=$wikiPage->permalink?>/"+$( this ).val();
			});
		</script>
<?php } ?>

		<?php include('blocks/d.footer.html'); ?>

	</body>
</html>
