Mercurial > hg > soundsoftware-site
comparison app/helpers/.svn/text-base/application_helper.rb.svn-base @ 210:0579821a129a
Update to Redmine trunk rev 4802
author | Chris Cannam |
---|---|
date | Tue, 08 Feb 2011 13:51:46 +0000 |
parents | 8661b858af72 |
children | 051f544170fe |
comparison
equal
deleted
inserted
replaced
128:07fa8a8b56a8 | 210:0579821a129a |
---|---|
106 text = options.delete(:text) || format_revision(revision) | 106 text = options.delete(:text) || format_revision(revision) |
107 rev = revision.respond_to?(:identifier) ? revision.identifier : revision | 107 rev = revision.respond_to?(:identifier) ? revision.identifier : revision |
108 | 108 |
109 link_to(text, {:controller => 'repositories', :action => 'revision', :id => project, :rev => rev}, | 109 link_to(text, {:controller => 'repositories', :action => 'revision', :id => project, :rev => rev}, |
110 :title => l(:label_revision_id, format_revision(revision))) | 110 :title => l(:label_revision_id, format_revision(revision))) |
111 end | |
112 | |
113 # Generates a link to a message | |
114 def link_to_message(message, options={}, html_options = nil) | |
115 link_to( | |
116 h(truncate(message.subject, :length => 60)), | |
117 { :controller => 'messages', :action => 'show', | |
118 :board_id => message.board_id, | |
119 :id => message.root, | |
120 :r => (message.parent_id && message.id), | |
121 :anchor => (message.parent_id ? "message-#{message.id}" : nil) | |
122 }.merge(options), | |
123 html_options | |
124 ) | |
111 end | 125 end |
112 | 126 |
113 # Generates a link to a project if active | 127 # Generates a link to a project if active |
114 # Examples: | 128 # Examples: |
115 # | 129 # |
586 # source:some/file -> Link to the file located at /some/file in the project's repository | 600 # source:some/file -> Link to the file located at /some/file in the project's repository |
587 # source:some/file@52 -> Link to the file's revision 52 | 601 # source:some/file@52 -> Link to the file's revision 52 |
588 # source:some/file#L120 -> Link to line 120 of the file | 602 # source:some/file#L120 -> Link to line 120 of the file |
589 # source:some/file@52#L120 -> Link to line 120 of the file's revision 52 | 603 # source:some/file@52#L120 -> Link to line 120 of the file's revision 52 |
590 # export:some/file -> Force the download of the file | 604 # export:some/file -> Force the download of the file |
591 # Forum messages: | 605 # Forum messages: |
592 # message#1218 -> Link to message with id 1218 | 606 # message#1218 -> Link to message with id 1218 |
607 # | |
608 # Links can refer other objects from other projects, using project identifier: | |
609 # identifier:r52 | |
610 # identifier:document:"Some document" | |
611 # identifier:version:1.0.0 | |
612 # identifier:source:some/file | |
593 def parse_redmine_links(text, project, obj, attr, only_path, options) | 613 def parse_redmine_links(text, project, obj, attr, only_path, options) |
594 text.gsub!(%r{([\s\(,\-\[\>]|^)(!)?(attachment|document|version|commit|source|export|message|project)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|\]|<|$)}) do |m| | 614 text.gsub!(%r{([\s\(,\-\[\>]|^)(!)?(([a-z0-9\-]+):)?(attachment|document|version|commit|source|export|message|project)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|\]|<|$)}) do |m| |
595 leading, esc, prefix, sep, identifier = $1, $2, $3, $5 || $7, $6 || $8 | 615 leading, esc, project_prefix, project_identifier, prefix, sep, identifier = $1, $2, $3, $4, $5, $7 || $9, $8 || $10 |
596 link = nil | 616 link = nil |
617 if project_identifier | |
618 project = Project.visible.find_by_identifier(project_identifier) | |
619 end | |
597 if esc.nil? | 620 if esc.nil? |
598 if prefix.nil? && sep == 'r' | 621 if prefix.nil? && sep == 'r' |
599 if project && (changeset = project.changesets.find_by_revision(identifier)) | 622 # project.changesets.visible raises an SQL error because of a double join on repositories |
600 link = link_to("r#{identifier}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision}, | 623 if project && project.repository && (changeset = Changeset.visible.find_by_repository_id_and_revision(project.repository.id, identifier)) |
624 link = link_to("#{project_prefix}r#{identifier}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision}, | |
601 :class => 'changeset', | 625 :class => 'changeset', |
602 :title => truncate_single_line(changeset.comments, :length => 100)) | 626 :title => truncate_single_line(changeset.comments, :length => 100)) |
603 end | 627 end |
604 elsif sep == '#' | 628 elsif sep == '#' |
605 oid = identifier.to_i | 629 oid = identifier.to_i |
609 link = link_to("##{oid}", {:only_path => only_path, :controller => 'issues', :action => 'show', :id => oid}, | 633 link = link_to("##{oid}", {:only_path => only_path, :controller => 'issues', :action => 'show', :id => oid}, |
610 :class => issue.css_classes, | 634 :class => issue.css_classes, |
611 :title => "#{truncate(issue.subject, :length => 100)} (#{issue.status.name})") | 635 :title => "#{truncate(issue.subject, :length => 100)} (#{issue.status.name})") |
612 end | 636 end |
613 when 'document' | 637 when 'document' |
614 if document = Document.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current)) | 638 if document = Document.visible.find_by_id(oid) |
615 link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document}, | 639 link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document}, |
616 :class => 'document' | 640 :class => 'document' |
617 end | 641 end |
618 when 'version' | 642 when 'version' |
619 if version = Version.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current)) | 643 if version = Version.visible.find_by_id(oid) |
620 link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version}, | 644 link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version}, |
621 :class => 'version' | 645 :class => 'version' |
622 end | 646 end |
623 when 'message' | 647 when 'message' |
624 if message = Message.find_by_id(oid, :include => [:parent, {:board => :project}], :conditions => Project.visible_by(User.current)) | 648 if message = Message.visible.find_by_id(oid, :include => :parent) |
625 link = link_to h(truncate(message.subject, :length => 60)), {:only_path => only_path, | 649 link = link_to_message(message, {:only_path => only_path}, :class => 'message') |
626 :controller => 'messages', | |
627 :action => 'show', | |
628 :board_id => message.board, | |
629 :id => message.root, | |
630 :anchor => (message.parent ? "message-#{message.id}" : nil)}, | |
631 :class => 'message' | |
632 end | 650 end |
633 when 'project' | 651 when 'project' |
634 if p = Project.visible.find_by_id(oid) | 652 if p = Project.visible.find_by_id(oid) |
635 link = link_to_project(p, {:only_path => only_path}, :class => 'project') | 653 link = link_to_project(p, {:only_path => only_path}, :class => 'project') |
636 end | 654 end |
638 elsif sep == ':' | 656 elsif sep == ':' |
639 # removes the double quotes if any | 657 # removes the double quotes if any |
640 name = identifier.gsub(%r{^"(.*)"$}, "\\1") | 658 name = identifier.gsub(%r{^"(.*)"$}, "\\1") |
641 case prefix | 659 case prefix |
642 when 'document' | 660 when 'document' |
643 if project && document = project.documents.find_by_title(name) | 661 if project && document = project.documents.visible.find_by_title(name) |
644 link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document}, | 662 link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document}, |
645 :class => 'document' | 663 :class => 'document' |
646 end | 664 end |
647 when 'version' | 665 when 'version' |
648 if project && version = project.versions.find_by_name(name) | 666 if project && version = project.versions.visible.find_by_name(name) |
649 link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version}, | 667 link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version}, |
650 :class => 'version' | 668 :class => 'version' |
651 end | 669 end |
652 when 'commit' | 670 when 'commit' |
653 if project && (changeset = project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"])) | 671 if project && project.repository && (changeset = Changeset.visible.find(:first, :conditions => ["repository_id = ? AND scmid LIKE ?", project.repository.id, "#{name}%"])) |
654 link = link_to h("#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.identifier}, | 672 link = link_to h("#{project_prefix}#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.identifier}, |
655 :class => 'changeset', | 673 :class => 'changeset', |
656 :title => truncate_single_line(changeset.comments, :length => 100) | 674 :title => truncate_single_line(changeset.comments, :length => 100) |
657 end | 675 end |
658 when 'source', 'export' | 676 when 'source', 'export' |
659 if project && project.repository | 677 if project && project.repository && User.current.allowed_to?(:browse_repository, project) |
660 name =~ %r{^[/\\]*(.*?)(@([0-9a-f]+))?(#(L\d+))?$} | 678 name =~ %r{^[/\\]*(.*?)(@([0-9a-f]+))?(#(L\d+))?$} |
661 path, rev, anchor = $1, $3, $5 | 679 path, rev, anchor = $1, $3, $5 |
662 link = link_to h("#{prefix}:#{name}"), {:controller => 'repositories', :action => 'entry', :id => project, | 680 link = link_to h("#{project_prefix}#{prefix}:#{name}"), {:controller => 'repositories', :action => 'entry', :id => project, |
663 :path => to_path_param(path), | 681 :path => to_path_param(path), |
664 :rev => rev, | 682 :rev => rev, |
665 :anchor => anchor, | 683 :anchor => anchor, |
666 :format => (prefix == 'export' ? 'raw' : nil)}, | 684 :format => (prefix == 'export' ? 'raw' : nil)}, |
667 :class => (prefix == 'export' ? 'source download' : 'source') | 685 :class => (prefix == 'export' ? 'source download' : 'source') |
677 link = link_to_project(p, {:only_path => only_path}, :class => 'project') | 695 link = link_to_project(p, {:only_path => only_path}, :class => 'project') |
678 end | 696 end |
679 end | 697 end |
680 end | 698 end |
681 end | 699 end |
682 leading + (link || "#{prefix}#{sep}#{identifier}") | 700 leading + (link || "#{project_prefix}#{prefix}#{sep}#{identifier}") |
683 end | 701 end |
684 end | 702 end |
685 | 703 |
686 HEADING_RE = /<h(1|2|3|4)( [^>]+)?>(.+?)<\/h(1|2|3|4)>/i unless const_defined?(:HEADING_RE) | 704 HEADING_RE = /<h(1|2|3|4)( [^>]+)?>(.+?)<\/h(1|2|3|4)>/i unless const_defined?(:HEADING_RE) |
687 | 705 |