1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-11-26 05:32:59 +00:00

Improve settings configuration UI text

This commit is contained in:
Starbeamrainbowlabs 2016-12-11 19:28:03 +00:00
parent 3ff574b3fa
commit 16f5e8fa2c
3 changed files with 48 additions and 23 deletions

View file

@ -154,9 +154,11 @@ $guiConfig = <<<'GUICONFIG'
} }
GUICONFIG; GUICONFIG;
$settingsFilename = "peppermint.json";
$guiConfig = json_decode($guiConfig); $guiConfig = json_decode($guiConfig);
$settings = new stdClass(); $settings = new stdClass();
if(!file_exists("peppermint.json")) if(!file_exists($settingsFilename))
{ {
// Copy the default settings over to the main settings array // Copy the default settings over to the main settings array
foreach ($guiConfig as $key => $value) foreach ($guiConfig as $key => $value)
@ -313,19 +315,19 @@ if($settings->css === "auto")
/////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////
$version = "v0.13-dev"; $version = "v0.13-dev";
/// Environment /// /// Environment ///
$env = new stdClass(); $env = new stdClass(); // The environment object
$env->action = $settings->defaultaction; $env->action = $settings->defaultaction; // The action requested by the user
$env->page = ""; $env->page = ""; // The page name
$env->page_filename = ""; $env->page_filename = ""; // The filename that the page is stored in
$env->is_history_revision = false; $env->is_history_revision = false; // Whether we are looking at a history revision
$env->history = new stdClass(); $env->history = new stdClass(); // History revision information
$env->history->revision_number = -1; $env->history->revision_number = -1; // The revision number of the current page
$env->history->revision_data = false; $env->history->revision_data = false; // The revision data object from the page index
$env->user = "Anonymous"; $env->user = "Anonymous"; // The user's name
$env->is_logged_in = false; $env->is_logged_in = false; // Whether the user is logged in
$env->is_admin = false; $env->is_admin = false; // Whether the user is an admin (moderator)
$env->storage_prefix = $settings->data_storage_dir . DIRECTORY_SEPARATOR; $env->storage_prefix = $settings->data_storage_dir . DIRECTORY_SEPARATOR; // The data storage directory
$env->perfdata = new stdClass(); $env->perfdata = new stdClass(); // Performance data
/// Paths /// /// Paths ///
$paths = new stdClass(); $paths = new stdClass();
$paths->pageindex = "pageindex.json"; // The pageindex $paths->pageindex = "pageindex.json"; // The pageindex
@ -337,6 +339,7 @@ foreach ($paths as &$path) {
$path = $env->storage_prefix . $path; $path = $env->storage_prefix . $path;
} }
$paths->settings_file = $settingsFilename; // The master settings file
$paths->upload_file_prefix = "Files/"; // The prefix to add to uploaded files $paths->upload_file_prefix = "Files/"; // The prefix to add to uploaded files
session_start(); session_start();
@ -1947,7 +1950,8 @@ register_module([
} }
$content = "<h1>Master Control Panel</h1>\n"; $content = "<h1>Master Control Panel</h1>\n";
$content .= "<p>This page lets you configure the site settings. Please be careful - you can break things easily on this page if you're not careful!</p>\n"; $content .= "<p>This page lets you configure $settings->sitename's master settings. Please be careful - you can break things easily on this page if you're not careful!</p>\n";
$content .= "<p>Mouse over the name of each the settings to see a description of what it does.</p>\n";
$content .= "<form action='?action=configure-save' method='post'>\n"; $content .= "<form action='?action=configure-save' method='post'>\n";
foreach($guiConfig as $configKey => $configData) foreach($guiConfig as $configKey => $configData)
@ -2015,7 +2019,7 @@ register_module([
add_action("configure-save", function () { add_action("configure-save", function () {
global $env, $settings, $defaultCSS; global $env, $settings, $paths, $defaultCSS;
// If the user isn't an admin, then the regular configuration page will display an appropriate error // If the user isn't an admin, then the regular configuration page will display an appropriate error
if(!$env->is_admin) if(!$env->is_admin)
@ -2055,8 +2059,18 @@ register_module([
$newSettings->$configKey = $configValue; $newSettings->$configKey = $configValue;
} }
header("content-type: application/json"); // Take a backup of the current settings file
exit(json_encode($newSettings, JSON_PRETTY_PRINT)); rename($paths->settings_file, "$paths->settings_file.bak");
// Save the new settings file
file_put_contents($paths->settings_file, json_encode($newSettings, JSON_PRETTY_PRINT));
$content = "<h1>Master settings updated sucessfully</h1>\n";
$content .= "<p>$settings->sitename's master settings file has been updated successfully. A backup of the original settings has been created under the name <code>peppermint.json.bak</code>, just in case. You can <a href='?action=configure'>go back</a> and continue editing the master settings file, or you can go to the <a href='?action=view&page=" . rawurlencode($settings->defaultpage) . "'>" . htmlentities($settings->defaultpage) . "</a>.</p>\n";
$content .= "<p>For reference, the newly generated master settings file is as follows:</p>\n";
$content .= "<textarea name='content'>";
$content .= json_encode($newSettings, JSON_PRETTY_PRINT);
$content .= "</textarea>\n";
exit(page_renderer::render_main("Master Settings Updated - $settings->sitename", $content));
}); });
add_help_section("800-raw-page-content", "Viewing Raw Page Content", "<p>Although you can use the edit page to view a page's source, you can also ask $settings->sitename to send you the raw page source and nothing else. This feature is intented for those who want to automate their interaction with $settings->sitename.</p> add_help_section("800-raw-page-content", "Viewing Raw Page Content", "<p>Although you can use the edit page to view a page's source, you can also ask $settings->sitename to send you the raw page source and nothing else. This feature is intented for those who want to automate their interaction with $settings->sitename.</p>

View file

@ -50,7 +50,7 @@
"author": "Starbeamrainbowlabs", "author": "Starbeamrainbowlabs",
"description": "The module everyone has been waiting for! Adds a web based gui that lets mods change the wiki settings.", "description": "The module everyone has been waiting for! Adds a web based gui that lets mods change the wiki settings.",
"id": "feature-guiconfig", "id": "feature-guiconfig",
"lastupdate": 1481484131, "lastupdate": 1481484345,
"optional": false "optional": false
}, },
{ {

View file

@ -35,7 +35,8 @@ register_module([
} }
$content = "<h1>Master Control Panel</h1>\n"; $content = "<h1>Master Control Panel</h1>\n";
$content .= "<p>This page lets you configure the site settings. Please be careful - you can break things easily on this page if you're not careful!</p>\n"; $content .= "<p>This page lets you configure $settings->sitename's master settings. Please be careful - you can break things easily on this page if you're not careful!</p>\n";
$content .= "<p>Mouse over the name of each the settings to see a description of what it does.</p>\n";
$content .= "<form action='?action=configure-save' method='post'>\n"; $content .= "<form action='?action=configure-save' method='post'>\n";
foreach($guiConfig as $configKey => $configData) foreach($guiConfig as $configKey => $configData)
@ -103,7 +104,7 @@ register_module([
add_action("configure-save", function () { add_action("configure-save", function () {
global $env, $settings, $defaultCSS; global $env, $settings, $paths, $defaultCSS;
// If the user isn't an admin, then the regular configuration page will display an appropriate error // If the user isn't an admin, then the regular configuration page will display an appropriate error
if(!$env->is_admin) if(!$env->is_admin)
@ -143,8 +144,18 @@ register_module([
$newSettings->$configKey = $configValue; $newSettings->$configKey = $configValue;
} }
header("content-type: application/json"); // Take a backup of the current settings file
exit(json_encode($newSettings, JSON_PRETTY_PRINT)); rename($paths->settings_file, "$paths->settings_file.bak");
// Save the new settings file
file_put_contents($paths->settings_file, json_encode($newSettings, JSON_PRETTY_PRINT));
$content = "<h1>Master settings updated sucessfully</h1>\n";
$content .= "<p>$settings->sitename's master settings file has been updated successfully. A backup of the original settings has been created under the name <code>peppermint.json.bak</code>, just in case. You can <a href='?action=configure'>go back</a> and continue editing the master settings file, or you can go to the <a href='?action=view&page=" . rawurlencode($settings->defaultpage) . "'>" . htmlentities($settings->defaultpage) . "</a>.</p>\n";
$content .= "<p>For reference, the newly generated master settings file is as follows:</p>\n";
$content .= "<textarea name='content'>";
$content .= json_encode($newSettings, JSON_PRETTY_PRINT);
$content .= "</textarea>\n";
exit(page_renderer::render_main("Master Settings Updated - $settings->sitename", $content));
}); });
add_help_section("800-raw-page-content", "Viewing Raw Page Content", "<p>Although you can use the edit page to view a page's source, you can also ask $settings->sitename to send you the raw page source and nothing else. This feature is intented for those who want to automate their interaction with $settings->sitename.</p> add_help_section("800-raw-page-content", "Viewing Raw Page Content", "<p>Although you can use the edit page to view a page's source, you can also ask $settings->sitename to send you the raw page source and nothing else. This feature is intented for those who want to automate their interaction with $settings->sitename.</p>