diff --git a/lib/gollum/app.rb b/lib/gollum/app.rb index 08179589..349481df 100644 --- a/lib/gollum/app.rb +++ b/lib/gollum/app.rb @@ -89,6 +89,7 @@ module Precious settings.wiki_options[:allow_editing] = settings.wiki_options.fetch(:allow_editing, true) @allow_editing = settings.wiki_options[:allow_editing] @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] forbid unless @allow_editing || request.request_method == "GET" @@ -158,15 +159,15 @@ module Precious end end - get %r{/(edit|create)/(custom|mathjax\.config)\.(js|css)} do + get %r{/(edit|create)/(\.redirects.gollum|(custom|mathjax\.config)\.(js|css))} do forbid('Changing this resource is not allowed.') end - post %r{/(delete|rename|edit|create)/(custom|mathjax\.config)\.(js|css)} do + post %r{/(delete|rename|edit|create)/(\.redirects.gollum|(custom|mathjax\.config)\.(js|css))} do forbid('Changing this resource is not allowed.') end - post %r{/revert/(custom|mathjax\.config\.)\.(js|css)/.*/.*} do + post %r{/revert/(\.redirects.gollum|(custom|mathjax\.config\.)\.(js|css)/.*/.*)} do forbid('Changing this resource is not allowed.') end @@ -274,9 +275,13 @@ module Precious return end committer.commit - + # Renaming preserves format, so add the page's format to the renamed path to retrieve the renamed page - page = wiki_page("#{rename}.#{Gollum::Page.format_to_ext(page.format)}").page + new_path = "#{rename}.#{Gollum::Page.format_to_ext(page.format)}" + # Add a redirect from the old page to the new + wiki.add_redirect(page.url_path, clean_url(new_path)) if @redirects_enabled + + page = wiki_page(new_path).page return if page.nil? redirect to("/#{page.escaped_url_path}") end @@ -496,7 +501,7 @@ module Precious @newable = true mustache :overview end - end + end # gollum namespace get %r{/(.+?)/([0-9a-f]{40})} do file_path = params[:captures][0] @@ -520,6 +525,10 @@ module Precious end end + get '/\.redirects\.gollum' do + forbid('Accessing this resource is not allowed.') + end + get '/*' do show_page_or_file(params[:splat].first) end @@ -545,6 +554,8 @@ module Precious mustache :page elsif file = wiki.file(fullpath, wiki.ref, true) show_file(file) + elsif @redirects_enabled && redirect_path = wiki.redirects[fullpath] + redirect to("#{encodeURIComponent(redirect_path)}?redirected_from=#{encodeURIComponent(fullpath)}") else if @allow_editing path = fullpath[-1] == '/' ? "#{fullpath}#{wiki.index_page}" : fullpath # Append default index page if no page name is supplied diff --git a/lib/gollum/helpers.rb b/lib/gollum/helpers.rb index d0dad08e..f94ecf8a 100644 --- a/lib/gollum/helpers.rb +++ b/lib/gollum/helpers.rb @@ -17,7 +17,7 @@ module Precious # Remove all slashes from the start of string. # Remove all double slashes - def clean_url url + def clean_url(url) return url if url.nil? url.gsub('%2F', '/').gsub(/^\/+/, '').gsub('//', '/') end diff --git a/lib/gollum/public/gollum/javascript/gollum.js.erb b/lib/gollum/public/gollum/javascript/gollum.js.erb index f26a77d8..3a99f7ec 100755 --- a/lib/gollum/public/gollum/javascript/gollum.js.erb +++ b/lib/gollum/public/gollum/javascript/gollum.js.erb @@ -102,6 +102,12 @@ function preparePage () { } } +function flashNotice(type, notice) { + // accepted types: info, success, warn, error + html = '