From 110d5f1ae693979b0885a2099967faa8ece9e5a7 Mon Sep 17 00:00:00 2001
From: Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com>
Date: Sat, 16 Jan 2016 13:51:25 +0000
Subject: [PATCH] Tweaks and fixes to new recent changes

---
 build/index.php                    | 43 +++++++++++++++++++++---------
 module_index.json                  |  2 +-
 modules/feature-recent-changes.php | 38 +++++++++++++++++---------
 settings.fragment.php              |  5 ++++
 4 files changed, 63 insertions(+), 25 deletions(-)

diff --git a/build/index.php b/build/index.php
index 3421736..fcfbc77 100644
--- a/build/index.php
+++ b/build/index.php
@@ -322,6 +322,11 @@ textarea ~ input[type=submit] { margin: 0.5rem 0.8rem; padding: 0.5rem; font-wei
 .tag-list li { display: inline-block; margin: 1rem; }
 .mini-tag { background: #d2c3dd; padding: 0.2rem 0.4rem; color: #fb701a; text-decoration: none; }
 
+.larger { color: rgb(9, 180, 0); }
+.smaller { color: rgb(207, 28, 17); }
+.nochange { color: rgb(132, 123, 199); font-style: italic; }
+.significant { font-weight: bold; }
+
 footer { padding: 2rem; }
 /* #ffdb6d #36962c */";
 
@@ -1562,19 +1567,33 @@ register_module([
 		add_action("recent-changes", function() {
 			global $settings, $paths;
 			
-			$content = "\t\t<h1>Recent Changes</h1>
-		<ul>\n";
+			$content = "\t\t<h1>Recent Changes</h1>\n";
 			
 			$recentchanges = json_decode(file_get_contents($paths->recentchanges));
-			foreach($recentchanges as $rchange)
-			{
-				// The number (and the sign) of the size difference to display
-				$size_display = ($rchange->sizediff > 0 ? "+" : ($rchange < 0 ? "-" : "")) . $rchange->sizediff;
-				$size_display_class = $rchange->sizediff > 0 ? "larger" : ($rchange < 0 ? "smaller" : "nochange");
-				$content .= "\t\t\t<li><span class='editor'>&#9998; $rchange->page $rchange->user</span> " . human_time_since($rchange->timestamp) . " <span class='$size_display_class' title='New size: $rchange->newsize'>($size_display)</span></li>\n";
-			}
 			
-			$content .= "\t\t</ul>";
+			if(count($recentchanges) > 0)
+			{
+				$content .= "<ul class='page-list'>\n";
+				foreach($recentchanges as $rchange)
+				{
+					// The number (and the sign) of the size difference to display
+					$size_display = ($rchange->sizediff > 0 ? "+" : "") . $rchange->sizediff;
+					$size_display_class = $rchange->sizediff > 0 ? "larger" : ($rchange->sizediff < 0 ? "smaller" : "nochange");
+					if($rchange->sizediff > 500 or $rchange->sizediff < -500)
+					$size_display_class .= " significant";
+					
+					
+					$title_display = human_filesize($rchange->newsize - $rchange->sizediff) . " -> " .  human_filesize($rchange->newsize);
+					
+					$content .= "\t\t\t<li><a href='?page=" . rawurlencode($rchange->page) . "'>$rchange->page</a> <span class='editor'>&#9998; $rchange->user</span> " . human_time_since($rchange->timestamp) . " <span class='$size_display_class' title='$title_display'>($size_display)</span></li>\n";
+				}
+				$content .= "\t\t</ul>";
+			}
+			else
+			{
+				// No changes yet :(
+				$content .= "<p><em>None yet! Try making a few changes and then check back here.</em></p>\n";
+			}
 			
 			echo(page_renderer::render("Recent Changes - $settings->sitename", $content));
 		});
@@ -1592,13 +1611,13 @@ register_module([
 			error_log("Size diff: $size_diff");
 			
 			$recentchanges = json_decode(file_get_contents($paths->recentchanges), true);
-			$recentchanges[] = [
+			array_unshift($recentchanges, [
 				"timestamp" => time(),
 				"page" => $env->page,
 				"user" => $env->user,
 				"newsize" => $newsize,
 				"sizediff" => $size_diff
-			];
+			]);
 			
 			// Limit the number of entries in the recent changes file if we've
 			// been asked to.
diff --git a/module_index.json b/module_index.json
index 5eb0176..f9d1a49 100644
--- a/module_index.json
+++ b/module_index.json
@@ -41,7 +41,7 @@
         "author": "Starbeamrainbowlabs",
         "description": "Adds recent changes. Access through the 'recent-changes' action.",
         "id": "feature-recent-changes",
-        "lastupdate": 1452950460,
+        "lastupdate": 1452952166,
         "optional": false
     },
     {
diff --git a/modules/feature-recent-changes.php b/modules/feature-recent-changes.php
index c7726d4..1a5403a 100644
--- a/modules/feature-recent-changes.php
+++ b/modules/feature-recent-changes.php
@@ -29,19 +29,33 @@ register_module([
 		add_action("recent-changes", function() {
 			global $settings, $paths;
 			
-			$content = "\t\t<h1>Recent Changes</h1>
-		<ul>\n";
+			$content = "\t\t<h1>Recent Changes</h1>\n";
 			
 			$recentchanges = json_decode(file_get_contents($paths->recentchanges));
-			foreach($recentchanges as $rchange)
-			{
-				// The number (and the sign) of the size difference to display
-				$size_display = ($rchange->sizediff > 0 ? "+" : ($rchange < 0 ? "-" : "")) . $rchange->sizediff;
-				$size_display_class = $rchange->sizediff > 0 ? "larger" : ($rchange < 0 ? "smaller" : "nochange");
-				$content .= "\t\t\t<li><span class='editor'>&#9998; $rchange->page $rchange->user</span> " . human_time_since($rchange->timestamp) . " <span class='$size_display_class' title='New size: $rchange->newsize'>($size_display)</span></li>\n";
-			}
 			
-			$content .= "\t\t</ul>";
+			if(count($recentchanges) > 0)
+			{
+				$content .= "<ul class='page-list'>\n";
+				foreach($recentchanges as $rchange)
+				{
+					// The number (and the sign) of the size difference to display
+					$size_display = ($rchange->sizediff > 0 ? "+" : "") . $rchange->sizediff;
+					$size_display_class = $rchange->sizediff > 0 ? "larger" : ($rchange->sizediff < 0 ? "smaller" : "nochange");
+					if($rchange->sizediff > 500 or $rchange->sizediff < -500)
+					$size_display_class .= " significant";
+					
+					
+					$title_display = human_filesize($rchange->newsize - $rchange->sizediff) . " -> " .  human_filesize($rchange->newsize);
+					
+					$content .= "\t\t\t<li><a href='?page=" . rawurlencode($rchange->page) . "'>$rchange->page</a> <span class='editor'>&#9998; $rchange->user</span> " . human_time_since($rchange->timestamp) . " <span class='$size_display_class' title='$title_display'>($size_display)</span></li>\n";
+				}
+				$content .= "\t\t</ul>";
+			}
+			else
+			{
+				// No changes yet :(
+				$content .= "<p><em>None yet! Try making a few changes and then check back here.</em></p>\n";
+			}
 			
 			echo(page_renderer::render("Recent Changes - $settings->sitename", $content));
 		});
@@ -59,13 +73,13 @@ register_module([
 			error_log("Size diff: $size_diff");
 			
 			$recentchanges = json_decode(file_get_contents($paths->recentchanges), true);
-			$recentchanges[] = [
+			array_unshift($recentchanges, [
 				"timestamp" => time(),
 				"page" => $env->page,
 				"user" => $env->user,
 				"newsize" => $newsize,
 				"sizediff" => $size_diff
-			];
+			]);
 			
 			// Limit the number of entries in the recent changes file if we've
 			// been asked to.
diff --git a/settings.fragment.php b/settings.fragment.php
index 3c44586..db3de38 100644
--- a/settings.fragment.php
+++ b/settings.fragment.php
@@ -311,6 +311,11 @@ textarea ~ input[type=submit] { margin: 0.5rem 0.8rem; padding: 0.5rem; font-wei
 .tag-list li { display: inline-block; margin: 1rem; }
 .mini-tag { background: #d2c3dd; padding: 0.2rem 0.4rem; color: #fb701a; text-decoration: none; }
 
+.larger { color: rgb(9, 180, 0); }
+.smaller { color: rgb(207, 28, 17); }
+.nochange { color: rgb(132, 123, 199); font-style: italic; }
+.significant { font-weight: bold; }
+
 footer { padding: 2rem; }
 /* #ffdb6d #36962c */";
 
