diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f04e5491..d5a65891 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -588,16 +588,25 @@ module ApplicationHelper # source:some/file#L120 -> Link to line 120 of the file # source:some/file@52#L120 -> Link to line 120 of the file's revision 52 # export:some/file -> Force the download of the file - # Forum messages: + # Forum messages: # message#1218 -> Link to message with id 1218 + # + # Links can refer other objects from other projects, using project identifier: + # identifier:r52 + # identifier:document:"Some document" + # identifier:version:1.0.0 + # identifier:source:some/file def parse_redmine_links(text, project, obj, attr, only_path, options) - text.gsub!(%r{([\s\(,\-\[\>]|^)(!)?(attachment|document|version|commit|source|export|message|project)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|\]|<|$)}) do |m| - leading, esc, prefix, sep, identifier = $1, $2, $3, $5 || $7, $6 || $8 + text.gsub!(%r{([\s\(,\-\[\>]|^)(!)?(([a-z0-9\-]+):)?(attachment|document|version|commit|source|export|message|project)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|\]|<|$)}) do |m| + leading, esc, project_prefix, project_identifier, prefix, sep, identifier = $1, $2, $3, $4, $5, $7 || $9, $8 || $10 link = nil + if project_identifier + project = Project.visible.find_by_identifier(project_identifier) + end if esc.nil? if prefix.nil? && sep == 'r' if project && (changeset = project.changesets.find_by_revision(identifier)) - link = link_to("r#{identifier}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision}, + link = link_to("#{project_prefix}r#{identifier}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision}, :class => 'changeset', :title => truncate_single_line(changeset.comments, :length => 100)) end @@ -651,7 +660,7 @@ module ApplicationHelper end when 'commit' if project && (changeset = project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"])) - link = link_to h("#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.identifier}, + link = link_to h("#{project_prefix}#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.identifier}, :class => 'changeset', :title => truncate_single_line(changeset.comments, :length => 100) end @@ -659,7 +668,7 @@ module ApplicationHelper if project && project.repository name =~ %r{^[/\\]*(.*?)(@([0-9a-f]+))?(#(L\d+))?$} path, rev, anchor = $1, $3, $5 - link = link_to h("#{prefix}:#{name}"), {:controller => 'repositories', :action => 'entry', :id => project, + link = link_to h("#{project_prefix}#{prefix}:#{name}"), {:controller => 'repositories', :action => 'entry', :id => project, :path => to_path_param(path), :rev => rev, :anchor => anchor, @@ -679,7 +688,7 @@ module ApplicationHelper end end end - leading + (link || "#{prefix}#{sep}#{identifier}") + leading + (link || "#{project_prefix}#{prefix}#{sep}#{identifier}") end end diff --git a/public/help/wiki_syntax_detailed.html b/public/help/wiki_syntax_detailed.html index a1af336a..0c9cea34 100644 --- a/public/help/wiki_syntax_detailed.html +++ b/public/help/wiki_syntax_detailed.html @@ -46,7 +46,9 @@

Wiki links:

@@ -74,7 +76,7 @@
  • document#17 (link to document with id 17)
  • document:Greetings (link to the document with title "Greetings")
  • document:"Some document" (double quotes can be used when document title contains spaces)
  • -
  • document:some_project:"Some document" (link to a document with title "Some document" in other project "some_project") +
  • sandbox:document:"Some document" (link to a document with title "Some document" in other project "sandbox")
  • @@ -84,6 +86,7 @@
  • version#3 (link to version with id 3)
  • version:1.0.0 (link to version named "1.0.0")
  • version:"1.0 beta 2"
  • +
  • sandbox:version:1.0.0 (link to version "1.0.0" in the project "sandbox")
  • @@ -103,7 +106,9 @@
  • source:some/file#L120 (link to line 120 of the file)
  • source:some/file@52#L120 (link to line 120 of the file's revision 52)
  • source:"some file@52#L120" (use double quotes when the URL contains spaces
  • -
  • export:some/file (force the download of the file)
  • +
  • export:some/file (force the download of the file)
  • +
  • sandbox:source:some/file (link to the file located at /some/file in the repository of the project "sandbox")
  • +
  • sandbox:export:some/file (force the download of the file)
  • diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb index c8235ada..9232b1b8 100644 --- a/test/unit/helpers/application_helper_test.rb +++ b/test/unit/helpers/application_helper_test.rb @@ -224,6 +224,35 @@ RAW @project = Project.find(1) to_test.each { |text, result| assert_equal "

    #{result}

    ", textilizable(text), "#{text} failed" } end + + def test_cross_project_redmine_links + source_link = link_to('ecookbook:source:/some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']}, + :class => 'source') + + changeset_link = link_to('ecookbook:r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2}, + :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3') + + to_test = { + # documents + 'document:"Test document"' => 'document:"Test document"', + 'ecookbook:document:"Test document"' => 'Test document', + 'invalid:document:"Test document"' => 'invalid:document:"Test document"', + # versions + 'version:"1.0"' => 'version:"1.0"', + 'ecookbook:version:"1.0"' => '1.0', + 'invalid:version:"1.0"' => 'invalid:version:"1.0"', + # changeset + 'r2' => 'r2', + 'ecookbook:r2' => changeset_link, + 'invalid:r2' => 'invalid:r2', + # source + 'source:/some/file' => 'source:/some/file', + 'ecookbook:source:/some/file' => source_link, + 'invalid:source:/some/file' => 'invalid:source:/some/file', + } + @project = Project.find(3) + to_test.each { |text, result| assert_equal "

    #{result}

    ", textilizable(text), "#{text} failed" } + end def test_redmine_links_git_commit changeset_link = link_to('abcd',