"Settings GUI", "version" => "0.1.1", "author" => "Starbeamrainbowlabs", "description" => "The module everyone has been waiting for! Adds a web based gui that lets mods change the wiki settings.", "id" => "feature-guiconfig", "code" => function() { global $settings; /** * @api {get} ?action=configure Get a page to change the global wiki settings * @apiName ConfigureSettings * @apiGroup Utility * @apiPermission Moderator */ /* * ██████ ██████ ███ ██ ███████ ██ ██████ ██ ██ ██████ ███████ * ██ ██ ██ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ * ██ ██ ██ ██ ██ ██ █████ ██ ██ ███ ██ ██ ██████ █████ * ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ * ██████ ██████ ██ ████ ██ ██ ██████ ██████ ██ ██ ███████ */ add_action("configure", function() { global $settings, $env, $guiConfig; if(!$env->is_admin) { $errorMessage = "
You don't have permission to change $settings->sitename's master settings.
\n"; if(!$env->is_logged_in) $errorMessage .= "You could try logging in.
"; else $errorMessage .= "You could try logging out and then logging in again with a different account that has the appropriate privileges..
"; exit(page_renderer::render_main("Error - $settings->sitename", $errorMessage)); } $content = "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!
\n"; $content .= "Mouse over the name of each setting to see a description of what it does.
\n"; $content .= "\n"; exit(page_renderer::render_main("Master Control Panel - $settings->sitename", $content)); }); /** * @api {post} ?action=configure-save Save changes to the global wiki settings * @apiName ConfigureSettings * @apiGroup Utility * @apiPermission Moderator */ /* * ██████ ██████ ███ ██ ███████ ██ ██████ ██ ██ ██████ ███████ * ██ ██ ██ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ * ██ ██ ██ ██ ██ ██ █████ ██ ██ ███ ██ ██ ██████ █████ █████ * ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ * ██████ ██████ ██ ████ ██ ██ ██████ ██████ ██ ██ ███████ * ███████ █████ ██ ██ ███████ * ██ ██ ██ ██ ██ ██ * ███████ ███████ ██ ██ █████ * ██ ██ ██ ██ ██ ██ * ███████ ██ ██ ████ ███████ */ add_action("configure-save", function () { global $env, $settings, $paths, $defaultCSS; // If the user isn't an admin, then the regular configuration page will display an appropriate error if(!$env->is_admin) { http_response_code(307); header("location: ?action=configure"); exit(); } // Build a new settings object $newSettings = new stdClass(); foreach($settings as $configKey => $rawValue) { $configValue = $rawValue; if(isset($_POST[$configKey])) { $decodedConfigValue = json_decode($_POST[$configKey]); if(json_last_error() === JSON_ERROR_NONE) $configValue = $decodedConfigValue; else $configValue = $_POST[$configKey]; // Convert boolean settings to a boolean, since POST // parameters don't decode correctly. if(is_bool($settings->$configKey)) $configValue = in_array($configValue, [ 1, "on"], true) ? true : false; // If the CSS hasn't changed, then we can replace it with // 'auto' - this will ensure that upon update the new // default CSS will be used. Also make sure we ignore line // ending nonsense & differences here, since they really // don't matter if($configKey === "css" && str_replace("\r\n", "\n", $defaultCSS) === str_replace("\r\n", "\n", $configValue)) $configValue = "auto"; } $newSettings->$configKey = $configValue; } // Take a backup of the current settings file 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 = "$settings->sitename's master settings file has been updated successfully. A backup of the original settings has been created under the name peppermint.json.bak
, just in case. You can go back and continue editing the master settings file, or you can go to the " . htmlentities($settings->defaultpage) . ".
For reference, the newly generated master settings file is as follows:
\n"; $content .= "\n"; exit(page_renderer::render_main("Master Settings Updated - $settings->sitename", $content)); }); add_help_section("800-raw-page-content", "Viewing Raw Page Content", "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.
To use this feature, navigate to the page for which you want to see the source, and then alter the action
parameter in the url's query string to be raw
. If the action
parameter doesn't exist, add it. Note that when used on an file's page this action will return the source of the description and not the file itself.