# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
--- J:\application_helper.rb
+++ C:\Depots\redmine\app\helpers\application_helper.rb
@@ -29,8 +29,8 @@
   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,9 @@
     #     #52 -> Link to issue #52
     #   Changesets:
     #     r52 -> Link to revision 52
+    #     r:project:52 -> Link to revision 52 of an other project, using project name or identifier
     #     commit:a85130f -> Link to scmid starting with a85130f
+    #     commit:project:a85130f -> Link to scmid starting with a85130f of an other project, using project name or identifier
     #   Documents:
     #     document#17 -> Link to document with id 17
     #     document:Greetings -> Link to the document with title "Greetings"
@@ -441,16 +443,27 @@
     #     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|commit|source|export|message)?((#|r)(:[^\s<>][^\:\r\n\b]+[^\s<>]:)?(\d+)|(:)([^\s<>][^\:\r\n\b]+[^\s<>]:)?([^"\:\s<>][^\:\s\r\n\b<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|<|$)}) do |m|
+      leading, esc, prefix, sep, revproj, oid = $1, $2, $3, $8 || $5, $9 || $6, $10 || $7
       link = nil
       if esc.nil?
         if prefix.nil? && sep == 'r'
+          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
           case prefix
@@ -497,11 +510,22 @@
                                               :class => 'version'
             end
           when 'commit'
+            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
               name =~ %r{^[/\\]*(.*?)(@([0-9a-f]+))?(#(L\d+))?$}
@@ -521,7 +545,7 @@
           end
         end
       end
-      leading + (link || "#{prefix}#{sep}#{oid}")
+      leading + (link || (revproj ? "#{revproj}:" : "") + "#{prefix}#{sep}#{oid}")
     end
 
     text
