@@ -249,12 +249,21 private | |||||
249 | # Finds the requested page or a new page if it doesn't exist |
|
249 | # Finds the requested page or a new page if it doesn't exist | |
250 | def find_existing_or_new_page |
|
250 | def find_existing_or_new_page | |
251 | @page = @wiki.find_or_new_page(params[:id]) |
|
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 | end |
|
255 | end | |
253 |
|
256 | |||
254 | # Finds the requested page and returns a 404 error if it doesn't exist |
|
257 | # Finds the requested page and returns a 404 error if it doesn't exist | |
255 | def find_existing_page |
|
258 | def find_existing_page | |
256 | @page = @wiki.find_page(params[:id]) |
|
259 | @page = @wiki.find_page(params[:id]) | |
257 |
|
|
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 | end |
|
267 | end | |
259 |
|
268 | |||
260 | # Returns true if the current user is allowed to edit the page, otherwise false |
|
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 | # find the page with the given title |
|
45 | # find the page with the given title | |
46 | def find_page(title, options = {}) |
|
46 | def find_page(title, options = {}) | |
|
47 | @page_found_with_redirect = false | |||
47 | title = start_page if title.blank? |
|
48 | title = start_page if title.blank? | |
48 | title = Wiki.titleize(title) |
|
49 | title = Wiki.titleize(title) | |
49 | page = pages.first(:conditions => ["LOWER(title) = LOWER(?)", title]) |
|
50 | page = pages.first(:conditions => ["LOWER(title) = LOWER(?)", title]) | |
50 | if !page && !(options[:with_redirect] == false) |
|
51 | if !page && !(options[:with_redirect] == false) | |
51 | # search for a redirect |
|
52 | # search for a redirect | |
52 | redirect = redirects.first(:conditions => ["LOWER(title) = LOWER(?)", title]) |
|
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 | end |
|
58 | end | |
55 | page |
|
59 | page | |
56 | end |
|
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 | # Finds a page by title |
|
67 | # Finds a page by title | |
59 | # The given string can be of one of the forms: "title" or "project:title" |
|
68 | # The given string can be of one of the forms: "title" or "project:title" | |
60 | # Examples: |
|
69 | # Examples: |
@@ -55,6 +55,13 class WikiControllerTest < ActionController::TestCase | |||||
55 | :alt => 'This is a logo' } |
|
55 | :alt => 'This is a logo' } | |
56 | end |
|
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 | def test_show_with_sidebar |
|
65 | def test_show_with_sidebar | |
59 | page = Project.find(1).wiki.pages.new(:title => 'Sidebar') |
|
66 | page = Project.find(1).wiki.pages.new(:title => 'Sidebar') | |
60 | page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar') |
|
67 | page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar') |
@@ -1,7 +1,7 | |||||
1 | # encoding: utf-8 |
|
1 | # encoding: utf-8 | |
2 | # |
|
2 | # | |
3 |
# |
|
3 | # Redmine - project management software | |
4 |
# Copyright (C) 2006-20 |
|
4 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |
5 | # |
|
5 | # | |
6 | # This program is free software; you can redistribute it and/or |
|
6 | # This program is free software; you can redistribute it and/or | |
7 | # modify it under the terms of the GNU General Public License |
|
7 | # modify it under the terms of the GNU General Public License | |
@@ -39,21 +39,44 class WikiTest < ActiveSupport::TestCase | |||||
39 | assert_equal "Another start page", @wiki.start_page |
|
39 | assert_equal "Another start page", @wiki.start_page | |
40 | end |
|
40 | end | |
41 |
|
41 | |||
42 | def test_find_page |
|
42 | def test_find_page_should_not_be_case_sensitive | |
43 | wiki = Wiki.find(1) |
|
43 | wiki = Wiki.find(1) | |
44 | page = WikiPage.find(2) |
|
44 | page = WikiPage.find(2) | |
45 |
|
45 | |||
46 | assert_equal page, wiki.find_page('Another_page') |
|
46 | assert_equal page, wiki.find_page('Another_page') | |
47 | assert_equal page, wiki.find_page('Another page') |
|
47 | assert_equal page, wiki.find_page('Another page') | |
48 | assert_equal page, wiki.find_page('ANOTHER page') |
|
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 | page = WikiPage.find(10) |
|
53 | page = WikiPage.find(10) | |
51 | assert_equal page, wiki.find_page('Этика_менеджмента') |
|
54 | assert_equal page, wiki.find_page('Этика_менеджмента') | |
52 |
|
55 | end | ||
|
56 | ||||
|
57 | def test_find_page_with_backslashes | |||
|
58 | wiki = Wiki.find(1) | |||
53 | page = WikiPage.generate!(:wiki => wiki, :title => '2009\\02\\09') |
|
59 | page = WikiPage.generate!(:wiki => wiki, :title => '2009\\02\\09') | |
54 | assert_equal page, wiki.find_page('2009\\02\\09') |
|
60 | assert_equal page, wiki.find_page('2009\\02\\09') | |
55 | end |
|
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 | def test_titleize |
|
80 | def test_titleize | |
58 | assert_equal 'Page_title_with_CAPITALES', Wiki.titleize('page title with CAPITALES') |
|
81 | assert_equal 'Page_title_with_CAPITALES', Wiki.titleize('page title with CAPITALES') | |
59 | assert_equal 'テスト', Wiki.titleize('テスト') |
|
82 | assert_equal 'テスト', Wiki.titleize('テスト') |
General Comments 0
You need to be logged in to leave comments.
Login now