comparison app/models/wiki_page.rb @ 441:cbce1fd3b1b7 redmine-1.2

Update to Redmine 1.2-stable branch (Redmine SVN rev 6000)
author Chris Cannam
date Mon, 06 Jun 2011 14:24:13 +0100
parents 051f544170fe
children 0c939c159af4
comparison
equal deleted inserted replaced
245:051f544170fe 441:cbce1fd3b1b7
30 :datetime => :created_on, 30 :datetime => :created_on,
31 :url => Proc.new {|o| {:controller => 'wiki', :action => 'show', :project_id => o.wiki.project, :id => o.title}} 31 :url => Proc.new {|o| {:controller => 'wiki', :action => 'show', :project_id => o.wiki.project, :id => o.title}}
32 32
33 acts_as_searchable :columns => ['title', 'text'], 33 acts_as_searchable :columns => ['title', 'text'],
34 :include => [{:wiki => :project}, :content], 34 :include => [{:wiki => :project}, :content],
35 :permission => :view_wiki_pages,
35 :project_key => "#{Wiki.table_name}.project_id" 36 :project_key => "#{Wiki.table_name}.project_id"
36 37
37 attr_accessor :redirect_existing_links 38 attr_accessor :redirect_existing_links
38 39
39 validates_presence_of :title 40 validates_presence_of :title
40 validates_format_of :title, :with => /^[^,\.\/\?\;\|\s]*$/ 41 validates_format_of :title, :with => /^[^,\.\/\?\;\|\s]*$/
41 validates_uniqueness_of :title, :scope => :wiki_id, :case_sensitive => false 42 validates_uniqueness_of :title, :scope => :wiki_id, :case_sensitive => false
42 validates_associated :content 43 validates_associated :content
44
45 # eager load information about last updates, without loading text
46 named_scope :with_updated_on, {
47 :select => "#{WikiPage.table_name}.*, #{WikiContent.table_name}.updated_on",
48 :joins => "LEFT JOIN #{WikiContent.table_name} ON #{WikiContent.table_name}.page_id = #{WikiPage.table_name}.id"
49 }
43 50
44 # Wiki pages that are protected by default 51 # Wiki pages that are protected by default
45 DEFAULT_PROTECTED_PAGES = %w(sidebar) 52 DEFAULT_PROTECTED_PAGES = %w(sidebar)
46 53
47 def after_initialize 54 def after_initialize
117 wiki.project 124 wiki.project
118 end 125 end
119 126
120 def text 127 def text
121 content.text if content 128 content.text if content
129 end
130
131 def updated_on
132 unless @updated_on
133 if time = read_attribute(:updated_on)
134 # content updated_on was eager loaded with the page
135 @updated_on = Time.parse(time) rescue nil
136 else
137 @updated_on = content && content.updated_on
138 end
139 end
140 @updated_on
122 end 141 end
123 142
124 # Returns true if usr is allowed to edit the page, otherwise false 143 # Returns true if usr is allowed to edit the page, otherwise false
125 def editable_by?(usr) 144 def editable_by?(usr)
126 !protected? || usr.allowed_to?(:protect_wiki_pages, wiki.project) 145 !protected? || usr.allowed_to?(:protect_wiki_pages, wiki.project)