From c4796c57bd4596deade139a5e82787b2ccbf767e Mon Sep 17 00:00:00 2001
From: Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com>
Date: Fri, 23 Dec 2016 18:18:39 +0000
Subject: [PATCH] Add user preferences button next to username

---
 Changelog.md              |  4 ++++
 build/index.php           | 10 ++++++++--
 core.php                  |  7 ++++++-
 peppermint.guiconfig.json |  3 ++-
 4 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/Changelog.md b/Changelog.md
index 4706d1e..b6b658f 100755
--- a/Changelog.md
+++ b/Changelog.md
@@ -9,6 +9,10 @@
  - Added dynamic server-calculated page suggestions. Very helpful for larger wikis. Currently works best in firefox. Part of the `feature-search` module.
  - Added Alt + Enter support to the page search box. Works just like your browser's address bar - opens results in a new tab instead of the current one.
  - Initial UI for configuring settings! Some things still have to be done by editing the file, but it's certainly a start :D
+ - User preferences!
+     - Accessible via the (by default) small cog next to your username when you're logged in
+     - The cog is customisable via the new `user_preferences_button_text` setting.
+     - You can change your password
  - [Module API] Added `$env->user_data` and `save_userdata()` to interact with the logged in users' data
 
 ### Changed
diff --git a/build/index.php b/build/index.php
index 9d39daa..f5e5f9b 100644
--- a/build/index.php
+++ b/build/index.php
@@ -51,7 +51,8 @@ $guiConfig = <<<'GUICONFIG'
 		}
 	}},
 	"admins": {"type": "array", "description": "An array of usernames that are administrators. Administrators can delete and move pages.", "default": [ "admin" ]},
-	"anonymous_user_name": { "type": "text", "description": "THe default name for anonymous users.", "default": "Anonymous" },
+	"anonymous_user_name": { "type": "text", "description": "The default name for anonymous users.", "default": "Anonymous" },
+	"user_preferences_button_text": { "type": "text", "description": "The text to display on the button that lets logged in users chang  their settings. Defaults to a cog (aka a 'gear' in unicode-land).", "default": "&#x2699;" },
 	"use_sha3": {"type": "checkbox", "description": "Whether to use the new sha3 hashing algorithm for passwords etc.", "default": false },
 	"require_login_view": {"type": "checkbox", "description": "Whether to require that users login before they do anything else. Best used with the data_storage_dir option.", "default": false},
 	"data_storage_dir": {"type": "text", "description": "The directory in which to store all files, except the main index.php.", "default": "."},
@@ -1374,7 +1375,12 @@ class page_renderer
 					case "user-status": // Renders the user status box
 						if($env->is_logged_in)
 						{
-							$result .= "<span class='inflexible logged-in" . ($env->is_logged_in ? " moderator" : " normal-user") . "'>" . self::render_username($env->user) . " <small>(<a href='index.php?action=logout'>Logout</a>)</small></span>";
+							$result .= "<span class='inflexible logged-in" . ($env->is_logged_in ? " moderator" : " normal-user") . "'>";
+							if(module_exists("feature-user-preferences")) {
+								$result .= "<a href='?action=user-preferences'>$settings->user_preferences_button_text</a> ";
+							}
+							$result .= self::render_username($env->user) . " <small>(<a href='index.php?action=logout'>Logout</a>)</small>";
+							$result .= "</span>";
 							//$result .= page_renderer::$nav_divider;
 						}
 						else
diff --git a/core.php b/core.php
index 8f8920b..eadd389 100644
--- a/core.php
+++ b/core.php
@@ -1057,7 +1057,12 @@ class page_renderer
 					case "user-status": // Renders the user status box
 						if($env->is_logged_in)
 						{
-							$result .= "<span class='inflexible logged-in" . ($env->is_logged_in ? " moderator" : " normal-user") . "'>" . self::render_username($env->user) . " <small>(<a href='index.php?action=logout'>Logout</a>)</small></span>";
+							$result .= "<span class='inflexible logged-in" . ($env->is_logged_in ? " moderator" : " normal-user") . "'>";
+							if(module_exists("feature-user-preferences")) {
+								$result .= "<a href='?action=user-preferences'>$settings->user_preferences_button_text</a> ";
+							}
+							$result .= self::render_username($env->user) . " <small>(<a href='index.php?action=logout'>Logout</a>)</small>";
+							$result .= "</span>";
 							//$result .= page_renderer::$nav_divider;
 						}
 						else
diff --git a/peppermint.guiconfig.json b/peppermint.guiconfig.json
index 8a900c9..11a4540 100644
--- a/peppermint.guiconfig.json
+++ b/peppermint.guiconfig.json
@@ -29,7 +29,8 @@
 		}
 	}},
 	"admins": {"type": "array", "description": "An array of usernames that are administrators. Administrators can delete and move pages.", "default": [ "admin" ]},
-	"anonymous_user_name": { "type": "text", "description": "THe default name for anonymous users.", "default": "Anonymous" },
+	"anonymous_user_name": { "type": "text", "description": "The default name for anonymous users.", "default": "Anonymous" },
+	"user_preferences_button_text": { "type": "text", "description": "The text to display on the button that lets logged in users chang  their settings. Defaults to a cog (aka a 'gear' in unicode-land).", "default": "&#x2699;" },
 	"use_sha3": {"type": "checkbox", "description": "Whether to use the new sha3 hashing algorithm for passwords etc.", "default": false },
 	"require_login_view": {"type": "checkbox", "description": "Whether to require that users login before they do anything else. Best used with the data_storage_dir option.", "default": false},
 	"data_storage_dir": {"type": "text", "description": "The directory in which to store all files, except the main index.php.", "default": "."},
