From 30bfe144fe2630e17378b0ff88cc2d868fa0ab1e Mon Sep 17 00:00:00 2001
From: Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com>
Date: Sun, 3 Apr 2016 16:10:37 +0100
Subject: [PATCH] Add uploads to the recent changes page

---
 build/index.php                    | 23 +++++++++++++++++++++--
 module_index.json                  |  6 +++---
 modules/feature-recent-changes.php | 11 +++++++++--
 modules/feature-upload.php         | 11 +++++++++++
 settings.fragment.php              |  1 +
 5 files changed, 45 insertions(+), 7 deletions(-)

diff --git a/build/index.php b/build/index.php
index 44396d7..da243be 100644
--- a/build/index.php
+++ b/build/index.php
@@ -355,6 +355,7 @@ textarea ~ input[type=submit] { margin: 0.5rem 0.8rem; padding: 0.5rem; font-wei
 .deletion, .deletion > .editor { text-decoration: line-through; }
 
 .newpage::before { content: \"N\"; margin: 0 0.3em 0 -1em; font-weight: bolder; text-decoration: underline dotted; }
+.upload::before { content: \"\\1f845\"; margin: 0 0.1em 0 -1.1em; }
 
 footer { padding: 2rem; }
 /* #ffdb6d #36962c */";
@@ -1566,7 +1567,7 @@ function render_sidebar($pageindex, $root_pagename = "")
 
 register_module([
 	"name" => "Recent Changes",
-	"version" => "0.3",
+	"version" => "0.3.2",
 	"author" => "Starbeamrainbowlabs",
 	"description" => "Adds recent changes. Access through the 'recent-changes' action.",
 	"id" => "feature-recent-changes",
@@ -1677,6 +1678,7 @@ function render_recent_change($rchange)
 	$pageDisplayName = $rchange->page;
 	if(isset($pageindex->$pageDisplayName) and !empty($pageindex->$pageDisplayName->redirect))
 		$pageDisplayName = "<em>$pageDisplayName</em>";
+	$pageDisplayLink = "<a href='?page=" . rawurlencode($rchange->page) . "'>$pageDisplayName</a>";
 	
 	$editorDisplayHtml = "<span class='editor'>&#9998; $rchange->user</span>";
 	$timeDisplayHtml = "<time class='cursor-query' title='" . date("l jS \of F Y \a\\t h:ia T", $rchange->timestamp) . "'>" . human_time_since($rchange->timestamp) . "</time>";
@@ -1698,12 +1700,18 @@ function render_recent_change($rchange)
 			if(!empty($rchange->newpage))
 				$resultClasses[] = "newpage";
 			
-			$result .= "<a href='?page=" . rawurlencode($rchange->page) . "'>$pageDisplayName</a> $editorDisplayHtml $timeDisplayHtml <span class='$size_display_class' title='$title_display'>($size_display)</span>";
+			$result .= "$pageDisplayLink $editorDisplayHtml $timeDisplayHtml <span class='$size_display_class' title='$title_display'>($size_display)</span>";
 			break;
 		
 		case "deletion":
 			$resultClasses[] = "deletion";
 			$result .= "$pageDisplayName $editorDisplayHtml $timeDisplayHtml";
+			break;
+		
+		case "upload":
+			$resultClasses[] = "upload";
+			$result .= "$pageDisplayLink $editorDisplayHtml $timeDisplayHtml (" . human_filesize($rchange->filesize) . ")";
+			break;
 	}
 	
 	$resultAttributes = " " . (count($resultClasses) > 0 ? "class='" . implode(" ", $resultClasses) . "'" : "");
@@ -2437,6 +2445,17 @@ register_module([
 					// Save the pageindex
 					file_put_contents($paths->pageindex, json_encode($pageindex, JSON_PRETTY_PRINT));
 					
+					if(module_exists("feature-recent-changes"))
+					{
+						add_recent_change([
+							"type" => "upload",
+							"timestamp" => time(),
+							"page" => $new_filename,
+							"user" => $env->user,
+							"filesize" => filesize($entry->uploadedfilepath)
+						]);
+					}
+					
 					header("location: ?action=view&page=$new_filename&upload=success");
 					
 					break;
diff --git a/module_index.json b/module_index.json
index 2fc2df3..9ac84a2 100644
--- a/module_index.json
+++ b/module_index.json
@@ -37,11 +37,11 @@
     },
     {
         "name": "Recent Changes",
-        "version": "0.3",
+        "version": "0.3.2",
         "author": "Starbeamrainbowlabs",
         "description": "Adds recent changes. Access through the 'recent-changes' action.",
         "id": "feature-recent-changes",
-        "lastupdate": 1459695505,
+        "lastupdate": 1459695897,
         "optional": false
     },
     {
@@ -68,7 +68,7 @@
         "author": "Starbeamrainbowlabs",
         "description": "Adds the ability to upload files to Pepperminty Wiki. Uploaded files act as pages and have the special 'File:' prefix.",
         "id": "feature-upload",
-        "lastupdate": 1459627881,
+        "lastupdate": 1459695742,
         "optional": false
     },
     {
diff --git a/modules/feature-recent-changes.php b/modules/feature-recent-changes.php
index 0016a55..563cc63 100644
--- a/modules/feature-recent-changes.php
+++ b/modules/feature-recent-changes.php
@@ -1,7 +1,7 @@
 <?php
 register_module([
 	"name" => "Recent Changes",
-	"version" => "0.3",
+	"version" => "0.3.2",
 	"author" => "Starbeamrainbowlabs",
 	"description" => "Adds recent changes. Access through the 'recent-changes' action.",
 	"id" => "feature-recent-changes",
@@ -112,6 +112,7 @@ function render_recent_change($rchange)
 	$pageDisplayName = $rchange->page;
 	if(isset($pageindex->$pageDisplayName) and !empty($pageindex->$pageDisplayName->redirect))
 		$pageDisplayName = "<em>$pageDisplayName</em>";
+	$pageDisplayLink = "<a href='?page=" . rawurlencode($rchange->page) . "'>$pageDisplayName</a>";
 	
 	$editorDisplayHtml = "<span class='editor'>&#9998; $rchange->user</span>";
 	$timeDisplayHtml = "<time class='cursor-query' title='" . date("l jS \of F Y \a\\t h:ia T", $rchange->timestamp) . "'>" . human_time_since($rchange->timestamp) . "</time>";
@@ -133,12 +134,18 @@ function render_recent_change($rchange)
 			if(!empty($rchange->newpage))
 				$resultClasses[] = "newpage";
 			
-			$result .= "<a href='?page=" . rawurlencode($rchange->page) . "'>$pageDisplayName</a> $editorDisplayHtml $timeDisplayHtml <span class='$size_display_class' title='$title_display'>($size_display)</span>";
+			$result .= "$pageDisplayLink $editorDisplayHtml $timeDisplayHtml <span class='$size_display_class' title='$title_display'>($size_display)</span>";
 			break;
 		
 		case "deletion":
 			$resultClasses[] = "deletion";
 			$result .= "$pageDisplayName $editorDisplayHtml $timeDisplayHtml";
+			break;
+		
+		case "upload":
+			$resultClasses[] = "upload";
+			$result .= "$pageDisplayLink $editorDisplayHtml $timeDisplayHtml (" . human_filesize($rchange->filesize) . ")";
+			break;
 	}
 	
 	$resultAttributes = " " . (count($resultClasses) > 0 ? "class='" . implode(" ", $resultClasses) . "'" : "");
diff --git a/modules/feature-upload.php b/modules/feature-upload.php
index 141fa98..c607b12 100644
--- a/modules/feature-upload.php
+++ b/modules/feature-upload.php
@@ -155,6 +155,17 @@ register_module([
 					// Save the pageindex
 					file_put_contents($paths->pageindex, json_encode($pageindex, JSON_PRETTY_PRINT));
 					
+					if(module_exists("feature-recent-changes"))
+					{
+						add_recent_change([
+							"type" => "upload",
+							"timestamp" => time(),
+							"page" => $new_filename,
+							"user" => $env->user,
+							"filesize" => filesize($entry->uploadedfilepath)
+						]);
+					}
+					
 					header("location: ?action=view&page=$new_filename&upload=success");
 					
 					break;
diff --git a/settings.fragment.php b/settings.fragment.php
index f9ac77b..1b6c398 100644
--- a/settings.fragment.php
+++ b/settings.fragment.php
@@ -352,6 +352,7 @@ textarea ~ input[type=submit] { margin: 0.5rem 0.8rem; padding: 0.5rem; font-wei
 .deletion, .deletion > .editor { text-decoration: line-through; }
 
 .newpage::before { content: \"N\"; margin: 0 0.3em 0 -1em; font-weight: bolder; text-decoration: underline dotted; }
+.upload::before { content: \"\\1f845\"; margin: 0 0.1em 0 -1.1em; }
 
 footer { padding: 2rem; }
 /* #ffdb6d #36962c */";
