27 |
27 |
def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter
|
28 |
28 |
|
29 |
29 |
# Return true if user is authorized for controller/action, otherwise false
|
30 |
|
def authorize_for(controller, action)
|
31 |
|
User.current.allowed_to?({:controller => controller, :action => action}, @project)
|
|
30 |
def authorize_for(controller, action, project = @project)
|
|
31 |
User.current.allowed_to?({:controller => controller, :action => action}, project)
|
32 |
32 |
end
|
33 |
33 |
|
34 |
34 |
# Display a link if user is authorized
|
... | ... | |
531 |
531 |
# #52 -> Link to issue #52
|
532 |
532 |
# Changesets:
|
533 |
533 |
# r52 -> Link to revision 52
|
|
534 |
# project:r52 -> Link to revision 52 of an other project, using project name or identifier
|
534 |
535 |
# commit:a85130f -> Link to scmid starting with a85130f
|
|
536 |
# project:commit:a85130f -> Link to scmid starting with a85130f of an other project, using project name or identifier
|
|
537 |
# If your project name contains spaces, use quotation marks :
|
|
538 |
# "My Project":r52
|
|
539 |
# "My Project":commit:a85130f
|
535 |
540 |
# Documents:
|
536 |
541 |
# document#17 -> Link to document with id 17
|
537 |
542 |
# document:Greetings -> Link to the document with title "Greetings"
|
... | ... | |
543 |
548 |
# Attachments:
|
544 |
549 |
# attachment:file.zip -> Link to the attachment of the current object named file.zip
|
545 |
550 |
# Source files:
|
|
551 |
# ["Link alternate display title"=][project:]source:some/path[/file][@52][#L120]
|
|
552 |
# ["Link alternate display title"=][project:]export:some/path/file[@52]
|
546 |
553 |
# source:some/file -> Link to the file located at /some/file in the project's repository
|
547 |
554 |
# source:some/file@52 -> Link to the file's revision 52
|
548 |
555 |
# source:some/file#L120 -> Link to line 120 of the file
|
|
556 |
# "click here"=source:some/file#L120 -> Link to line 120 of the file
|
|
557 |
# "click here"=wizbang:source:some/file#L120 -> Link to line 120 of the file in the repo for the wizbang project
|
549 |
558 |
# source:some/file@52#L120 -> Link to line 120 of the file's revision 52
|
550 |
559 |
# export:some/file -> Force the download of the file
|
|
560 |
# "Download This File"=export:some/file -> Force the download of the file
|
|
561 |
# "Download This File"=myproject:export:some/file -> Force the download of the file in repository for myproject project
|
551 |
562 |
# Forum messages:
|
552 |
563 |
# message#1218 -> Link to message with id 1218
|
553 |
564 |
def parse_redmine_links(text, project, obj, attr, only_path, options)
|
554 |
|
text.gsub!(%r{([\s\(,\-\[\>]|^)(!)?(attachment|document|version|commit|source|export|message|project)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|\]|<|$)}) do |m|
|
555 |
|
leading, esc, prefix, sep, identifier = $1, $2, $3, $5 || $7, $6 || $8
|
|
565 |
text.gsub!(%r{([\s\(,\-\[\>]|^)(!)?(\"[^\"\n]+\"=)?(attachment|document|version|(\"[^:<>\r\n\b]+\":|[^:<>\s\r\n\b]+:)?(commit|source|export)|message|project)?((#|(\"[^:<>\r\n\b]+\":|[^:<>\s\r\n\b]+:)?(r))(\d+)|(:)([^"\s<>][^:\s\r\n\b<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|\]|<|$)}) do |m|
|
|
566 |
|
|
567 |
leading, esc, linktitle, prefix, sep, revproj, identifier = $1, $2, $3, $6 || $4, $12 || $10 || $8, $5 || $9, $11 || $13
|
|
568 |
#logger.debug "leading=#{leading},esc=#{esc},linktitle=#{linktitle},prefix=#{prefix},sep=#{sep},revproj=#{revproj},identifier=#{identifier}"
|
556 |
569 |
link = nil
|
557 |
570 |
if esc.nil?
|
558 |
571 |
if prefix.nil? && sep == 'r'
|
|
572 |
if revproj.nil?
|
559 |
573 |
if project && (changeset = project.changesets.find_by_revision(identifier))
|
560 |
574 |
link = link_to("r#{identifier}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision},
|
561 |
|
:class => 'changeset',
|
562 |
|
:title => truncate_single_line(changeset.comments, :length => 100))
|
|
575 |
:class => 'changeset',
|
|
576 |
:title => truncate_single_line(changeset.comments, :length => 100))
|
|
577 |
end
|
|
578 |
else
|
|
579 |
revproj.gsub!(/[\:"]/,'')
|
|
580 |
link_project = Project.find_by_name(h(revproj)) || Project.find_by_identifier(h(revproj))
|
|
581 |
if link_project && (changeset = link_project.changesets.find_by_revision(identifier))
|
|
582 |
title = truncate_single_line(changeset.comments, :length => 100) if authorize_for('repositories', 'revision', link_project)
|
|
583 |
link = link_to h("#{revproj}:r#{identifier}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => link_project, :rev => changeset.revision},
|
|
584 |
:class => 'changeset',
|
|
585 |
:title => title
|
|
586 |
end
|
563 |
587 |
end
|
564 |
588 |
elsif sep == '#'
|
565 |
589 |
oid = identifier.to_i
|
... | ... | |
611 |
635 |
:class => 'version'
|
612 |
636 |
end
|
613 |
637 |
when 'commit'
|
614 |
|
if project && (changeset = project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"]))
|
615 |
|
link = link_to h("#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision},
|
616 |
|
:class => 'changeset',
|
617 |
|
:title => truncate_single_line(changeset.comments, :length => 100)
|
|
638 |
if revproj.nil?
|
|
639 |
if project && (changeset = project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"]))
|
|
640 |
link = link_to h("#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision},
|
|
641 |
:class => 'changeset',
|
|
642 |
:title => truncate_single_line(changeset.comments, :length => 100)
|
|
643 |
end
|
|
644 |
else
|
|
645 |
revproj.gsub!(/[\:"]/,'')
|
|
646 |
link_project = Project.find_by_name(h(revproj)) || Project.find_by_identifier(h(revproj))
|
|
647 |
if link_project && (changeset = link_project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"]))
|
|
648 |
title = truncate_single_line(changeset.comments, :length => 100) if authorize_for('repositories', 'revision', link_project)
|
|
649 |
link = link_to h("#{revproj}:#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => link_project, :rev => changeset.revision},
|
|
650 |
:class => 'changeset',
|
|
651 |
:title => title
|
|
652 |
end
|
618 |
653 |
end
|
619 |
654 |
when 'source', 'export'
|
620 |
|
if project && project.repository
|
|
655 |
if revproj.nil?
|
|
656 |
link_project = project
|
|
657 |
else
|
|
658 |
revproj.gsub!(/[\:"]/,'')
|
|
659 |
link_project = Project.find_by_name(h(revproj)) || Project.find_by_identifier(h(revproj))
|
|
660 |
end
|
|
661 |
if link_project && link_project.repository
|
621 |
662 |
name =~ %r{^[/\\]*(.*?)(@([0-9a-f]+))?(#(L\d+))?$}
|
622 |
663 |
path, rev, anchor = $1, $3, $5
|
623 |
|
link = link_to h("#{prefix}:#{name}"), {:controller => 'repositories', :action => 'entry', :id => project,
|
|
664 |
link_title = linktitle ? linktitle.gsub!(/[\"=]/,'') : (link_project != project ? "#{revproj}:" : "") + "#{prefix}:#{name}"
|
|
665 |
link = link_to h(link_title), {:only_path => only_path, :controller => 'repositories', :action => 'entry', :id => link_project,
|
624 |
666 |
:path => to_path_param(path),
|
625 |
667 |
:rev => rev,
|
626 |
668 |
:anchor => anchor,
|