From 35a1161be457b66c496f924d83e6d97bd15883bc Mon Sep 17 00:00:00 2001
From: Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com>
Date: Thu, 22 Oct 2015 08:51:43 +0100
Subject: [PATCH] Bugfix: Include system_mime_type_extensions not
 system_extension_mime_types

---
 build/index.php            | 10 +++++-----
 core.php                   |  9 +++++----
 module_index.json          |  2 +-
 modules/feature-upload.php |  1 -
 4 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/build/index.php b/build/index.php
index 5885d47..178aa4c 100644
--- a/build/index.php
+++ b/build/index.php
@@ -537,9 +537,10 @@ function starts_with($haystack, $needle)
      return (substr($haystack, 0, $length) === $needle);
 }
 
-function system_extension_mime_types() {
+function system_mime_type_extensions() {
 	global $settings;
-    # Returns the system MIME type mapping of extensions to MIME types, as defined in /etc/mime.types.
+    # Returns the system MIME type mapping of MIME types to extensions, as defined in /etc/mime.types (considering the first
+    # extension listed to be canonical).
     $out = array();
     $file = fopen($settings->mime_extension_mappings_location, 'r');
     while(($line = fgets($file)) !== false) {
@@ -550,8 +551,8 @@ function system_extension_mime_types() {
         if(count($parts) == 1)
             continue;
         $type = array_shift($parts);
-        foreach($parts as $part)
-            $out[$part] = $type;
+        if(!isset($out[$type]))
+            $out[$type] = array_shift($parts);
     }
     fclose($file);
     return $out;
@@ -1290,7 +1291,6 @@ register_module([
 						case "image":
 							$extra_data = [];
 							$imagesize = getimagesize($temp_filename, $extra_data);
-							var_dump($imagesize);
 							// Make sure that the image size is defined
 							if(!is_int($imagesize[0]) or !is_int($imagesize[1]))
 								exit(page_renderer::render("Upload Error - $settings->sitename", "<p>The file that you uploaded doesn't appear to be an image. $settings->sitename currently only supports uploading images (videos coming soon). <a href='?action=upload'>Go back to try again</a>.</p>"));
diff --git a/core.php b/core.php
index a37456f..7fc6bb4 100644
--- a/core.php
+++ b/core.php
@@ -253,9 +253,10 @@ function starts_with($haystack, $needle)
      return (substr($haystack, 0, $length) === $needle);
 }
 
-function system_extension_mime_types() {
+function system_mime_type_extensions() {
 	global $settings;
-    # Returns the system MIME type mapping of extensions to MIME types, as defined in /etc/mime.types.
+    # Returns the system MIME type mapping of MIME types to extensions, as defined in /etc/mime.types (considering the first
+    # extension listed to be canonical).
     $out = array();
     $file = fopen($settings->mime_extension_mappings_location, 'r');
     while(($line = fgets($file)) !== false) {
@@ -266,8 +267,8 @@ function system_extension_mime_types() {
         if(count($parts) == 1)
             continue;
         $type = array_shift($parts);
-        foreach($parts as $part)
-            $out[$part] = $type;
+        if(!isset($out[$type]))
+            $out[$type] = array_shift($parts);
     }
     fclose($file);
     return $out;
diff --git a/module_index.json b/module_index.json
index 06d4a52..2a4304a 100644
--- a/module_index.json
+++ b/module_index.json
@@ -50,7 +50,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": 1445500026,
+        "lastupdate": 1445500053,
         "optional": false
     },
     {
diff --git a/modules/feature-upload.php b/modules/feature-upload.php
index ed4fb88..cce35af 100644
--- a/modules/feature-upload.php
+++ b/modules/feature-upload.php
@@ -72,7 +72,6 @@ register_module([
 						case "image":
 							$extra_data = [];
 							$imagesize = getimagesize($temp_filename, $extra_data);
-							var_dump($imagesize);
 							// Make sure that the image size is defined
 							if(!is_int($imagesize[0]) or !is_int($imagesize[1]))
 								exit(page_renderer::render("Upload Error - $settings->sitename", "<p>The file that you uploaded doesn't appear to be an image. $settings->sitename currently only supports uploading images (videos coming soon). <a href='?action=upload'>Go back to try again</a>.</p>"));
