# 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
# 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:
:alt => 'This is a logo' }
end
+ def test_show_redirected_page
+ WikiRedirect.create!(:wiki_id => 1, :title => 'Old_title', :redirects_to => 'Another_page')
+
+ get :show, :project_id => 'ecookbook', :id => 'Old_title'
+ assert_redirected_to '/projects/ecookbook/wiki/Another_page'
+ end
+
def test_show_with_sidebar
page = Project.find(1).wiki.pages.new(:title => 'Sidebar')
page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar')
# encoding: utf-8
#
-# redMine - project management software
-# Copyright (C) 2006-2007 Jean-Philippe Lang
+# Redmine - project management software
+# Copyright (C) 2006-2011 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
assert_equal "Another start page", @wiki.start_page
end
- def test_find_page
+ def test_find_page_should_not_be_case_sensitive
wiki = Wiki.find(1)
page = WikiPage.find(2)
assert_equal page, wiki.find_page('Another_page')
assert_equal page, wiki.find_page('Another page')
assert_equal page, wiki.find_page('ANOTHER page')
-
+ end
+
+ def test_find_page_with_cyrillic_characters
+ wiki = Wiki.find(1)
page = WikiPage.find(10)
assert_equal page, wiki.find_page('Этика_менеджмента')
-
+ end
+
+ def test_find_page_with_backslashes
+ wiki = Wiki.find(1)
page = WikiPage.generate!(:wiki => wiki, :title => '2009\\02\\09')
assert_equal page, wiki.find_page('2009\\02\\09')
end
+ def test_find_page_without_redirect
+ wiki = Wiki.find(1)
+ page = wiki.find_page('Another_page')
+ assert_not_nil page
+ assert_equal 'Another_page', page.title
+ assert_equal false, wiki.page_found_with_redirect?
+ end
+
+ def test_find_page_with_redirect
+ wiki = Wiki.find(1)
+ WikiRedirect.create!(:wiki => wiki, :title => 'Old_title', :redirects_to => 'Another_page')
+ page = wiki.find_page('Old_title')
+ assert_not_nil page
+ assert_equal 'Another_page', page.title
+ assert_equal true, wiki.page_found_with_redirect?
+ end
+
def test_titleize
assert_equal 'Page_title_with_CAPITALES', Wiki.titleize('page title with CAPITALES')
assert_equal 'テスト', Wiki.titleize('テスト')