From be1fa80959603af8898eec2af1b0af72c2ada17f Mon Sep 17 00:00:00 2001
From: Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com>
Date: Thu, 26 Apr 2018 23:51:41 +0100
Subject: [PATCH] Enhance display of orphaned pages list

---
 build/index.php              | 13 +++++++------
 module_index.json            |  2 +-
 modules/parser-parsedown.php | 11 ++++++-----
 3 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/build/index.php b/build/index.php
index c9c703e..e7d9443 100644
--- a/build/index.php
+++ b/build/index.php
@@ -387,7 +387,7 @@ if($settings->css === "auto")
 /////////////////////////////////////////////////////////////////////////////
 /** The version of Pepperminty Wiki currently running. */
 $version = "v0.16-dev";
-$commit = "0c00cf36316ba33f9acf4013e9ddee02ed4191d4";
+$commit = "c6a3ce16df9886c0135bd8ed36efa3df7cc376a1";
 /// Environment ///
 /** Holds information about the current request environment. */
 $env = new stdClass();
@@ -7992,9 +7992,8 @@ register_module([
 				$result = new stdClass(); // completed, value, state
 				$pages = [];
 				foreach($pageindex as $pagename => $pagedata) {
-					if(!file_exists($env->storage_prefix . $pagedata->filename)) {
+					if(!file_exists($env->storage_prefix . $pagedata->filename))
 						continue;
-					}
 					$page_content = file_get_contents($env->storage_prefix . $pagedata->filename);
 					
 					$page_links = PeppermintParsedown::extract_page_names($page_content);
@@ -8037,9 +8036,8 @@ register_module([
 				$result = new stdClass(); // completed, value, state
 				$pages = [];
 				foreach($pageindex as $pagename => $pagedata) {
-					if(!file_exists($env->storage_prefix . $pagedata->filename)) {
+					if(!file_exists($env->storage_prefix . $pagedata->filename))
 						continue;
-					}
 					$page_content = file_get_contents($env->storage_prefix . $pagedata->filename);
 					
 					$page_links = PeppermintParsedown::extract_page_names($page_content);
@@ -8065,10 +8063,13 @@ register_module([
 				return $result;
 			},
 			"render" => function($stats_data) {
+				global $pageindex;
 				$result = "<h2>$stats_data->name</h2>\n";
+				$result .= "<p><strong>Count:</strong> " . count($stats_data->value) . "</p>\n";
 				$result .= "<ul class='orphan-pages'>\n";
 				foreach($stats_data->value as $pagename) {
-					$result .= "\t<li>$pagename</li>\n";
+					$pagename_display = !empty($pageindex->$pagename->redirect) && $pageindex->$pagename->redirect ? "<em>$pagename</em>" : $pagename;
+					$result .= "\t<li><a href='?page=" . rawurlencode($pagename) . "'>$pagename_display</a></li>\n";
 				}
 				$result .= "</ul>\n";
 				return $result;
diff --git a/module_index.json b/module_index.json
index c125938..632ad6b 100755
--- a/module_index.json
+++ b/module_index.json
@@ -266,7 +266,7 @@
         "author": "Emanuil Rusev & Starbeamrainbowlabs",
         "description": "An upgraded (now default!) parser based on Emanuil Rusev's Parsedown Extra PHP library (https:\/\/github.com\/erusev\/parsedown-extra), which is licensed MIT. Please be careful, as this module adds some weight to your installation, and also *requires* write access to the disk on first load.",
         "id": "parser-parsedown",
-        "lastupdate": 1524781555,
+        "lastupdate": 1524783071,
         "optional": false
     }
 ]
\ No newline at end of file
diff --git a/modules/parser-parsedown.php b/modules/parser-parsedown.php
index 8daba42..844f800 100644
--- a/modules/parser-parsedown.php
+++ b/modules/parser-parsedown.php
@@ -32,9 +32,8 @@ register_module([
 				$result = new stdClass(); // completed, value, state
 				$pages = [];
 				foreach($pageindex as $pagename => $pagedata) {
-					if(!file_exists($env->storage_prefix . $pagedata->filename)) {
+					if(!file_exists($env->storage_prefix . $pagedata->filename))
 						continue;
-					}
 					$page_content = file_get_contents($env->storage_prefix . $pagedata->filename);
 					
 					$page_links = PeppermintParsedown::extract_page_names($page_content);
@@ -77,9 +76,8 @@ register_module([
 				$result = new stdClass(); // completed, value, state
 				$pages = [];
 				foreach($pageindex as $pagename => $pagedata) {
-					if(!file_exists($env->storage_prefix . $pagedata->filename)) {
+					if(!file_exists($env->storage_prefix . $pagedata->filename))
 						continue;
-					}
 					$page_content = file_get_contents($env->storage_prefix . $pagedata->filename);
 					
 					$page_links = PeppermintParsedown::extract_page_names($page_content);
@@ -105,10 +103,13 @@ register_module([
 				return $result;
 			},
 			"render" => function($stats_data) {
+				global $pageindex;
 				$result = "<h2>$stats_data->name</h2>\n";
+				$result .= "<p><strong>Count:</strong> " . count($stats_data->value) . "</p>\n";
 				$result .= "<ul class='orphan-pages'>\n";
 				foreach($stats_data->value as $pagename) {
-					$result .= "\t<li>$pagename</li>\n";
+					$pagename_display = !empty($pageindex->$pagename->redirect) && $pageindex->$pagename->redirect ? "<em>$pagename</em>" : $pagename;
+					$result .= "\t<li><a href='?page=" . rawurlencode($pagename) . "'>$pagename_display</a></li>\n";
 				}
 				$result .= "</ul>\n";
 				return $result;
