Index: app/helpers/application_helper.rb =================================================================== --- app/helpers/application_helper.rb (revision 16970) +++ app/helpers/application_helper.rb (working copy) @@ -818,6 +818,10 @@ # user:jsmith -> Link to user with login jsmith # @jsmith -> Link to user with login jsmith # user#2 -> Link to user with id 2 + # Files: + # file#1 -> Link to file with id 1 + # file:filename.ext -> Link to file with filename "filename.ext" + # file:"filename.ext" -> Link to file with filename "filename.ext" # # Links can refer other objects from other projects, using project identifier: # identifier:r52 @@ -908,6 +912,15 @@ when 'user' u = User.visible.where(:id => oid, :type => 'User').first link = link_to_user(u, :only_path => only_path) if u + when 'file' + if project && file = Attachment.find_by_id(oid) + if (file.container.is_a?(Version) && file.container.project == project) || + (file.container.is_a?(Project) && file.container == project) + name = file.filename + link = link_to(h(name), { :only_path => only_path, :controller => 'attachments', :action => 'download', :id => file }, + :class => 'attachment') + end + end end elsif sep == ':' name = remove_double_quotes(identifier) @@ -969,6 +982,19 @@ when 'user' u = User.visible.where(:login => name, :type => 'User').first link = link_to_user(u, :only_path => only_path) if u + when 'file' + if project + conditions = "container_type = 'Project' AND container_id = #{project.id}" + if project.versions.any? + conditions = "(#{conditions}) OR " + conditions << "(container_type = 'Version' AND container_id IN (#{project.versions.collect{ |version| version.id }.join(', ')}))" + end + if file = Attachment.where(conditions).find_by_filename(name) + name = file.filename + link = link_to(h(name), { :only_path => only_path, :controller => 'attachments', :action => 'download', :id => file }, + :class => 'attachment') + end + end end elsif sep == "@" name = remove_double_quotes(identifier) @@ -987,7 +1013,7 @@ (?[\s\(,\-\[\>]|^) (?!)? (?(?[a-z0-9\-_]+):)? - (?attachment|document|version|forum|news|message|project|commit|source|export|user)? + (?attachment|document|version|forum|news|message|project|commit|source|export|user|file)? ( ( (?\#)|