Commit 15f6083d authored by jplang's avatar jplang

Adds support for cross project Redmine links (#7409).

See public/help/wiki_syntax_detailed.html for the syntax.

git-svn-id: https://svn.redmine.org/redmine/trunk@4758 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 7784aec4
......@@ -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
......
......@@ -46,7 +46,9 @@
<ul>
<li>Link to an issue: <strong>#124</strong> (displays <del><a href="#" class="issue" title="bulk edit doesn't change the category or fixed version properties (Closed)">#124</a></del>, link is striked-through if the issue is closed)</li>
<li>Link to a changeset: <strong>r758</strong> (displays <a href="#" class="changeset" title="Search engine now only searches objects the user is allowed to view.">r758</a>)</li>
<li>Link to a changeset with a non-numeric hash: <strong>commit:c6f4d0fd</strong> (displays c6f4d0fd). Added in <a href="#" class="changeset" title="Merged Git support branch (r1200 to r1226).">r1236</a>.</li>
<li>Link to a changeset with a non-numeric hash: <strong>commit:c6f4d0fd</strong> (displays <a href="#" class="changeset">c6f4d0fd</a>).</li>
<li>Link to a changeset of another project: <strong>sandbox:r758</strong> (displays <a href="#" class="changeset" title="Search engine now only searches objects the user is allowed to view.">sanbox:r758</a>)</li>
<li>Link to a changeset with a non-numeric hash: <strong>sandbox:c6f4d0fd</strong> (displays <a href="#" class="changeset">sandbox:c6f4d0fd</a>).</li>
</ul>
<p>Wiki links:</p>
......@@ -74,7 +76,7 @@
<li><strong>document#17</strong> (link to document with id 17)</li>
<li><strong>document:Greetings</strong> (link to the document with title "Greetings")</li>
<li><strong>document:"Some document"</strong> (double quotes can be used when document title contains spaces)</li>
<li><strong>document:some_project:"Some document"</strong> (link to a document with title "Some document" in other project "some_project")
<li><strong>sandbox:document:"Some document"</strong> (link to a document with title "Some document" in other project "sandbox")</li>
</ul></li>
</ul>
......@@ -84,6 +86,7 @@
<li><strong>version#3</strong> (link to version with id 3)</li>
<li><strong>version:1.0.0</strong> (link to version named "1.0.0")</li>
<li><strong>version:"1.0 beta 2"</strong></li>
<li><strong>sandbox:version:1.0.0</strong> (link to version "1.0.0" in the project "sandbox")</li>
</ul></li>
</ul>
......@@ -103,7 +106,9 @@
<li><strong>source:some/file#L120</strong> (link to line 120 of the file)</li>
<li><strong>source:some/file@52#L120</strong> (link to line 120 of the file's revision 52)</li>
<li><strong>source:"some file@52#L120"</strong> (use double quotes when the URL contains spaces</li>
<li><strong>export:some/file</strong> (force the download of the file)</li>
<li><strong>export:some/file</strong> (force the download of the file)</li>
<li><strong>sandbox:source:some/file</strong> (link to the file located at /some/file in the repository of the project "sandbox")</li>
<li><strong>sandbox:export:some/file</strong> (force the download of the file)</li>
</ul></li>
</ul>
......
......@@ -224,6 +224,35 @@ RAW
@project = Project.find(1)
to_test.each { |text, result| assert_equal "<p>#{result}</p>", 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"' => '<a href="/documents/1" class="document">Test document</a>',
'invalid:document:"Test document"' => 'invalid:document:"Test document"',
# versions
'version:"1.0"' => 'version:"1.0"',
'ecookbook:version:"1.0"' => '<a href="/versions/show/2" class="version">1.0</a>',
'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 "<p>#{result}</p>", textilizable(text), "#{text} failed" }
end
def test_redmine_links_git_commit
changeset_link = link_to('abcd',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment