Mercurial > hg > soundsoftware-site
diff app/models/wiki_page.rb @ 514:7eba09d624db live
Merge
author | Chris Cannam |
---|---|
date | Thu, 14 Jul 2011 10:50:53 +0100 |
parents | 0c939c159af4 |
children | cbb26bc654de |
line wrap: on
line diff
--- a/app/models/wiki_page.rb Thu Jul 14 10:46:20 2011 +0100 +++ b/app/models/wiki_page.rb Thu Jul 14 10:50:53 2011 +0100 @@ -1,5 +1,5 @@ # Redmine - project management software -# Copyright (C) 2006-2009 Jean-Philippe Lang +# Copyright (C) 2006-2011 Jean-Philippe Lang # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -32,6 +32,7 @@ acts_as_searchable :columns => ['title', 'text'], :include => [{:wiki => :project}, :content], + :permission => :view_wiki_pages, :project_key => "#{Wiki.table_name}.project_id" attr_accessor :redirect_existing_links @@ -41,6 +42,12 @@ validates_uniqueness_of :title, :scope => :wiki_id, :case_sensitive => false validates_associated :content + # eager load information about last updates, without loading text + named_scope :with_updated_on, { + :select => "#{WikiPage.table_name}.*, #{WikiContent.table_name}.updated_on", + :joins => "LEFT JOIN #{WikiContent.table_name} ON #{WikiContent.table_name}.page_id = #{WikiPage.table_name}.id" + } + # Wiki pages that are protected by default DEFAULT_PROTECTED_PAGES = %w(sidebar) @@ -121,6 +128,18 @@ content.text if content end + def updated_on + unless @updated_on + if time = read_attribute(:updated_on) + # content updated_on was eager loaded with the page + @updated_on = Time.parse(time) rescue nil + else + @updated_on = content && content.updated_on + end + end + @updated_on + end + # Returns true if usr is allowed to edit the page, otherwise false def editable_by?(usr) !protected? || usr.allowed_to?(:protect_wiki_pages, wiki.project) @@ -149,17 +168,13 @@ end end -class WikiDiff - attr_reader :diff, :words, :content_to, :content_from +class WikiDiff < Redmine::Helpers::Diff + attr_reader :content_to, :content_from def initialize(content_to, content_from) @content_to = content_to @content_from = content_from - @words = content_to.text.split(/(\s+)/) - @words = @words.select {|word| word != ' '} - words_from = content_from.text.split(/(\s+)/) - words_from = words_from.select {|word| word != ' '} - @diff = words_from.diff @words + super(content_to.text, content_from.text) end end @@ -197,6 +212,10 @@ break unless @lines.detect { |line| line[0].nil? } current = current.previous end - @lines.each { |line| line[0] ||= current.version } + @lines.each { |line| + line[0] ||= current.version + # if the last known version is > 1 (eg. history was cleared), we don't know the author + line[1] ||= current.author if current.version == 1 + } end end