##// END OF EJS Templates
Fixed: wiki pages with cyrillic characters not found with postgresql (#7245)....
Jean-Philippe Lang -
r4560:f1a5dca2ba84
parent child
Show More
@@ -1,85 +1,85
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2009 Jean-Philippe Lang
2 # Copyright (C) 2006-2009 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class Wiki < ActiveRecord::Base
18 class Wiki < ActiveRecord::Base
19 belongs_to :project
19 belongs_to :project
20 has_many :pages, :class_name => 'WikiPage', :dependent => :destroy, :order => 'title'
20 has_many :pages, :class_name => 'WikiPage', :dependent => :destroy, :order => 'title'
21 has_many :redirects, :class_name => 'WikiRedirect', :dependent => :delete_all
21 has_many :redirects, :class_name => 'WikiRedirect', :dependent => :delete_all
22
22
23 acts_as_watchable
23 acts_as_watchable
24
24
25 validates_presence_of :start_page
25 validates_presence_of :start_page
26 validates_format_of :start_page, :with => /^[^,\.\/\?\;\|\:]*$/
26 validates_format_of :start_page, :with => /^[^,\.\/\?\;\|\:]*$/
27
27
28 def visible?(user=User.current)
28 def visible?(user=User.current)
29 !user.nil? && user.allowed_to?(:view_wiki_pages, project)
29 !user.nil? && user.allowed_to?(:view_wiki_pages, project)
30 end
30 end
31
31
32 # Returns the wiki page that acts as the sidebar content
32 # Returns the wiki page that acts as the sidebar content
33 # or nil if no such page exists
33 # or nil if no such page exists
34 def sidebar
34 def sidebar
35 @sidebar ||= find_page('Sidebar', :with_redirect => false)
35 @sidebar ||= find_page('Sidebar', :with_redirect => false)
36 end
36 end
37
37
38 # find the page with the given title
38 # find the page with the given title
39 # if page doesn't exist, return a new page
39 # if page doesn't exist, return a new page
40 def find_or_new_page(title)
40 def find_or_new_page(title)
41 title = start_page if title.blank?
41 title = start_page if title.blank?
42 find_page(title) || WikiPage.new(:wiki => self, :title => Wiki.titleize(title))
42 find_page(title) || WikiPage.new(:wiki => self, :title => Wiki.titleize(title))
43 end
43 end
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 title = start_page if title.blank?
47 title = start_page if title.blank?
48 title = Wiki.titleize(title).downcase
48 title = Wiki.titleize(title)
49 page = pages.first(:conditions => ["LOWER(title) LIKE ?", title])
49 page = pages.first(:conditions => ["LOWER(title) LIKE LOWER(?)", title])
50 if !page && !(options[:with_redirect] == false)
50 if !page && !(options[:with_redirect] == false)
51 # search for a redirect
51 # search for a redirect
52 redirect = redirects.first(:conditions => ["LOWER(title) LIKE ?", title])
52 redirect = redirects.first(:conditions => ["LOWER(title) LIKE LOWER(?)", title])
53 page = find_page(redirect.redirects_to, :with_redirect => false) if redirect
53 page = find_page(redirect.redirects_to, :with_redirect => false) if redirect
54 end
54 end
55 page
55 page
56 end
56 end
57
57
58 # Finds a page by title
58 # Finds a page by title
59 # The given string can be of one of the forms: "title" or "project:title"
59 # The given string can be of one of the forms: "title" or "project:title"
60 # Examples:
60 # Examples:
61 # Wiki.find_page("bar", project => foo)
61 # Wiki.find_page("bar", project => foo)
62 # Wiki.find_page("foo:bar")
62 # Wiki.find_page("foo:bar")
63 def self.find_page(title, options = {})
63 def self.find_page(title, options = {})
64 project = options[:project]
64 project = options[:project]
65 if title.to_s =~ %r{^([^\:]+)\:(.*)$}
65 if title.to_s =~ %r{^([^\:]+)\:(.*)$}
66 project_identifier, title = $1, $2
66 project_identifier, title = $1, $2
67 project = Project.find_by_identifier(project_identifier) || Project.find_by_name(project_identifier)
67 project = Project.find_by_identifier(project_identifier) || Project.find_by_name(project_identifier)
68 end
68 end
69 if project && project.wiki
69 if project && project.wiki
70 page = project.wiki.find_page(title)
70 page = project.wiki.find_page(title)
71 if page && page.content
71 if page && page.content
72 page
72 page
73 end
73 end
74 end
74 end
75 end
75 end
76
76
77 # turn a string into a valid page title
77 # turn a string into a valid page title
78 def self.titleize(title)
78 def self.titleize(title)
79 # replace spaces with _ and remove unwanted caracters
79 # replace spaces with _ and remove unwanted caracters
80 title = title.gsub(/\s+/, '_').delete(',./?;|:') if title
80 title = title.gsub(/\s+/, '_').delete(',./?;|:') if title
81 # upcase the first letter
81 # upcase the first letter
82 title = (title.slice(0..0).upcase + (title.slice(1..-1) || '')) if title
82 title = (title.slice(0..0).upcase + (title.slice(1..-1) || '')) if title
83 title
83 title
84 end
84 end
85 end
85 end
@@ -1,65 +1,71
1 ---
1 ---
2 wiki_pages_001:
2 wiki_pages_001:
3 created_on: 2007-03-07 00:08:07 +01:00
3 created_on: 2007-03-07 00:08:07 +01:00
4 title: CookBook_documentation
4 title: CookBook_documentation
5 id: 1
5 id: 1
6 wiki_id: 1
6 wiki_id: 1
7 protected: true
7 protected: true
8 parent_id:
8 parent_id:
9 wiki_pages_002:
9 wiki_pages_002:
10 created_on: 2007-03-08 00:18:07 +01:00
10 created_on: 2007-03-08 00:18:07 +01:00
11 title: Another_page
11 title: Another_page
12 id: 2
12 id: 2
13 wiki_id: 1
13 wiki_id: 1
14 protected: false
14 protected: false
15 parent_id:
15 parent_id:
16 wiki_pages_003:
16 wiki_pages_003:
17 created_on: 2007-03-08 00:18:07 +01:00
17 created_on: 2007-03-08 00:18:07 +01:00
18 title: Start_page
18 title: Start_page
19 id: 3
19 id: 3
20 wiki_id: 2
20 wiki_id: 2
21 protected: false
21 protected: false
22 parent_id:
22 parent_id:
23 wiki_pages_004:
23 wiki_pages_004:
24 created_on: 2007-03-08 00:18:07 +01:00
24 created_on: 2007-03-08 00:18:07 +01:00
25 title: Page_with_an_inline_image
25 title: Page_with_an_inline_image
26 id: 4
26 id: 4
27 wiki_id: 1
27 wiki_id: 1
28 protected: false
28 protected: false
29 parent_id: 1
29 parent_id: 1
30 wiki_pages_005:
30 wiki_pages_005:
31 created_on: 2007-03-08 00:18:07 +01:00
31 created_on: 2007-03-08 00:18:07 +01:00
32 title: Child_1
32 title: Child_1
33 id: 5
33 id: 5
34 wiki_id: 1
34 wiki_id: 1
35 protected: false
35 protected: false
36 parent_id: 2
36 parent_id: 2
37 wiki_pages_006:
37 wiki_pages_006:
38 created_on: 2007-03-08 00:18:07 +01:00
38 created_on: 2007-03-08 00:18:07 +01:00
39 title: Child_2
39 title: Child_2
40 id: 6
40 id: 6
41 wiki_id: 1
41 wiki_id: 1
42 protected: false
42 protected: false
43 parent_id: 2
43 parent_id: 2
44 wiki_pages_007:
44 wiki_pages_007:
45 created_on: 2007-03-08 00:18:07 +01:00
45 created_on: 2007-03-08 00:18:07 +01:00
46 title: Child_page_1
46 title: Child_page_1
47 id: 7
47 id: 7
48 wiki_id: 2
48 wiki_id: 2
49 protected: false
49 protected: false
50 parent_id: 8
50 parent_id: 8
51 wiki_pages_008:
51 wiki_pages_008:
52 created_on: 2007-03-08 00:18:07 +01:00
52 created_on: 2007-03-08 00:18:07 +01:00
53 title: Parent_page
53 title: Parent_page
54 id: 8
54 id: 8
55 wiki_id: 2
55 wiki_id: 2
56 protected: false
56 protected: false
57 parent_id:
57 parent_id:
58 wiki_pages_009:
58 wiki_pages_009:
59 created_on: 2007-03-08 00:18:07 +01:00
59 created_on: 2007-03-08 00:18:07 +01:00
60 title: Child_page_2
60 title: Child_page_2
61 id: 9
61 id: 9
62 wiki_id: 2
62 wiki_id: 2
63 protected: false
63 protected: false
64 parent_id: 8
64 parent_id: 8
65 No newline at end of file
65 wiki_pages_010:
66 created_on: 2007-03-08 00:18:07 +01:00
67 title: Этика_менеджмента
68 id: 10
69 wiki_id: 1
70 protected: false
71 parent_id:
@@ -1,74 +1,77
1 # encoding: utf-8
1 # encoding: utf-8
2 #
2 #
3 # redMine - project management software
3 # redMine - project management software
4 # Copyright (C) 2006-2007 Jean-Philippe Lang
4 # Copyright (C) 2006-2007 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
8 # as published by the Free Software Foundation; either version 2
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
9 # of the License, or (at your option) any later version.
10 #
10 #
11 # This program is distributed in the hope that it will be useful,
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
14 # GNU General Public License for more details.
15 #
15 #
16 # You should have received a copy of the GNU General Public License
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
19
20 require File.expand_path('../../test_helper', __FILE__)
20 require File.expand_path('../../test_helper', __FILE__)
21
21
22 class WikiTest < ActiveSupport::TestCase
22 class WikiTest < ActiveSupport::TestCase
23 fixtures :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions
23 fixtures :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions
24
24
25 def test_create
25 def test_create
26 wiki = Wiki.new(:project => Project.find(2))
26 wiki = Wiki.new(:project => Project.find(2))
27 assert !wiki.save
27 assert !wiki.save
28 assert_equal 1, wiki.errors.count
28 assert_equal 1, wiki.errors.count
29
29
30 wiki.start_page = "Start page"
30 wiki.start_page = "Start page"
31 assert wiki.save
31 assert wiki.save
32 end
32 end
33
33
34 def test_update
34 def test_update
35 @wiki = Wiki.find(1)
35 @wiki = Wiki.find(1)
36 @wiki.start_page = "Another start page"
36 @wiki.start_page = "Another start page"
37 assert @wiki.save
37 assert @wiki.save
38 @wiki.reload
38 @wiki.reload
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
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
50 page = WikiPage.find(10)
51 assert_equal page, wiki.find_page('Этика_менеджмента')
49 end
52 end
50
53
51 def test_titleize
54 def test_titleize
52 assert_equal 'Page_title_with_CAPITALES', Wiki.titleize('page title with CAPITALES')
55 assert_equal 'Page_title_with_CAPITALES', Wiki.titleize('page title with CAPITALES')
53 assert_equal 'テスト', Wiki.titleize('テスト')
56 assert_equal 'テスト', Wiki.titleize('テスト')
54 end
57 end
55
58
56 context "#sidebar" do
59 context "#sidebar" do
57 setup do
60 setup do
58 @wiki = Wiki.find(1)
61 @wiki = Wiki.find(1)
59 end
62 end
60
63
61 should "return nil if undefined" do
64 should "return nil if undefined" do
62 assert_nil @wiki.sidebar
65 assert_nil @wiki.sidebar
63 end
66 end
64
67
65 should "return a WikiPage if defined" do
68 should "return a WikiPage if defined" do
66 page = @wiki.pages.new(:title => 'Sidebar')
69 page = @wiki.pages.new(:title => 'Sidebar')
67 page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar')
70 page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar')
68 page.save!
71 page.save!
69
72
70 assert_kind_of WikiPage, @wiki.sidebar
73 assert_kind_of WikiPage, @wiki.sidebar
71 assert_equal 'Sidebar', @wiki.sidebar.title
74 assert_equal 'Sidebar', @wiki.sidebar.title
72 end
75 end
73 end
76 end
74 end
77 end
General Comments 0
You need to be logged in to leave comments. Login now