##// END OF EJS Templates
fix typo "RedMine" at app/models/wiki_content.rb...
Toshi MARUYAMA -
r9182:f0f7158d87c9
parent child
Show More
@@ -1,122 +1,122
1 # RedMine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 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 require 'zlib'
18 require 'zlib'
19
19
20 class WikiContent < ActiveRecord::Base
20 class WikiContent < ActiveRecord::Base
21 set_locking_column :version
21 set_locking_column :version
22 belongs_to :page, :class_name => 'WikiPage', :foreign_key => 'page_id'
22 belongs_to :page, :class_name => 'WikiPage', :foreign_key => 'page_id'
23 belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
23 belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
24 validates_presence_of :text
24 validates_presence_of :text
25 validates_length_of :comments, :maximum => 255, :allow_nil => true
25 validates_length_of :comments, :maximum => 255, :allow_nil => true
26
26
27 acts_as_versioned
27 acts_as_versioned
28
28
29 def visible?(user=User.current)
29 def visible?(user=User.current)
30 page.visible?(user)
30 page.visible?(user)
31 end
31 end
32
32
33 def project
33 def project
34 page.project
34 page.project
35 end
35 end
36
36
37 def attachments
37 def attachments
38 page.nil? ? [] : page.attachments
38 page.nil? ? [] : page.attachments
39 end
39 end
40
40
41 # Returns the mail adresses of users that should be notified
41 # Returns the mail adresses of users that should be notified
42 def recipients
42 def recipients
43 notified = project.notified_users
43 notified = project.notified_users
44 notified.reject! {|user| !visible?(user)}
44 notified.reject! {|user| !visible?(user)}
45 notified.collect(&:mail)
45 notified.collect(&:mail)
46 end
46 end
47
47
48 # Return true if the content is the current page content
48 # Return true if the content is the current page content
49 def current_version?
49 def current_version?
50 true
50 true
51 end
51 end
52
52
53 class Version
53 class Version
54 belongs_to :page, :class_name => '::WikiPage', :foreign_key => 'page_id'
54 belongs_to :page, :class_name => '::WikiPage', :foreign_key => 'page_id'
55 belongs_to :author, :class_name => '::User', :foreign_key => 'author_id'
55 belongs_to :author, :class_name => '::User', :foreign_key => 'author_id'
56 attr_protected :data
56 attr_protected :data
57
57
58 acts_as_event :title => Proc.new {|o| "#{l(:label_wiki_edit)}: #{o.page.title} (##{o.version})"},
58 acts_as_event :title => Proc.new {|o| "#{l(:label_wiki_edit)}: #{o.page.title} (##{o.version})"},
59 :description => :comments,
59 :description => :comments,
60 :datetime => :updated_on,
60 :datetime => :updated_on,
61 :type => 'wiki-page',
61 :type => 'wiki-page',
62 :url => Proc.new {|o| {:controller => 'wiki', :action => 'show', :project_id => o.page.wiki.project, :id => o.page.title, :version => o.version}}
62 :url => Proc.new {|o| {:controller => 'wiki', :action => 'show', :project_id => o.page.wiki.project, :id => o.page.title, :version => o.version}}
63
63
64 acts_as_activity_provider :type => 'wiki_edits',
64 acts_as_activity_provider :type => 'wiki_edits',
65 :timestamp => "#{WikiContent.versioned_table_name}.updated_on",
65 :timestamp => "#{WikiContent.versioned_table_name}.updated_on",
66 :author_key => "#{WikiContent.versioned_table_name}.author_id",
66 :author_key => "#{WikiContent.versioned_table_name}.author_id",
67 :permission => :view_wiki_edits,
67 :permission => :view_wiki_edits,
68 :find_options => {:select => "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
68 :find_options => {:select => "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
69 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
69 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
70 "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
70 "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
71 "#{WikiContent.versioned_table_name}.id",
71 "#{WikiContent.versioned_table_name}.id",
72 :joins => "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
72 :joins => "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
73 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " +
73 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " +
74 "LEFT JOIN #{Project.table_name} ON #{Project.table_name}.id = #{Wiki.table_name}.project_id"}
74 "LEFT JOIN #{Project.table_name} ON #{Project.table_name}.id = #{Wiki.table_name}.project_id"}
75
75
76 def text=(plain)
76 def text=(plain)
77 case Setting.wiki_compression
77 case Setting.wiki_compression
78 when 'gzip'
78 when 'gzip'
79 begin
79 begin
80 self.data = Zlib::Deflate.deflate(plain, Zlib::BEST_COMPRESSION)
80 self.data = Zlib::Deflate.deflate(plain, Zlib::BEST_COMPRESSION)
81 self.compression = 'gzip'
81 self.compression = 'gzip'
82 rescue
82 rescue
83 self.data = plain
83 self.data = plain
84 self.compression = ''
84 self.compression = ''
85 end
85 end
86 else
86 else
87 self.data = plain
87 self.data = plain
88 self.compression = ''
88 self.compression = ''
89 end
89 end
90 plain
90 plain
91 end
91 end
92
92
93 def text
93 def text
94 @text ||= case compression
94 @text ||= case compression
95 when 'gzip'
95 when 'gzip'
96 str = Zlib::Inflate.inflate(data)
96 str = Zlib::Inflate.inflate(data)
97 str.force_encoding("UTF-8") if str.respond_to?(:force_encoding)
97 str.force_encoding("UTF-8") if str.respond_to?(:force_encoding)
98 str
98 str
99 else
99 else
100 # uncompressed data
100 # uncompressed data
101 data
101 data
102 end
102 end
103 end
103 end
104
104
105 def project
105 def project
106 page.project
106 page.project
107 end
107 end
108
108
109 # Return true if the content is the current page content
109 # Return true if the content is the current page content
110 def current_version?
110 def current_version?
111 page.content.version == self.version
111 page.content.version == self.version
112 end
112 end
113
113
114 # Returns the previous version or nil
114 # Returns the previous version or nil
115 def previous
115 def previous
116 @previous ||= WikiContent::Version.find(:first,
116 @previous ||= WikiContent::Version.find(:first,
117 :order => 'version DESC',
117 :order => 'version DESC',
118 :include => :author,
118 :include => :author,
119 :conditions => ["wiki_content_id = ? AND version < ?", wiki_content_id, version])
119 :conditions => ["wiki_content_id = ? AND version < ?", wiki_content_id, version])
120 end
120 end
121 end
121 end
122 end
122 end
General Comments 0
You need to be logged in to leave comments. Login now