Wiki links can now refer other project wikis, using this syntax:

[[project:]] -> wiki starting page
[[project:page]]
[[project:page|text]]
where 'project' is the project name or identifier.

git-svn-id: http://redmine.rubyforge.org/svn/trunk@643 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2007-08-15 17:31:01 +00:00
parent 38e0c237a4
commit a5849ee044
2 changed files with 24 additions and 14 deletions

View File

@ -126,23 +126,33 @@ module ApplicationHelper
case options[:wiki_links]
when :local
# used for local links to html files
format_wiki_link = Proc.new {|title| "#{title}.html" }
format_wiki_link = Proc.new {|project, title| "#{title}.html" }
when :anchor
# used for single-file wiki export
format_wiki_link = Proc.new {|title| "##{title}" }
format_wiki_link = Proc.new {|project, title| "##{title}" }
else
if @project
format_wiki_link = Proc.new {|title| url_for :controller => 'wiki', :action => 'index', :id => @project, :page => title }
else
format_wiki_link = Proc.new {|title| title }
end
format_wiki_link = Proc.new {|project, title| url_for :controller => 'wiki', :action => 'index', :id => project, :page => title }
end
# turn wiki links into textile links:
# turn wiki links into html links
# example:
# [[link]] -> "link":link
# [[link|title]] -> "title":link
text = text.gsub(/\[\[([^\]\|]+)(\|([^\]\|]+))?\]\]/) {|m| link_to(($3 || $1), format_wiki_link.call(Wiki.titleize($1)), :class => 'wiki-page') }
# [[mypage]]
# [[mypage|mytext]]
# wiki links can refer other project wikis, using project name or identifier:
# [[project:]] -> wiki starting page
# [[project:mypage]]
# [[project:mypage|mytext]]
text = text.gsub(/\[\[([^\]\|]+)(\|([^\]\|]+))?\]\]/) do |m|
project = @project
page = $1
title = $3
if page =~ /^([^\:]+)\:(.*)$/
project = Project.find_by_name($1) || Project.find_by_identifier($1)
page = $2
title = $1 if page.blank?
end
link_to((title || page), format_wiki_link.call(project, Wiki.titleize(page)), :class => 'wiki-page')
end
# turn issue ids into links
# example:

View File

@ -20,7 +20,7 @@ class Wiki < ActiveRecord::Base
has_many :pages, :class_name => 'WikiPage', :dependent => :destroy
validates_presence_of :start_page
validates_format_of :start_page, :with => /^[^,\.\/\?\;\|]*$/
validates_format_of :start_page, :with => /^[^,\.\/\?\;\|\:]*$/
# find the page with the given title
# if page doesn't exist, return a new page
@ -38,9 +38,9 @@ class Wiki < ActiveRecord::Base
# turn a string into a valid page title
def self.titleize(title)
# replace spaces with _ and remove unwanted caracters
title = title.gsub(/\s+/, '_').delete(',./?;|') if title
title = title.gsub(/\s+/, '_').delete(',./?;|:') if title
# upcase the first letter
title = title[0..0].upcase + title[1..-1] if title
title = (title.length > 1 ? title.first.upcase + title[1..-1] : title.upcase) if title
title
end
end