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
This commit is contained in:
Jean-Philippe Lang
2011-04-11 19:21:57 +00:00
parent 6db0e8dcef
commit 3cc7353093
4 changed files with 55 additions and 7 deletions
+10 -1
View File
@@ -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: