##// END OF EJS Templates
Do a redirect when accessing a renamed wiki page....
Jean-Philippe Lang -
r5303:3cc7353093a7
parent child
Show More
@@ -249,12 +249,21 private
249 249 # Finds the requested page or a new page if it doesn't exist
250 250 def find_existing_or_new_page
251 251 @page = @wiki.find_or_new_page(params[:id])
252 if @wiki.page_found_with_redirect?
253 redirect_to params.update(:id => @page.title)
254 end
252 255 end
253 256
254 257 # Finds the requested page and returns a 404 error if it doesn't exist
255 258 def find_existing_page
256 259 @page = @wiki.find_page(params[:id])
257 render_404 if @page.nil?
260 if @page.nil?
261 render_404
262 return
263 end
264 if @wiki.page_found_with_redirect?
265 redirect_to params.update(:id => @page.title)
266 end
258 267 end
259 268
260 269 # Returns true if the current user is allowed to edit the page, otherwise false
@@ -44,17 +44,26 class Wiki < ActiveRecord::Base
44 44
45 45 # find the page with the given title
46 46 def find_page(title, options = {})
47 @page_found_with_redirect = false
47 48 title = start_page if title.blank?
48 49 title = Wiki.titleize(title)
49 50 page = pages.first(:conditions => ["LOWER(title) = LOWER(?)", title])
50 51 if !page && !(options[:with_redirect] == false)
51 52 # search for a redirect
52 53 redirect = redirects.first(:conditions => ["LOWER(title) = LOWER(?)", title])
53 page = find_page(redirect.redirects_to, :with_redirect => false) if redirect
54 if redirect
55 page = find_page(redirect.redirects_to, :with_redirect => false)
56 @page_found_with_redirect = true
57 end
54 58 end
55 59 page
56 60 end
57 61
62 # Returns true if the last page was found with a redirect
63 def page_found_with_redirect?
64 @page_found_with_redirect
65 end
66
58 67 # Finds a page by title
59 68 # The given string can be of one of the forms: "title" or "project:title"
60 69 # Examples:
@@ -55,6 +55,13 class WikiControllerTest < ActionController::TestCase
55 55 :alt => 'This is a logo' }
56 56 end
57 57
58 def test_show_redirected_page
59 WikiRedirect.create!(:wiki_id => 1, :title => 'Old_title', :redirects_to => 'Another_page')
60
61 get :show, :project_id => 'ecookbook', :id => 'Old_title'
62 assert_redirected_to '/projects/ecookbook/wiki/Another_page'
63 end
64
58 65 def test_show_with_sidebar
59 66 page = Project.find(1).wiki.pages.new(:title => 'Sidebar')
60 67 page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar')
@@ -1,7 +1,7
1 1 # encoding: utf-8
2 2 #
3 # redMine - project management software
4 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 # Redmine - project management software
4 # Copyright (C) 2006-2011 Jean-Philippe Lang
5 5 #
6 6 # This program is free software; you can redistribute it and/or
7 7 # modify it under the terms of the GNU General Public License
@@ -39,21 +39,44 class WikiTest < ActiveSupport::TestCase
39 39 assert_equal "Another start page", @wiki.start_page
40 40 end
41 41
42 def test_find_page
42 def test_find_page_should_not_be_case_sensitive
43 43 wiki = Wiki.find(1)
44 44 page = WikiPage.find(2)
45 45
46 46 assert_equal page, wiki.find_page('Another_page')
47 47 assert_equal page, wiki.find_page('Another page')
48 48 assert_equal page, wiki.find_page('ANOTHER page')
49
49 end
50
51 def test_find_page_with_cyrillic_characters
52 wiki = Wiki.find(1)
50 53 page = WikiPage.find(10)
51 54 assert_equal page, wiki.find_page('Этика_менеджмента')
52
55 end
56
57 def test_find_page_with_backslashes
58 wiki = Wiki.find(1)
53 59 page = WikiPage.generate!(:wiki => wiki, :title => '2009\\02\\09')
54 60 assert_equal page, wiki.find_page('2009\\02\\09')
55 61 end
56 62
63 def test_find_page_without_redirect
64 wiki = Wiki.find(1)
65 page = wiki.find_page('Another_page')
66 assert_not_nil page
67 assert_equal 'Another_page', page.title
68 assert_equal false, wiki.page_found_with_redirect?
69 end
70
71 def test_find_page_with_redirect
72 wiki = Wiki.find(1)
73 WikiRedirect.create!(:wiki => wiki, :title => 'Old_title', :redirects_to => 'Another_page')
74 page = wiki.find_page('Old_title')
75 assert_not_nil page
76 assert_equal 'Another_page', page.title
77 assert_equal true, wiki.page_found_with_redirect?
78 end
79
57 80 def test_titleize
58 81 assert_equal 'Page_title_with_CAPITALES', Wiki.titleize('page title with CAPITALES')
59 82 assert_equal 'テスト', Wiki.titleize('テスト')
General Comments 0
You need to be logged in to leave comments. Login now