From 1c30d2543ba96d8ecfcc0a168ea00652406afe03 Mon Sep 17 00:00:00 2001
From: Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com>
Date: Tue, 27 Mar 2018 17:20:58 +0100
Subject: [PATCH] Add minified option to status action

---
 Changelog.md           | 1 +
 build/index.php        | 9 ++++++---
 module_index.json      | 2 +-
 modules/api-status.php | 9 ++++++---
 4 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/Changelog.md b/Changelog.md
index e8c5c1b..cbf0c55 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -19,6 +19,7 @@ This file holds the changelog for Pepperminty Wiki. This is the master list of t
      - You'll need to rebuild your search index for this fix to fully take effect (call the `invindex-rebuild` action as a mod or better)
  - Normalise utf8 text to avoid duplicate ids and missing search results.
  - Improved handling of mime types in some places in the API.
+ - Added `minified` option to `status` action to reduce data usage slightly
 
 ### Changed
  - Disallow uploads if editing is disabled. Previously files could still be uploaded even if editing was disabled - unless `upload_enabled` was set to `false`.
diff --git a/build/index.php b/build/index.php
index 4a9b5f9..b0ba5aa 100644
--- a/build/index.php
+++ b/build/index.php
@@ -2368,11 +2368,12 @@ register_module([
 	"code" => function() {
 		global $settings;
 		/**
-		 * @api {get} ?action=status	Get the json-formatted status of this wiki
+		 * @api {get} ?action=status[&minified=type]	Get the json-formatted status of this wiki
 		 * @apiName Status
 		 * @apiGroup Stats
 		 * @apiPermission Anonymous
-		 * 
+		 *
+		 * @apiParam	{boolean}	Whether or not the result should be minified JSON. Default: false
 		 */
 		
 		
@@ -2387,6 +2388,8 @@ register_module([
 				exit("Unfortunately, this API is currently only available in application/json at the moment, which you haven't indicated you accept in your http accept header. You said this in your accept header:\n" . $_SERVER["HTTP_ACCEPT"]);
 			}
 			
+			$minified = ($_GET["minified"] ?? "false") == "true";
+			
 			$action_names = array_keys(get_object_vars($actions));
 			sort($action_names);
 			
@@ -2398,7 +2401,7 @@ register_module([
 			$result->logo_url = $settings->favicon;
 			
 			header("content-type: application/json");
-			exit(json_encode($result, JSON_PRETTY_PRINT) . "\n");
+			exit($minified ? json_encode($result) : json_encode($result, JSON_PRETTY_PRINT) . "\n");
 		});
 		
 		add_help_section("960-api-status", "Wiki Status API", "<p></p>");
diff --git a/module_index.json b/module_index.json
index 8a54c3f..9b46d1d 100755
--- a/module_index.json
+++ b/module_index.json
@@ -41,7 +41,7 @@
         "author": "Starbeamrainbowlabs",
         "description": "Provides a basic JSON status action that provices a few useful bits of information for API consumption.",
         "id": "api-status",
-        "lastupdate": 1522166256,
+        "lastupdate": 1522167607,
         "optional": false
     },
     {
diff --git a/modules/api-status.php b/modules/api-status.php
index f68127f..cdd214c 100644
--- a/modules/api-status.php
+++ b/modules/api-status.php
@@ -8,11 +8,12 @@ register_module([
 	"code" => function() {
 		global $settings;
 		/**
-		 * @api {get} ?action=status	Get the json-formatted status of this wiki
+		 * @api {get} ?action=status[&minified=type]	Get the json-formatted status of this wiki
 		 * @apiName Status
 		 * @apiGroup Stats
 		 * @apiPermission Anonymous
-		 * 
+		 *
+		 * @apiParam	{boolean}	Whether or not the result should be minified JSON. Default: false
 		 */
 		
 		
@@ -27,6 +28,8 @@ register_module([
 				exit("Unfortunately, this API is currently only available in application/json at the moment, which you haven't indicated you accept in your http accept header. You said this in your accept header:\n" . $_SERVER["HTTP_ACCEPT"]);
 			}
 			
+			$minified = ($_GET["minified"] ?? "false") == "true";
+			
 			$action_names = array_keys(get_object_vars($actions));
 			sort($action_names);
 			
@@ -38,7 +41,7 @@ register_module([
 			$result->logo_url = $settings->favicon;
 			
 			header("content-type: application/json");
-			exit(json_encode($result, JSON_PRETTY_PRINT) . "\n");
+			exit($minified ? json_encode($result) : json_encode($result, JSON_PRETTY_PRINT) . "\n");
 		});
 		
 		add_help_section("960-api-status", "Wiki Status API", "<p></p>");
