508 |
508 |
# export:some/file -> Force the download of the file
|
509 |
509 |
# Forum messages:
|
510 |
510 |
# message#1218 -> Link to message with id 1218
|
511 |
|
text = text.gsub(%r{([\s\(,\-\>]|^)(!)?(attachment|document|version|commit|source|export|message)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|<|$)}) do |m|
|
512 |
|
leading, esc, prefix, sep, oid = $1, $2, $3, $5 || $7, $6 || $8
|
|
511 |
text = text.gsub(%r{([\s\(,\-\>]|^)(!)?("([^"]+)":)?(attachment|document|version|commit|source|export|message)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|<|$)}) do |m|
|
|
512 |
leading, esc, label, prefix, sep, oid = $1, $2, $4, $5, $7 || $9, $8 || $10
|
513 |
513 |
link = nil
|
514 |
514 |
if esc.nil?
|
515 |
515 |
if prefix.nil? && sep == 'r'
|
516 |
516 |
if project && (changeset = project.changesets.find_by_revision(oid))
|
517 |
|
link = link_to("r#{oid}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => oid},
|
|
517 |
label = label || "r#{oid}"
|
|
518 |
link = link_to(label, {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => oid},
|
518 |
519 |
:class => 'changeset',
|
519 |
520 |
:title => truncate_single_line(changeset.comments, :length => 100))
|
520 |
521 |
end
|
... | ... | |
523 |
524 |
case prefix
|
524 |
525 |
when nil
|
525 |
526 |
if issue = Issue.visible.find_by_id(oid, :include => :status)
|
526 |
|
link = link_to("##{oid}", {:only_path => only_path, :controller => 'issues', :action => 'show', :id => oid},
|
|
527 |
title = label ? "##{oid} #{truncate(issue.subject, :length => 100)} (#{issue.status.name})" : "#{truncate(issue.subject, :length => 100)} (#{issue.status.name})"
|
|
528 |
label = label || "##{oid}"
|
|
529 |
link = link_to(label, {:only_path => only_path, :controller => 'issues', :action => 'show', :id => oid},
|
527 |
530 |
:class => issue.css_classes,
|
528 |
|
:title => "#{truncate(issue.subject, :length => 100)} (#{issue.status.name})")
|
|
531 |
:title => title)
|
529 |
532 |
end
|
530 |
533 |
when 'document'
|
531 |
534 |
if document = Document.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
|
532 |
|
link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
|
|
535 |
label = label || h(document.title)
|
|
536 |
link = link_to label, {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
|
533 |
537 |
:class => 'document'
|
534 |
538 |
end
|
535 |
539 |
when 'version'
|
536 |
540 |
if version = Version.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
|
537 |
|
link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
|
|
541 |
label = label || h(version.name)
|
|
542 |
link = link_to label, {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
|
538 |
543 |
:class => 'version'
|
539 |
544 |
end
|
540 |
545 |
when 'message'
|
541 |
546 |
if message = Message.find_by_id(oid, :include => [:parent, {:board => :project}], :conditions => Project.visible_by(User.current))
|
542 |
|
link = link_to h(truncate(message.subject, :length => 60)), {:only_path => only_path,
|
|
547 |
label = label || h(truncate(message.subject, :length => 60))
|
|
548 |
link = link_to label, {:only_path => only_path,
|
543 |
549 |
:controller => 'messages',
|
544 |
550 |
:action => 'show',
|
545 |
551 |
:board_id => message.board,
|
... | ... | |
554 |
560 |
case prefix
|
555 |
561 |
when 'document'
|
556 |
562 |
if project && document = project.documents.find_by_title(name)
|
557 |
|
link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
|
|
563 |
label = label || h(document.title)
|
|
564 |
link = link_to label, {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
|
558 |
565 |
:class => 'document'
|
559 |
566 |
end
|
560 |
567 |
when 'version'
|
561 |
568 |
if project && version = project.versions.find_by_name(name)
|
562 |
|
link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
|
|
569 |
label = label || h(version.name)
|
|
570 |
link = link_to label, {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
|
563 |
571 |
:class => 'version'
|
564 |
572 |
end
|
565 |
573 |
when 'commit'
|
566 |
574 |
if project && (changeset = project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"]))
|
567 |
|
link = link_to h("#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision},
|
|
575 |
label = label || h("#{name}")
|
|
576 |
link = link_to label, {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision},
|
568 |
577 |
:class => 'changeset',
|
569 |
578 |
:title => truncate_single_line(changeset.comments, :length => 100)
|
570 |
579 |
end
|
... | ... | |
572 |
581 |
if project && project.repository
|
573 |
582 |
name =~ %r{^[/\\]*(.*?)(@([0-9a-f]+))?(#(L\d+))?$}
|
574 |
583 |
path, rev, anchor = $1, $3, $5
|
575 |
|
link = link_to h("#{prefix}:#{name}"), {:controller => 'repositories', :action => 'entry', :id => project,
|
|
584 |
label = label || h("#{prefix}:#{name}")
|
|
585 |
link = link_to label, {:controller => 'repositories', :action => 'entry', :id => project,
|
576 |
586 |
:path => to_path_param(path),
|
577 |
587 |
:rev => rev,
|
578 |
588 |
:anchor => anchor,
|
... | ... | |
581 |
591 |
end
|
582 |
592 |
when 'attachment'
|
583 |
593 |
if attachments && attachment = attachments.detect {|a| a.filename == name }
|
584 |
|
link = link_to h(attachment.filename), {:only_path => only_path, :controller => 'attachments', :action => 'download', :id => attachment},
|
|
594 |
label = label || h(attachment.filename)
|
|
595 |
link = link_to label, {:only_path => only_path, :controller => 'attachments', :action => 'download', :id => attachment},
|
585 |
596 |
:class => 'attachment'
|
586 |
597 |
end
|
587 |
598 |
end
|