Project

General

Profile

Feature #6188 » 01_version_in_parse_wiki_links.diff

Torsten Schönebaum, 2012-06-28 12:11

View differences:

app/helpers/application_helper.rb
622 622
          if page =~ /^(.+?)\#(.+)$/
623 623
            page, anchor = $1, $2
624 624
          end
625
          # extract version
626
          version = nil
627
          if anchor.present?
628
            if anchor =~ /^(.+?)\@(\d+)$/
629
              anchor, version = $1, $2
630
            end
631
          else
632
            if page =~ /^(.+?)\@(\d+)$/
633
              page, version = $1, $2
634
            end
635
          end
636
          version = version.to_i if version.present?
625 637
          anchor = sanitize_anchor_name(anchor) if anchor.present?
626 638
          # check if page exists
627 639
          wiki_page = link_project.wiki.find_page(page)
628
          url = if anchor.present? && wiki_page.present? && (obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version)) && obj.page == wiki_page
640
          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)
629 641
            "##{anchor}"
630 642
          else
631 643
            case options[:wiki_links]
632
            when :local; "#{page.present? ? Wiki.titleize(page) : ''}.html" + (anchor.present? ? "##{anchor}" : '')
644
            when :local; "#{page.present? ? Wiki.titleize(page) : ''}.html" + (version.present? ? "?version=#{version}" : '') + (anchor.present? ? "##{anchor}" : '')
633 645
            when :anchor; "##{page.present? ? Wiki.titleize(page) : title}" + (anchor.present? ? "_#{anchor}" : '') # used for single-file wiki export
634 646
            else
635 647
              wiki_page_id = page.present? ? Wiki.titleize(page) : nil
636 648
              parent = wiki_page.nil? && obj.is_a?(WikiContent) && obj.page && project == link_project ? obj.page.title : nil
637
              url_for(:only_path => only_path, :controller => 'wiki', :action => 'show', :project_id => link_project, 
638
               :id => wiki_page_id, :anchor => anchor, :parent => parent)
649
              url_for(:only_path => only_path, :controller => 'wiki', :action => 'show', :project_id => link_project,
650
               :id => wiki_page_id, :anchor => anchor, :parent => parent, :version => version)
639 651
            end
640 652
          end
641 653
          link_to(title.present? ? title.html_safe : h(page), url, :class => ('wiki-page' + (wiki_page ? '' : ' new')))
    (1-1/1)