From a5849ee044837be589e9aae554cf99a394b9b9af Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Wed, 15 Aug 2007 17:31:01 +0000 Subject: [PATCH] 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 --- app/helpers/application_helper.rb | 32 ++++++++++++++++++++----------- app/models/wiki.rb | 6 +++--- 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 -- 2.39.5