@@ -1,65 +1,65 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require 'zlib' |
|
19 | 19 | |
|
20 | 20 | class WikiContent < ActiveRecord::Base |
|
21 | 21 | set_locking_column :version |
|
22 | 22 | belongs_to :page, :class_name => 'WikiPage', :foreign_key => 'page_id' |
|
23 | 23 | belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' |
|
24 | 24 | validates_presence_of :text |
|
25 | 25 | |
|
26 | 26 | acts_as_versioned |
|
27 | 27 | class Version |
|
28 | belongs_to :page, :class_name => 'WikiPage', :foreign_key => 'page_id' | |
|
29 | belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' | |
|
28 | belongs_to :page, :class_name => '::WikiPage', :foreign_key => 'page_id' | |
|
29 | belongs_to :author, :class_name => '::User', :foreign_key => 'author_id' | |
|
30 | 30 | attr_protected :data |
|
31 | 31 | |
|
32 | 32 | acts_as_event :title => Proc.new {|o| "#{l(:label_wiki_edit)}: #{o.page.title} (##{o.version})"}, |
|
33 | 33 | :description => :comments, |
|
34 | 34 | :datetime => :updated_on, |
|
35 | 35 | :url => Proc.new {|o| {:controller => 'wiki', :id => o.page.wiki.project_id, :page => o.page.title, :version => o.version}} |
|
36 | 36 | |
|
37 | 37 | def text=(plain) |
|
38 | 38 | case Setting.wiki_compression |
|
39 | 39 | when 'gzip' |
|
40 | 40 | begin |
|
41 | 41 | self.data = Zlib::Deflate.deflate(plain, Zlib::BEST_COMPRESSION) |
|
42 | 42 | self.compression = 'gzip' |
|
43 | 43 | rescue |
|
44 | 44 | self.data = plain |
|
45 | 45 | self.compression = '' |
|
46 | 46 | end |
|
47 | 47 | else |
|
48 | 48 | self.data = plain |
|
49 | 49 | self.compression = '' |
|
50 | 50 | end |
|
51 | 51 | plain |
|
52 | 52 | end |
|
53 | 53 | |
|
54 | 54 | def text |
|
55 | 55 | @text ||= case compression |
|
56 | 56 | when 'gzip' |
|
57 | 57 | Zlib::Inflate.inflate(data) |
|
58 | 58 | else |
|
59 | 59 | # uncompressed data |
|
60 | 60 | data |
|
61 | 61 | end |
|
62 | 62 | end |
|
63 | 63 | end |
|
64 | 64 | |
|
65 | 65 | end |
General Comments 0
You need to be logged in to leave comments.
Login now