##// END OF EJS Templates
Added page association on versioned WikiContent...
Jean-Philippe Lang -
r562:5332c4362cdf
parent child
Show More
@@ -1,59 +1,60
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 :author, :class_name => 'User', :foreign_key => 'author_id'
29 belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
29 attr_protected :data
30 attr_protected :data
30
31
31 def text=(plain)
32 def text=(plain)
32 case Setting.wiki_compression
33 case Setting.wiki_compression
33 when 'gzip'
34 when 'gzip'
34 begin
35 begin
35 self.data = Zlib::Deflate.deflate(plain, Zlib::BEST_COMPRESSION)
36 self.data = Zlib::Deflate.deflate(plain, Zlib::BEST_COMPRESSION)
36 self.compression = 'gzip'
37 self.compression = 'gzip'
37 rescue
38 rescue
38 self.data = plain
39 self.data = plain
39 self.compression = ''
40 self.compression = ''
40 end
41 end
41 else
42 else
42 self.data = plain
43 self.data = plain
43 self.compression = ''
44 self.compression = ''
44 end
45 end
45 plain
46 plain
46 end
47 end
47
48
48 def text
49 def text
49 @text ||= case compression
50 @text ||= case compression
50 when 'gzip'
51 when 'gzip'
51 Zlib::Inflate.inflate(data)
52 Zlib::Inflate.inflate(data)
52 else
53 else
53 # uncompressed data
54 # uncompressed data
54 data
55 data
55 end
56 end
56 end
57 end
57 end
58 end
58
59
59 end
60 end
General Comments 0
You need to be logged in to leave comments. Login now