diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2011-04-11 19:21:57 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2011-04-11 19:21:57 +0000 |
commit | 3cc7353093a7cb8160fd34cb16aff099c5517e32 (patch) | |
tree | 5f16348e9417af9402a29ccdf8954d76fc2a8413 /app | |
parent | 6db0e8dcef0bf1e4ece02641b51b9df38dae31dc (diff) | |
download | redmine-3cc7353093a7cb8160fd34cb16aff099c5517e32.tar.gz redmine-3cc7353093a7cb8160fd34cb16aff099c5517e32.zip |
Do a redirect when accessing a renamed wiki page.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5423 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/wiki_controller.rb | 11 | ||||
-rw-r--r-- | app/models/wiki.rb | 11 |
2 files changed, 20 insertions, 2 deletions
diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 84fb16d2e..f11b21264 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -249,12 +249,21 @@ private # Finds the requested page or a new page if it doesn't exist def find_existing_or_new_page @page = @wiki.find_or_new_page(params[:id]) + if @wiki.page_found_with_redirect? + redirect_to params.update(:id => @page.title) + end end # Finds the requested page and returns a 404 error if it doesn't exist def find_existing_page @page = @wiki.find_page(params[:id]) - render_404 if @page.nil? + if @page.nil? + render_404 + return + end + if @wiki.page_found_with_redirect? + redirect_to params.update(:id => @page.title) + end end # Returns true if the current user is allowed to edit the page, otherwise false diff --git a/app/models/wiki.rb b/app/models/wiki.rb index eb521c99a..8c5ee0689 100644 --- a/app/models/wiki.rb +++ b/app/models/wiki.rb @@ -44,17 +44,26 @@ class Wiki < ActiveRecord::Base # find the page with the given title def find_page(title, options = {}) + @page_found_with_redirect = false title = start_page if title.blank? title = Wiki.titleize(title) page = pages.first(:conditions => ["LOWER(title) = LOWER(?)", title]) if !page && !(options[:with_redirect] == false) # search for a redirect redirect = redirects.first(:conditions => ["LOWER(title) = LOWER(?)", title]) - page = find_page(redirect.redirects_to, :with_redirect => false) if redirect + if redirect + page = find_page(redirect.redirects_to, :with_redirect => false) + @page_found_with_redirect = true + end end page end + # Returns true if the last page was found with a redirect + def page_found_with_redirect? + @page_found_with_redirect + end + # Finds a page by title # The given string can be of one of the forms: "title" or "project:title" # Examples: |