Make redirect functionality conditional on @redirect_enabled (defaults to true).

This commit is contained in:
Bart Kamphorst
2019-10-07 11:37:52 +02:00
parent 5487563a71
commit 5dd6c40933
+3 -2
View File
@@ -89,6 +89,7 @@ module Precious
settings.wiki_options[:allow_editing] = settings.wiki_options.fetch(:allow_editing, true) settings.wiki_options[:allow_editing] = settings.wiki_options.fetch(:allow_editing, true)
@allow_editing = settings.wiki_options[:allow_editing] @allow_editing = settings.wiki_options[:allow_editing]
@critic_markup = settings.wiki_options[:critic_markup] @critic_markup = settings.wiki_options[:critic_markup]
@redirects_enabled = settings.wiki_options.fetch(:redirects_enabled, true)
@per_page_uploads = settings.wiki_options[:per_page_uploads] @per_page_uploads = settings.wiki_options[:per_page_uploads]
forbid unless @allow_editing || request.request_method == "GET" forbid unless @allow_editing || request.request_method == "GET"
@@ -278,7 +279,7 @@ module Precious
# Renaming preserves format, so add the page's format to the renamed path to retrieve the renamed page # Renaming preserves format, so add the page's format to the renamed path to retrieve the renamed page
new_path = "#{rename}.#{Gollum::Page.format_to_ext(page.format)}" new_path = "#{rename}.#{Gollum::Page.format_to_ext(page.format)}"
# Add a redirect from the old page to the new # Add a redirect from the old page to the new
wiki.add_redirect(page.url_path, new_path.gsub(/(^\/)/, '')) wiki.add_redirect(page.url_path, new_path.gsub(/(^\/)/, '')) if @redirects_enabled
page = wiki_page(new_path).page page = wiki_page(new_path).page
return if page.nil? return if page.nil?
@@ -553,7 +554,7 @@ module Precious
mustache :page mustache :page
elsif file = wiki.file(fullpath, wiki.ref, true) elsif file = wiki.file(fullpath, wiki.ref, true)
show_file(file) show_file(file)
elsif redirect_path = wiki.redirects[fullpath] elsif @redirects_enabled && redirect_path = wiki.redirects[fullpath]
redirect to("#{encodeURIComponent(redirect_path)}?redirected_from=#{encodeURIComponent(fullpath)}") redirect to("#{encodeURIComponent(redirect_path)}?redirected_from=#{encodeURIComponent(fullpath)}")
else else
if @allow_editing if @allow_editing