@@ -1,110 +1,110 | |||||
1 |
# |
|
1 | # RedMine - project management software | |
2 |
# Copyright (C) 2006-20 |
|
2 | # Copyright (C) 2006-2011 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 | class Version |
|
48 | class Version | |
49 | belongs_to :page, :class_name => '::WikiPage', :foreign_key => 'page_id' |
|
49 | belongs_to :page, :class_name => '::WikiPage', :foreign_key => 'page_id' | |
50 | belongs_to :author, :class_name => '::User', :foreign_key => 'author_id' |
|
50 | belongs_to :author, :class_name => '::User', :foreign_key => 'author_id' | |
51 | attr_protected :data |
|
51 | attr_protected :data | |
52 |
|
52 | |||
53 | acts_as_event :title => Proc.new {|o| "#{l(:label_wiki_edit)}: #{o.page.title} (##{o.version})"}, |
|
53 | acts_as_event :title => Proc.new {|o| "#{l(:label_wiki_edit)}: #{o.page.title} (##{o.version})"}, | |
54 | :description => :comments, |
|
54 | :description => :comments, | |
55 | :datetime => :updated_on, |
|
55 | :datetime => :updated_on, | |
56 | :type => 'wiki-page', |
|
56 | :type => 'wiki-page', | |
57 | :url => Proc.new {|o| {:controller => 'wiki', :action => 'show', :project_id => o.page.wiki.project, :id => o.page.title, :version => o.version}} |
|
57 | :url => Proc.new {|o| {:controller => 'wiki', :action => 'show', :project_id => o.page.wiki.project, :id => o.page.title, :version => o.version}} | |
58 |
|
58 | |||
59 | acts_as_activity_provider :type => 'wiki_edits', |
|
59 | acts_as_activity_provider :type => 'wiki_edits', | |
60 | :timestamp => "#{WikiContent.versioned_table_name}.updated_on", |
|
60 | :timestamp => "#{WikiContent.versioned_table_name}.updated_on", | |
61 | :author_key => "#{WikiContent.versioned_table_name}.author_id", |
|
61 | :author_key => "#{WikiContent.versioned_table_name}.author_id", | |
62 | :permission => :view_wiki_edits, |
|
62 | :permission => :view_wiki_edits, | |
63 | :find_options => {:select => "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " + |
|
63 | :find_options => {:select => "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " + | |
64 | "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " + |
|
64 | "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " + | |
65 | "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " + |
|
65 | "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " + | |
66 | "#{WikiContent.versioned_table_name}.id", |
|
66 | "#{WikiContent.versioned_table_name}.id", | |
67 | :joins => "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " + |
|
67 | :joins => "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " + | |
68 | "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " + |
|
68 | "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " + | |
69 | "LEFT JOIN #{Project.table_name} ON #{Project.table_name}.id = #{Wiki.table_name}.project_id"} |
|
69 | "LEFT JOIN #{Project.table_name} ON #{Project.table_name}.id = #{Wiki.table_name}.project_id"} | |
70 |
|
70 | |||
71 | def text=(plain) |
|
71 | def text=(plain) | |
72 | case Setting.wiki_compression |
|
72 | case Setting.wiki_compression | |
73 | when 'gzip' |
|
73 | when 'gzip' | |
74 | begin |
|
74 | begin | |
75 | self.data = Zlib::Deflate.deflate(plain, Zlib::BEST_COMPRESSION) |
|
75 | self.data = Zlib::Deflate.deflate(plain, Zlib::BEST_COMPRESSION) | |
76 | self.compression = 'gzip' |
|
76 | self.compression = 'gzip' | |
77 | rescue |
|
77 | rescue | |
78 | self.data = plain |
|
78 | self.data = plain | |
79 | self.compression = '' |
|
79 | self.compression = '' | |
80 | end |
|
80 | end | |
81 | else |
|
81 | else | |
82 | self.data = plain |
|
82 | self.data = plain | |
83 | self.compression = '' |
|
83 | self.compression = '' | |
84 | end |
|
84 | end | |
85 | plain |
|
85 | plain | |
86 | end |
|
86 | end | |
87 |
|
87 | |||
88 | def text |
|
88 | def text | |
89 | @text ||= case compression |
|
89 | @text ||= case compression | |
90 | when 'gzip' |
|
90 | when 'gzip' | |
91 | Zlib::Inflate.inflate(data) |
|
91 | Zlib::Inflate.inflate(data) | |
92 | else |
|
92 | else | |
93 | # uncompressed data |
|
93 | # uncompressed data | |
94 | data |
|
94 | data | |
95 |
end |
|
95 | end | |
96 | end |
|
96 | end | |
97 |
|
97 | |||
98 | def project |
|
98 | def project | |
99 | page.project |
|
99 | page.project | |
100 | end |
|
100 | end | |
101 |
|
101 | |||
102 | # Returns the previous version or nil |
|
102 | # Returns the previous version or nil | |
103 | def previous |
|
103 | def previous | |
104 |
@previous ||= WikiContent::Version.find(:first, |
|
104 | @previous ||= WikiContent::Version.find(:first, | |
105 | :order => 'version DESC', |
|
105 | :order => 'version DESC', | |
106 | :include => :author, |
|
106 | :include => :author, | |
107 | :conditions => ["wiki_content_id = ? AND version < ?", wiki_content_id, version]) |
|
107 | :conditions => ["wiki_content_id = ? AND version < ?", wiki_content_id, version]) | |
108 | end |
|
108 | end | |
109 | end |
|
109 | end | |
110 | end |
|
110 | end |
General Comments 0
You need to be logged in to leave comments.
Login now