remove trailing white-spaces from app/models/wiki_page.rb.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@6511 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
d8cb0855dc
commit
ff8af0ea2e
@ -5,12 +5,12 @@
|
|||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
# as published by the Free Software Foundation; either version 2
|
# as published by the Free Software Foundation; either version 2
|
||||||
# of the License, or (at your option) any later version.
|
# of the License, or (at your option) any later version.
|
||||||
#
|
#
|
||||||
# This program is distributed in the hope that it will be useful,
|
# This program is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
@ -36,27 +36,27 @@ class WikiPage < ActiveRecord::Base
|
|||||||
:project_key => "#{Wiki.table_name}.project_id"
|
:project_key => "#{Wiki.table_name}.project_id"
|
||||||
|
|
||||||
attr_accessor :redirect_existing_links
|
attr_accessor :redirect_existing_links
|
||||||
|
|
||||||
validates_presence_of :title
|
validates_presence_of :title
|
||||||
validates_format_of :title, :with => /^[^,\.\/\?\;\|\s]*$/
|
validates_format_of :title, :with => /^[^,\.\/\?\;\|\s]*$/
|
||||||
validates_uniqueness_of :title, :scope => :wiki_id, :case_sensitive => false
|
validates_uniqueness_of :title, :scope => :wiki_id, :case_sensitive => false
|
||||||
validates_associated :content
|
validates_associated :content
|
||||||
|
|
||||||
# eager load information about last updates, without loading text
|
# eager load information about last updates, without loading text
|
||||||
named_scope :with_updated_on, {
|
named_scope :with_updated_on, {
|
||||||
:select => "#{WikiPage.table_name}.*, #{WikiContent.table_name}.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"
|
:joins => "LEFT JOIN #{WikiContent.table_name} ON #{WikiContent.table_name}.page_id = #{WikiPage.table_name}.id"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Wiki pages that are protected by default
|
# Wiki pages that are protected by default
|
||||||
DEFAULT_PROTECTED_PAGES = %w(sidebar)
|
DEFAULT_PROTECTED_PAGES = %w(sidebar)
|
||||||
|
|
||||||
def after_initialize
|
def after_initialize
|
||||||
if new_record? && DEFAULT_PROTECTED_PAGES.include?(title.to_s.downcase)
|
if new_record? && DEFAULT_PROTECTED_PAGES.include?(title.to_s.downcase)
|
||||||
self.protected = true
|
self.protected = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def visible?(user=User.current)
|
def visible?(user=User.current)
|
||||||
!user.nil? && user.allowed_to?(:view_wiki_pages, project)
|
!user.nil? && user.allowed_to?(:view_wiki_pages, project)
|
||||||
end
|
end
|
||||||
@ -68,7 +68,7 @@ class WikiPage < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def before_save
|
def before_save
|
||||||
self.title = Wiki.titleize(title)
|
self.title = Wiki.titleize(title)
|
||||||
# Manage redirects if the title has changed
|
# Manage redirects if the title has changed
|
||||||
if !@previous_title.blank? && (@previous_title != title) && !new_record?
|
if !@previous_title.blank? && (@previous_title != title) && !new_record?
|
||||||
# Update redirects that point to the old title
|
# Update redirects that point to the old title
|
||||||
@ -83,51 +83,51 @@ class WikiPage < ActiveRecord::Base
|
|||||||
@previous_title = nil
|
@previous_title = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def before_destroy
|
def before_destroy
|
||||||
# Remove redirects to this page
|
# Remove redirects to this page
|
||||||
wiki.redirects.find_all_by_redirects_to(title).each(&:destroy)
|
wiki.redirects.find_all_by_redirects_to(title).each(&:destroy)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pretty_title
|
def pretty_title
|
||||||
WikiPage.pretty_title(title)
|
WikiPage.pretty_title(title)
|
||||||
end
|
end
|
||||||
|
|
||||||
def content_for_version(version=nil)
|
def content_for_version(version=nil)
|
||||||
result = content.versions.find_by_version(version.to_i) if version
|
result = content.versions.find_by_version(version.to_i) if version
|
||||||
result ||= content
|
result ||= content
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
def diff(version_to=nil, version_from=nil)
|
def diff(version_to=nil, version_from=nil)
|
||||||
version_to = version_to ? version_to.to_i : self.content.version
|
version_to = version_to ? version_to.to_i : self.content.version
|
||||||
version_from = version_from ? version_from.to_i : version_to - 1
|
version_from = version_from ? version_from.to_i : version_to - 1
|
||||||
version_to, version_from = version_from, version_to unless version_from < version_to
|
version_to, version_from = version_from, version_to unless version_from < version_to
|
||||||
|
|
||||||
content_to = content.versions.find_by_version(version_to)
|
content_to = content.versions.find_by_version(version_to)
|
||||||
content_from = content.versions.find_by_version(version_from)
|
content_from = content.versions.find_by_version(version_from)
|
||||||
|
|
||||||
(content_to && content_from) ? WikiDiff.new(content_to, content_from) : nil
|
(content_to && content_from) ? WikiDiff.new(content_to, content_from) : nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def annotate(version=nil)
|
def annotate(version=nil)
|
||||||
version = version ? version.to_i : self.content.version
|
version = version ? version.to_i : self.content.version
|
||||||
c = content.versions.find_by_version(version)
|
c = content.versions.find_by_version(version)
|
||||||
c ? WikiAnnotate.new(c) : nil
|
c ? WikiAnnotate.new(c) : nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.pretty_title(str)
|
def self.pretty_title(str)
|
||||||
(str && str.is_a?(String)) ? str.tr('_', ' ') : str
|
(str && str.is_a?(String)) ? str.tr('_', ' ') : str
|
||||||
end
|
end
|
||||||
|
|
||||||
def project
|
def project
|
||||||
wiki.project
|
wiki.project
|
||||||
end
|
end
|
||||||
|
|
||||||
def text
|
def text
|
||||||
content.text if content
|
content.text if content
|
||||||
end
|
end
|
||||||
|
|
||||||
def updated_on
|
def updated_on
|
||||||
unless @updated_on
|
unless @updated_on
|
||||||
if time = read_attribute(:updated_on)
|
if time = read_attribute(:updated_on)
|
||||||
@ -139,20 +139,20 @@ class WikiPage < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
@updated_on
|
@updated_on
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns true if usr is allowed to edit the page, otherwise false
|
# Returns true if usr is allowed to edit the page, otherwise false
|
||||||
def editable_by?(usr)
|
def editable_by?(usr)
|
||||||
!protected? || usr.allowed_to?(:protect_wiki_pages, wiki.project)
|
!protected? || usr.allowed_to?(:protect_wiki_pages, wiki.project)
|
||||||
end
|
end
|
||||||
|
|
||||||
def attachments_deletable?(usr=User.current)
|
def attachments_deletable?(usr=User.current)
|
||||||
editable_by?(usr) && super(usr)
|
editable_by?(usr) && super(usr)
|
||||||
end
|
end
|
||||||
|
|
||||||
def parent_title
|
def parent_title
|
||||||
@parent_title || (self.parent && self.parent.pretty_title)
|
@parent_title || (self.parent && self.parent.pretty_title)
|
||||||
end
|
end
|
||||||
|
|
||||||
def parent_title=(t)
|
def parent_title=(t)
|
||||||
@parent_title = t
|
@parent_title = t
|
||||||
parent_page = t.blank? ? nil : self.wiki.find_page(t)
|
parent_page = t.blank? ? nil : self.wiki.find_page(t)
|
||||||
@ -160,7 +160,7 @@ class WikiPage < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def validate
|
def validate
|
||||||
errors.add(:parent_title, :invalid) if !@parent_title.blank? && parent.nil?
|
errors.add(:parent_title, :invalid) if !@parent_title.blank? && parent.nil?
|
||||||
errors.add(:parent_title, :circular_dependency) if parent && (parent == self || parent.ancestors.include?(self))
|
errors.add(:parent_title, :circular_dependency) if parent && (parent == self || parent.ancestors.include?(self))
|
||||||
@ -170,7 +170,7 @@ end
|
|||||||
|
|
||||||
class WikiDiff < Redmine::Helpers::Diff
|
class WikiDiff < Redmine::Helpers::Diff
|
||||||
attr_reader :content_to, :content_from
|
attr_reader :content_to, :content_from
|
||||||
|
|
||||||
def initialize(content_to, content_from)
|
def initialize(content_to, content_from)
|
||||||
@content_to = content_to
|
@content_to = content_to
|
||||||
@content_from = content_from
|
@content_from = content_from
|
||||||
@ -180,7 +180,7 @@ end
|
|||||||
|
|
||||||
class WikiAnnotate
|
class WikiAnnotate
|
||||||
attr_reader :lines, :content
|
attr_reader :lines, :content
|
||||||
|
|
||||||
def initialize(content)
|
def initialize(content)
|
||||||
@content = content
|
@content = content
|
||||||
current = content
|
current = content
|
||||||
@ -212,7 +212,7 @@ class WikiAnnotate
|
|||||||
break unless @lines.detect { |line| line[0].nil? }
|
break unless @lines.detect { |line| line[0].nil? }
|
||||||
current = current.previous
|
current = current.previous
|
||||||
end
|
end
|
||||||
@lines.each { |line|
|
@lines.each { |line|
|
||||||
line[0] ||= current.version
|
line[0] ||= current.version
|
||||||
# if the last known version is > 1 (eg. history was cleared), we don't know the author
|
# 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
|
line[1] ||= current.author if current.version == 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user