Feature #6188 » 01_version_in_parse_wiki_links.diff
| app/helpers/application_helper.rb | ||
|---|---|---|
|
if page =~ /^(.+?)\#(.+)$/
|
||
|
page, anchor = $1, $2
|
||
|
end
|
||
|
# extract version
|
||
|
version = nil
|
||
|
if anchor.present?
|
||
|
if anchor =~ /^(.+?)\@(\d+)$/
|
||
|
anchor, version = $1, $2
|
||
|
end
|
||
|
else
|
||
|
if page =~ /^(.+?)\@(\d+)$/
|
||
|
page, version = $1, $2
|
||
|
end
|
||
|
end
|
||
|
version = version.to_i if version.present?
|
||
|
anchor = sanitize_anchor_name(anchor) if anchor.present?
|
||
|
# check if page exists
|
||
|
wiki_page = link_project.wiki.find_page(page)
|
||
|
url = if anchor.present? && wiki_page.present? && (obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version)) && obj.page == wiki_page
|
||
|
url = if anchor.present? && wiki_page.present? && (obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version)) && obj.page == wiki_page && (version.nil? || obj.version == version)
|
||
|
"##{anchor}"
|
||
|
else
|
||
|
case options[:wiki_links]
|
||
|
when :local; "#{page.present? ? Wiki.titleize(page) : ''}.html" + (anchor.present? ? "##{anchor}" : '')
|
||
|
when :local; "#{page.present? ? Wiki.titleize(page) : ''}.html" + (version.present? ? "?version=#{version}" : '') + (anchor.present? ? "##{anchor}" : '')
|
||
|
when :anchor; "##{page.present? ? Wiki.titleize(page) : title}" + (anchor.present? ? "_#{anchor}" : '') # used for single-file wiki export
|
||
|
else
|
||
|
wiki_page_id = page.present? ? Wiki.titleize(page) : nil
|
||
|
parent = wiki_page.nil? && obj.is_a?(WikiContent) && obj.page && project == link_project ? obj.page.title : nil
|
||
|
url_for(:only_path => only_path, :controller => 'wiki', :action => 'show', :project_id => link_project,
|
||
|
:id => wiki_page_id, :anchor => anchor, :parent => parent)
|
||
|
url_for(:only_path => only_path, :controller => 'wiki', :action => 'show', :project_id => link_project,
|
||
|
:id => wiki_page_id, :anchor => anchor, :parent => parent, :version => version)
|
||
|
end
|
||
|
end
|
||
|
link_to(title.present? ? title.html_safe : h(page), url, :class => ('wiki-page' + (wiki_page ? '' : ' new')))
|
||