From edc1a694ddb3fbc9a45797e728d5e5b75c162c76 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Wed, 8 Jul 2020 19:35:42 +0100 Subject: [PATCH] feature-comments: add 2 new settings --- Changelog.md | 3 +++ modules/feature-comments.php | 16 +++++++++++++--- peppermint.guiconfig.json | 4 +++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Changelog.md b/Changelog.md index 762a9bf..ad4b678 100644 --- a/Changelog.md +++ b/Changelog.md @@ -21,6 +21,9 @@ This file holds the changelog for Pepperminty Wiki. This is the master list of t - Added similar page suggestions between the bottom of the page content and the comments - control it with the new `similarpages_enabled` and `similarpages_count` settings. - Added absolute redirect support - use it like this: `# REDIRECT [display text](INSERT_REDIRECT_URL_HERE)` - It's disabled by default due to potential security issues with untrusted editors - enable it with the new `redirect_absolute_enable` setting (default: : `false`) + - Added new settings to control the commenting system + - `comment_enabled` controls whether _anyone_ is allowed to comment at all or not + - `comment_hide_all` determines whether the commenting system displays anything at all (if disabled, it's (almost) like the `feature-comments` doesn't exist - consider using the downloader to exclude the commenting system instead of enabling this setting) ### Changed - Fiddled with Parsedown & ParsedownExtra versions diff --git a/modules/feature-comments.php b/modules/feature-comments.php index 703b64f..d89af84 100644 --- a/modules/feature-comments.php +++ b/modules/feature-comments.php @@ -8,6 +8,10 @@ register_module([ "code" => function() { global $env, $settings; + // Don't do anything if we're not wanted + if($settings->comment_hide_all) + return; + /** * @api {post} ?action=comment Comment on a page * @apiName Comment @@ -35,6 +39,12 @@ register_module([ $reply_to = $_POST["replyto"] ?? null; $message = $_POST["message"] ?? ""; + if(!$settings->comment_enabled) { + http_response_code(401); + exit(page_renderer::render_main("Commenting disabled - $settings->sitename", "

Your comment couldn't be posted because $settings->sitename currently has commenting disabled. Here's the comment you tried to post:

+ ")); + } + if(!$env->is_logged_in && !$settings->anoncomments) { http_response_code(401); exit(page_renderer::render_main("Error posting comment - $settings->sitename", "

Your comment couldn't be posted because you're not logged in. You can login here. Here's the comment you tried to post:

@@ -238,7 +248,7 @@ register_module([ if($env->action == "view") { page_renderer::register_part_preprocessor(function(&$parts) { - global $env; + global $env, $settings; $comments_filename = get_comment_filename($env->page); $comments_data = file_exists($comments_filename) ? json_decode(file_get_contents($comments_filename)) : []; @@ -246,7 +256,7 @@ register_module([ $comments_html = "