annotate .svn/pristine/7e/7e2e1bf298eac748b61a16c5e48048a8fbf6debf.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

Fix failure to interpret Javascript when autocompleting members for project
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 11 Sep 2014 10:24:38 +0100
parents e248c7af89ec
children
rev   line source
Chris@1494 1 # Redmine - project management software
Chris@1494 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1494 3 #
Chris@1494 4 # This program is free software; you can redistribute it and/or
Chris@1494 5 # modify it under the terms of the GNU General Public License
Chris@1494 6 # as published by the Free Software Foundation; either version 2
Chris@1494 7 # of the License, or (at your option) any later version.
Chris@1494 8 #
Chris@1494 9 # This program is distributed in the hope that it will be useful,
Chris@1494 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1494 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1494 12 # GNU General Public License for more details.
Chris@1494 13 #
Chris@1494 14 # You should have received a copy of the GNU General Public License
Chris@1494 15 # along with this program; if not, write to the Free Software
Chris@1494 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1494 17
Chris@1494 18 class Wiki < ActiveRecord::Base
Chris@1494 19 include Redmine::SafeAttributes
Chris@1494 20 belongs_to :project
Chris@1494 21 has_many :pages, :class_name => 'WikiPage', :dependent => :destroy, :order => 'title'
Chris@1494 22 has_many :redirects, :class_name => 'WikiRedirect', :dependent => :delete_all
Chris@1494 23
Chris@1494 24 acts_as_watchable
Chris@1494 25
Chris@1494 26 validates_presence_of :start_page
Chris@1494 27 validates_format_of :start_page, :with => /\A[^,\.\/\?\;\|\:]*\z/
Chris@1494 28
Chris@1494 29 safe_attributes 'start_page'
Chris@1494 30
Chris@1494 31 def visible?(user=User.current)
Chris@1494 32 !user.nil? && user.allowed_to?(:view_wiki_pages, project)
Chris@1494 33 end
Chris@1494 34
Chris@1494 35 # Returns the wiki page that acts as the sidebar content
Chris@1494 36 # or nil if no such page exists
Chris@1494 37 def sidebar
Chris@1494 38 @sidebar ||= find_page('Sidebar', :with_redirect => false)
Chris@1494 39 end
Chris@1494 40
Chris@1494 41 # find the page with the given title
Chris@1494 42 # if page doesn't exist, return a new page
Chris@1494 43 def find_or_new_page(title)
Chris@1494 44 title = start_page if title.blank?
Chris@1494 45 find_page(title) || WikiPage.new(:wiki => self, :title => Wiki.titleize(title))
Chris@1494 46 end
Chris@1494 47
Chris@1494 48 # find the page with the given title
Chris@1494 49 def find_page(title, options = {})
Chris@1494 50 @page_found_with_redirect = false
Chris@1494 51 title = start_page if title.blank?
Chris@1494 52 title = Wiki.titleize(title)
Chris@1494 53 page = pages.where("LOWER(title) = LOWER(?)", title).first
Chris@1494 54 if !page && !(options[:with_redirect] == false)
Chris@1494 55 # search for a redirect
Chris@1494 56 redirect = redirects.where("LOWER(title) = LOWER(?)", title).first
Chris@1494 57 if redirect
Chris@1494 58 page = find_page(redirect.redirects_to, :with_redirect => false)
Chris@1494 59 @page_found_with_redirect = true
Chris@1494 60 end
Chris@1494 61 end
Chris@1494 62 page
Chris@1494 63 end
Chris@1494 64
Chris@1494 65 # Returns true if the last page was found with a redirect
Chris@1494 66 def page_found_with_redirect?
Chris@1494 67 @page_found_with_redirect
Chris@1494 68 end
Chris@1494 69
Chris@1494 70 # Finds a page by title
Chris@1494 71 # The given string can be of one of the forms: "title" or "project:title"
Chris@1494 72 # Examples:
Chris@1494 73 # Wiki.find_page("bar", project => foo)
Chris@1494 74 # Wiki.find_page("foo:bar")
Chris@1494 75 def self.find_page(title, options = {})
Chris@1494 76 project = options[:project]
Chris@1494 77 if title.to_s =~ %r{^([^\:]+)\:(.*)$}
Chris@1494 78 project_identifier, title = $1, $2
Chris@1494 79 project = Project.find_by_identifier(project_identifier) || Project.find_by_name(project_identifier)
Chris@1494 80 end
Chris@1494 81 if project && project.wiki
Chris@1494 82 page = project.wiki.find_page(title)
Chris@1494 83 if page && page.content
Chris@1494 84 page
Chris@1494 85 end
Chris@1494 86 end
Chris@1494 87 end
Chris@1494 88
Chris@1494 89 # turn a string into a valid page title
Chris@1494 90 def self.titleize(title)
Chris@1494 91 # replace spaces with _ and remove unwanted caracters
Chris@1494 92 title = title.gsub(/\s+/, '_').delete(',./?;|:') if title
Chris@1494 93 # upcase the first letter
Chris@1494 94 title = (title.slice(0..0).upcase + (title.slice(1..-1) || '')) if title
Chris@1494 95 title
Chris@1494 96 end
Chris@1494 97 end