| 29 |
29 |
def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter
|
| 30 |
30 |
|
| 31 |
31 |
# Return true if user is authorized for controller/action, otherwise false
|
| 32 |
|
def authorize_for(controller, action)
|
| 33 |
|
User.current.allowed_to?({:controller => controller, :action => action}, @project)
|
|
32 |
def authorize_for(controller, action, project = @project)
|
|
33 |
User.current.allowed_to?({:controller => controller, :action => action}, project)
|
| 34 |
34 |
end
|
| 35 |
35 |
|
| 36 |
36 |
# Display a link if user is authorized
|
| ... | ... | |
| 443 |
443 |
# #52 -> Link to issue #52
|
| 444 |
444 |
# Changesets:
|
| 445 |
445 |
# r52 -> Link to revision 52
|
|
446 |
# project:r52 -> Link to revision 52 of an other project, using project name or identifier
|
| 446 |
447 |
# commit:a85130f -> Link to scmid starting with a85130f
|
|
448 |
# project:commit:a85130f -> Link to scmid starting with a85130f of an other project, using project name or identifier
|
|
449 |
# If your project name contains spaces, use quotation marks :
|
|
450 |
# "My Project":r52
|
|
451 |
# "My Project":commit:a85130f
|
| 447 |
452 |
# Documents:
|
| 448 |
453 |
# document#17 -> Link to document with id 17
|
| 449 |
454 |
# document:Greetings -> Link to the document with title "Greetings"
|
| ... | ... | |
| 455 |
460 |
# Attachments:
|
| 456 |
461 |
# attachment:file.zip -> Link to the attachment of the current object named file.zip
|
| 457 |
462 |
# Source files:
|
|
463 |
# ["Link alternate display title"=][project:]source:some/path[/file][@52][#L120]
|
|
464 |
# ["Link alternate display title"=][project:]export:some/path/file[@52]
|
| 458 |
465 |
# source:some/file -> Link to the file located at /some/file in the project's repository
|
| 459 |
466 |
# source:some/file@52 -> Link to the file's revision 52
|
| 460 |
467 |
# source:some/file#L120 -> Link to line 120 of the file
|
|
468 |
# "click here"=source:some/file#L120 -> Link to line 120 of the file
|
|
469 |
# "click here"=wizbang:source:some/file#L120 -> Link to line 120 of the file in the repo for the wizbang project
|
| 461 |
470 |
# source:some/file@52#L120 -> Link to line 120 of the file's revision 52
|
| 462 |
471 |
# export:some/file -> Force the download of the file
|
|
472 |
# "Download This File"=export:some/file -> Force the download of the file
|
|
473 |
# "Download This File"=myproject:export:some/file -> Force the download of the file in repository for myproject project
|
| 463 |
474 |
# Forum messages:
|
| 464 |
475 |
# message#1218 -> Link to message with id 1218
|
| 465 |
|
text = text.gsub(%r{([\s\(,\-\>]|^)(!)?(attachment|document|version|commit|source|export|message)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|<|$)}) do |m|
|
| 466 |
|
leading, esc, prefix, sep, oid = $1, $2, $3, $5 || $7, $6 || $8
|
|
476 |
text = text.gsub(%r{([\s\(,\-\>]|^)(!)?(\"[^\"\n]+\"=)?(attachment|document|version|(\"[^:<>\r\n\b]+\":|[^:<>\s\r\n\b]+:)?(commit|source|export)|message)?((#|(\"[^:<>\r\n\b]+\":|[^:<>\s\r\n\b]+:)?(r))(\d+)|(:)([^"\s<>][^:\s\r\n\b<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|<|$)}) do |m|
|
|
477 |
leading, esc, linktitle, prefix, sep, revproj, oid = $1, $2, $3, $6 || $4, $12 || $10 || $8, $5 || $9, $11 || $13
|
|
478 |
#logger.debug "leading=#{leading},esc=#{esc},linktitle=#{linktitle},prefix=#{prefix},sep=#{sep},revproj=#{revproj},oid=#{oid}"
|
| 467 |
479 |
link = nil
|
| 468 |
480 |
if esc.nil?
|
| 469 |
481 |
if prefix.nil? && sep == 'r'
|
| 470 |
|
if project && (changeset = project.changesets.find_by_revision(oid))
|
| 471 |
|
link = link_to("r#{oid}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => oid},
|
| 472 |
|
:class => 'changeset',
|
| 473 |
|
:title => truncate_single_line(changeset.comments, :length => 100))
|
|
482 |
if revproj.nil?
|
|
483 |
if project && (changeset = project.changesets.find_by_revision(oid))
|
|
484 |
link = link_to("r#{oid}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => oid},
|
|
485 |
:class => 'changeset',
|
|
486 |
:title => truncate_single_line(changeset.comments, :length => 100))
|
|
487 |
end
|
|
488 |
else
|
|
489 |
revproj.gsub!(/[\:"]/,'')
|
|
490 |
link_project = Project.find_by_name(h(revproj)) || Project.find_by_identifier(h(revproj))
|
|
491 |
if link_project && (changeset = link_project.changesets.find_by_revision(oid))
|
|
492 |
title = truncate_single_line(changeset.comments, :length => 100) if authorize_for('repositories', 'revision', link_project)
|
|
493 |
link = link_to h("#{revproj}:r#{oid}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => link_project, :rev => oid},
|
|
494 |
:class => 'changeset',
|
|
495 |
:title => title
|
|
496 |
end
|
| 474 |
497 |
end
|
| 475 |
498 |
elsif sep == '#'
|
| 476 |
499 |
oid = oid.to_i
|
| ... | ... | |
| 518 |
541 |
:class => 'version'
|
| 519 |
542 |
end
|
| 520 |
543 |
when 'commit'
|
| 521 |
|
if project && (changeset = project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"]))
|
| 522 |
|
link = link_to h("#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision},
|
| 523 |
|
:class => 'changeset',
|
| 524 |
|
:title => truncate_single_line(changeset.comments, :length => 100)
|
|
544 |
if revproj.nil?
|
|
545 |
if project && (changeset = project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"]))
|
|
546 |
link = link_to h("#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision},
|
|
547 |
:class => 'changeset',
|
|
548 |
:title => truncate_single_line(changeset.comments, :length => 100)
|
|
549 |
end
|
|
550 |
else
|
|
551 |
revproj.gsub!(/[\:"]/,'')
|
|
552 |
link_project = Project.find_by_name(h(revproj)) || Project.find_by_identifier(h(revproj))
|
|
553 |
if link_project && (changeset = link_project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"]))
|
|
554 |
title = truncate_single_line(changeset.comments, :length => 100) if authorize_for('repositories', 'revision', link_project)
|
|
555 |
link = link_to h("#{revproj}:#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => link_project, :rev => changeset.revision},
|
|
556 |
:class => 'changeset',
|
|
557 |
:title => title
|
|
558 |
end
|
| 525 |
559 |
end
|
| 526 |
560 |
when 'source', 'export'
|
| 527 |
|
if project && project.repository
|
|
561 |
if revproj.nil?
|
|
562 |
link_project = project
|
|
563 |
else
|
|
564 |
revproj.gsub!(/[\:"]/,'')
|
|
565 |
link_project = Project.find_by_name(h(revproj)) || Project.find_by_identifier(h(revproj))
|
|
566 |
end
|
|
567 |
if link_project && link_project.repository
|
| 528 |
568 |
name =~ %r{^[/\\]*(.*?)(@([0-9a-f]+))?(#(L\d+))?$}
|
| 529 |
569 |
path, rev, anchor = $1, $3, $5
|
| 530 |
|
link = link_to h("#{prefix}:#{name}"), {:controller => 'repositories', :action => 'entry', :id => project,
|
|
570 |
link_title = linktitle ? linktitle.gsub!(/[\"=]/,'') : (link_project != project ? "#{revproj}:" : "") + "#{prefix}:#{name}"
|
|
571 |
link = link_to h(link_title), {:only_path => only_path, :controller => 'repositories', :action => 'entry', :id => link_project,
|
| 531 |
572 |
:path => to_path_param(path),
|
| 532 |
573 |
:rev => rev,
|
| 533 |
574 |
:anchor => anchor,
|
| ... | ... | |
| 542 |
583 |
end
|
| 543 |
584 |
end
|
| 544 |
585 |
end
|
| 545 |
|
leading + (link || "#{prefix}#{sep}#{oid}")
|
|
586 |
leading + (link || (revproj ? "#{revproj}:" : "") + "#{prefix}#{sep}#{oid}")
|
| 546 |
587 |
end
|
| 547 |
588 |
|
| 548 |
589 |
text
|