summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/helpers/application_helper.rb32
-rw-r--r--app/models/wiki.rb6
2 files changed, 24 insertions, 14 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index f4d8a0d54..156310616 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -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:
diff --git a/app/models/wiki.rb b/app/models/wiki.rb
index 8d461a85b..ed473c7c0 100644
--- a/app/models/wiki.rb
+++ b/app/models/wiki.rb
@@ -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