diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f1b088c..fa141d6 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -29,8 +29,8 @@ module ApplicationHelper def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter # Return true if user is authorized for controller/action, otherwise false - def authorize_for(controller, action) - User.current.allowed_to?({:controller => controller, :action => action}, @project) + def authorize_for(controller, action, project = @project) + User.current.allowed_to?({:controller => controller, :action => action}, project) end # Display a link if user is authorized @@ -422,7 +422,12 @@ module ApplicationHelper # #52 -> Link to issue #52 # Changesets: # r52 -> Link to revision 52 + # project:r52 -> Link to revision 52 of an other project, using project name or identifier # commit:a85130f -> Link to scmid starting with a85130f + # project:commit:a85130f -> Link to scmid starting with a85130f of an other project, using project name or identifier + # If your project name contains spaces, use quotation marks : + # "My Project":r52 + # "My Project":commit:a85130f # Documents: # document#17 -> Link to document with id 17 # document:Greetings -> Link to the document with title "Greetings" @@ -441,15 +446,26 @@ module ApplicationHelper # export:some/file -> Force the download of the file # Forum messages: # message#1218 -> Link to message with id 1218 - text = text.gsub(%r{([\s\(,\-\>]|^)(!)?(attachment|document|version|commit|source|export|message)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|<|$)}) do |m| - leading, esc, prefix, sep, oid = $1, $2, $3, $5 || $7, $6 || $8 + text = text.gsub(%r{([\s\(,\-\>]|^)(!)?(attachment|document|version|(\"[^:<>\r\n\b]+\":|[^:<>\s\r\n\b]+:)?(commit)|source|export|message)?((#|(\"[^:<>\r\n\b]+\":|[^:<>\s\r\n\b]+:)?(r))(\d+)|(:)([^"\s<>][^:\s\r\n\b<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|<|$)}) do |m| + leading, esc, prefix, sep, revproj, oid = $1, $2, $5 || $3, $11 || $9 || $7, $4 || $8, $10 || $12 link = nil if esc.nil? if prefix.nil? && sep == 'r' - if project && (changeset = project.changesets.find_by_revision(oid)) - link = link_to("r#{oid}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => oid}, - :class => 'changeset', - :title => truncate_single_line(changeset.comments, :length => 100)) + if revproj.nil? + if project && (changeset = project.changesets.find_by_revision(oid)) + link = link_to("r#{oid}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => oid}, + :class => 'changeset', + :title => truncate_single_line(changeset.comments, :length => 100)) + end + else + revproj.gsub!(/[\:"]/,'') + link_project = Project.find_by_name(h(revproj)) || Project.find_by_identifier(h(revproj)) + if link_project && (changeset = link_project.changesets.find_by_revision(oid)) + title = truncate_single_line(changeset.comments, :length => 100) if authorize_for('repositories', 'revision', link_project) + link = link_to h("#{revproj}:r#{oid}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => link_project, :rev => oid}, + :class => 'changeset', + :title => title + end end elsif sep == '#' oid = oid.to_i @@ -497,10 +513,21 @@ module ApplicationHelper :class => 'version' 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.revision}, - :class => 'changeset', - :title => truncate_single_line(changeset.comments, :length => 100) + if revproj.nil? + 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.revision}, + :class => 'changeset', + :title => truncate_single_line(changeset.comments, :length => 100) + end + else + revproj.gsub!(/[\:"]/,'') + link_project = Project.find_by_name(h(revproj)) || Project.find_by_identifier(h(revproj)) + if link_project && (changeset = link_project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"])) + title = truncate_single_line(changeset.comments, :length => 100) if authorize_for('repositories', 'revision', link_project) + link = link_to h("#{revproj}:#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => link_project, :rev => changeset.revision}, + :class => 'changeset', + :title => title + end end when 'source', 'export' if project && project.repository @@ -521,7 +548,7 @@ module ApplicationHelper end end end - leading + (link || "#{prefix}#{sep}#{oid}") + leading + (link || (revproj ? "#{revproj}:" : "") + "#{prefix}#{sep}#{oid}") end text diff --git a/public/help/wiki_syntax_detailed.html b/public/help/wiki_syntax_detailed.html index 1131950..5047da4 100644 --- a/public/help/wiki_syntax_detailed.html +++ b/public/help/wiki_syntax_detailed.html @@ -49,6 +49,14 @@
You can also link to changesets of an other project repository:
+ +Wiki links:
#{result}
", textilizable(text) } + + User.current = nil end def test_wiki_links @@ -277,7 +293,7 @@ EXPECTED } to_test.each { |text, result| assert_equal "#{result}
", textilizable(text) } end - + def test_wiki_horizontal_rule assert_equal 'Dashes: ---
', textilizable('Dashes: ---')