@@ -1,65 +1,65 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2007 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 |
|
25 | |||
26 | acts_as_versioned |
|
26 | acts_as_versioned | |
27 | class Version |
|
27 | class Version | |
28 | belongs_to :page, :class_name => 'WikiPage', :foreign_key => 'page_id' |
|
28 | belongs_to :page, :class_name => '::WikiPage', :foreign_key => 'page_id' | |
29 | belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' |
|
29 | belongs_to :author, :class_name => '::User', :foreign_key => 'author_id' | |
30 | attr_protected :data |
|
30 | attr_protected :data | |
31 |
|
31 | |||
32 | acts_as_event :title => Proc.new {|o| "#{l(:label_wiki_edit)}: #{o.page.title} (##{o.version})"}, |
|
32 | acts_as_event :title => Proc.new {|o| "#{l(:label_wiki_edit)}: #{o.page.title} (##{o.version})"}, | |
33 | :description => :comments, |
|
33 | :description => :comments, | |
34 | :datetime => :updated_on, |
|
34 | :datetime => :updated_on, | |
35 | :url => Proc.new {|o| {:controller => 'wiki', :id => o.page.wiki.project_id, :page => o.page.title, :version => o.version}} |
|
35 | :url => Proc.new {|o| {:controller => 'wiki', :id => o.page.wiki.project_id, :page => o.page.title, :version => o.version}} | |
36 |
|
36 | |||
37 | def text=(plain) |
|
37 | def text=(plain) | |
38 | case Setting.wiki_compression |
|
38 | case Setting.wiki_compression | |
39 | when 'gzip' |
|
39 | when 'gzip' | |
40 | begin |
|
40 | begin | |
41 | self.data = Zlib::Deflate.deflate(plain, Zlib::BEST_COMPRESSION) |
|
41 | self.data = Zlib::Deflate.deflate(plain, Zlib::BEST_COMPRESSION) | |
42 | self.compression = 'gzip' |
|
42 | self.compression = 'gzip' | |
43 | rescue |
|
43 | rescue | |
44 | self.data = plain |
|
44 | self.data = plain | |
45 | self.compression = '' |
|
45 | self.compression = '' | |
46 | end |
|
46 | end | |
47 | else |
|
47 | else | |
48 | self.data = plain |
|
48 | self.data = plain | |
49 | self.compression = '' |
|
49 | self.compression = '' | |
50 | end |
|
50 | end | |
51 | plain |
|
51 | plain | |
52 | end |
|
52 | end | |
53 |
|
53 | |||
54 | def text |
|
54 | def text | |
55 | @text ||= case compression |
|
55 | @text ||= case compression | |
56 | when 'gzip' |
|
56 | when 'gzip' | |
57 | Zlib::Inflate.inflate(data) |
|
57 | Zlib::Inflate.inflate(data) | |
58 | else |
|
58 | else | |
59 | # uncompressed data |
|
59 | # uncompressed data | |
60 | data |
|
60 | data | |
61 | end |
|
61 | end | |
62 | end |
|
62 | end | |
63 | end |
|
63 | end | |
64 |
|
64 | |||
65 | end |
|
65 | end |
General Comments 0
You need to be logged in to leave comments.
Login now