From 708dc5a3f123876305325c5470bf8cbd2efe1a66 Mon Sep 17 00:00:00 2001 From: southerntofu Date: Sat, 20 Mar 2021 17:43:07 +0100 Subject: [PATCH] Handle 404 gracefully --- includes/404.md | 3 +++ wiki.php | 10 ++++------ 2 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 includes/404.md diff --git a/includes/404.md b/includes/404.md new file mode 100644 index 0000000..7140ab4 --- /dev/null +++ b/includes/404.md @@ -0,0 +1,3 @@ +# 404 + +This page ("$page") does not exist. diff --git a/wiki.php b/wiki.php index fa37516..5eadec1 100644 --- a/wiki.php +++ b/wiki.php @@ -7,14 +7,11 @@ Parsedown is licensed under the MIT license. include('config.php'); include('parsedown-1.7.3/Parsedown.php'); -$page = $_GET['page']; +$page = isset($_GET['page']) ? $_GET['page'] : 'main'; + $Parsedown = new Parsedown(); $Parsedown->setSafeMode(true); -if ( $page == "") { - $page = "main"; - } - if(isset($_GET['style'])) $site_style = $_GET['style']; else @@ -22,7 +19,8 @@ else $header = file_get_contents("includes/header.md"); $sidebar = file_get_contents("includes/sidebar.md"); -$content = file_get_contents("articles/$page.md"); +$content_file = "articles/$page.md"; +$content = file_exists($content_file) ? file_get_contents($content_file) : str_replace('$page', "$page", file_get_contents("includes/404.md")); $footer = file_get_contents("includes/footer.md"); print "