From 2861731c8361004a58d9c2948e61ced37c98c012 Mon Sep 17 00:00:00 2001
From: Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com>
Date: Mon, 22 Aug 2016 14:56:34 +0100
Subject: [PATCH] Fiddle with the file uploader to fix #100.

---
 build/index.php            | 14 +++++++-------
 module_index.json          |  6 +++---
 modules/feature-upload.php | 14 +++++++-------
 3 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/build/index.php b/build/index.php
index 723b90c..f2655a6 100755
--- a/build/index.php
+++ b/build/index.php
@@ -2677,7 +2677,7 @@ class search
 
 register_module([
 	"name" => "Uploader",
-	"version" => "0.5.6",
+	"version" => "0.5.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",
@@ -2805,8 +2805,8 @@ register_module([
 					
 					// Override the detected file extension if a file extension
 					// is explicitly specified in the settings
-					if(isset($settings->mime_mappings_overrides[$mime_type]))
-						$file_extension = $settings->mime_mappings_overrides[$mime_type];
+					if(isset($settings->mime_mappings_overrides->$mime_type))
+						$file_extension = $settings->mime_mappings_overrides->$mime_type;
 					
 					if(in_array($file_extension, [ "php", ".htaccess", "asp" ]))
 					{
@@ -2821,8 +2821,8 @@ register_module([
 					if(isset($pageindex->$new_filename))
 						exit(page_renderer::render("Upload Error - $settings->sitename", "<p>A page or file has already been uploaded with the name '$new_filename'. Try deleting it first. If you do not have permission to delete things, try contacting one of the moderators.</p>"));
 					
-					if(!file_exists("Files"))
-						mkdir("Files", 0664);
+					if(!file_exists($env->storage_prefix . "Files"))
+						mkdir($env->storage_prefix . "Files", 0775);
 					
 					if(!move_uploaded_file($temp_filename, $env->storage_prefix . $new_filename))
 					{
@@ -2871,7 +2871,7 @@ register_module([
 							"timestamp" => time(),
 							"page" => $new_filename,
 							"user" => $env->user,
-							"filesize" => filesize($entry->uploadedfilepath)
+							"filesize" => filesize($env->storage_prefix . $entry->uploadedfilepath)
 						]);
 					}
 					
@@ -3110,7 +3110,7 @@ register_module([
 				$fileInfo = [];
 				$fileInfo["Name"] = str_replace("File/", "", $filepath);
 				$fileInfo["Type"] = $mime_type;
-				$fileInfo["Size"] = human_filesize(filesize($filepath));
+				$fileInfo["Size"] = human_filesize(filesize($env->storage_prefix . $filepath));
 				switch($fileTypeDisplay)
 				{
 					case "image":
diff --git a/module_index.json b/module_index.json
index 7c50c65..7243672 100755
--- a/module_index.json
+++ b/module_index.json
@@ -73,11 +73,11 @@
     },
     {
         "name": "Uploader",
-        "version": "0.5.6",
+        "version": "0.5.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": 1466582736,
+        "lastupdate": 1471874150,
         "optional": false
     },
     {
@@ -203,7 +203,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": 1471860654,
+        "lastupdate": 1471860869,
         "optional": false
     }
 ]
\ No newline at end of file
diff --git a/modules/feature-upload.php b/modules/feature-upload.php
index 56ab5fa..ae711a0 100644
--- a/modules/feature-upload.php
+++ b/modules/feature-upload.php
@@ -1,7 +1,7 @@
 <?php
 register_module([
 	"name" => "Uploader",
-	"version" => "0.5.6",
+	"version" => "0.5.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",
@@ -129,8 +129,8 @@ register_module([
 					
 					// Override the detected file extension if a file extension
 					// is explicitly specified in the settings
-					if(isset($settings->mime_mappings_overrides[$mime_type]))
-						$file_extension = $settings->mime_mappings_overrides[$mime_type];
+					if(isset($settings->mime_mappings_overrides->$mime_type))
+						$file_extension = $settings->mime_mappings_overrides->$mime_type;
 					
 					if(in_array($file_extension, [ "php", ".htaccess", "asp" ]))
 					{
@@ -145,8 +145,8 @@ register_module([
 					if(isset($pageindex->$new_filename))
 						exit(page_renderer::render("Upload Error - $settings->sitename", "<p>A page or file has already been uploaded with the name '$new_filename'. Try deleting it first. If you do not have permission to delete things, try contacting one of the moderators.</p>"));
 					
-					if(!file_exists("Files"))
-						mkdir("Files", 0664);
+					if(!file_exists($env->storage_prefix . "Files"))
+						mkdir($env->storage_prefix . "Files", 0775);
 					
 					if(!move_uploaded_file($temp_filename, $env->storage_prefix . $new_filename))
 					{
@@ -195,7 +195,7 @@ register_module([
 							"timestamp" => time(),
 							"page" => $new_filename,
 							"user" => $env->user,
-							"filesize" => filesize($entry->uploadedfilepath)
+							"filesize" => filesize($env->storage_prefix . $entry->uploadedfilepath)
 						]);
 					}
 					
@@ -434,7 +434,7 @@ register_module([
 				$fileInfo = [];
 				$fileInfo["Name"] = str_replace("File/", "", $filepath);
 				$fileInfo["Type"] = $mime_type;
-				$fileInfo["Size"] = human_filesize(filesize($filepath));
+				$fileInfo["Size"] = human_filesize(filesize($env->storage_prefix . $filepath));
 				switch($fileTypeDisplay)
 				{
 					case "image":
