X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/cebda5ffb9bc45171ddc6b4c4a25f14912fdad51..HEAD:/app/helpers/browse_tags_helper.rb?ds=inline diff --git a/app/helpers/browse_tags_helper.rb b/app/helpers/browse_tags_helper.rb index 014b8262d..722b0425d 100644 --- a/app/helpers/browse_tags_helper.rb +++ b/app/helpers/browse_tags_helper.rb @@ -1,7 +1,7 @@ module BrowseTagsHelper # https://wiki.openstreetmap.org/wiki/Key:wikipedia#Secondary_Wikipedia_links # https://wiki.openstreetmap.org/wiki/Key:wikidata#Secondary_Wikidata_links - SECONDARY_WIKI_PREFIXES = "architect|artist|brand|flag|genus|name:etymology|network|operator|species|subject".freeze + SECONDARY_WIKI_PREFIXES = "architect|artist|brand|buried|flag|genus|manufacturer|model|name:etymology|network|operator|species|subject".freeze def format_key(key) if url = wiki_link("key", key) @@ -34,9 +34,13 @@ module BrowseTagsHelper end safe_join(phones, "; ") elsif colour_value = colour_preview(key, value) - tag.span("", :class => "colour-preview-box float-end m-1 border border-dark border-opacity-10", :"data-colour" => colour_value, :title => t("browse.tag_details.colour_preview", :colour_value => colour_value)) + colour_value + svg = tag.svg :width => 14, :height => 14, :class => "float-end m-1" do + concat tag.title t("browse.tag_details.colour_preview", :colour_value => colour_value) + concat tag.rect :x => 0.5, :y => 0.5, :width => 13, :height => 13, :fill => colour_value, :stroke => "#2222" + end + svg + colour_value else - safe_join(value.split(";").map { |x| linkify(h(x)) }, ";") + safe_join(value.split(";", -1).map { |x| linkify(h(x)) }, ";") end end @@ -65,38 +69,35 @@ module BrowseTagsHelper case key when "wikipedia", /^(#{SECONDARY_WIKI_PREFIXES}):wikipedia/o - # This regex should match Wikipedia language codes, everything - # from de to zh-classical - lang = if value =~ /^([a-z-]{2,12}):(.+)$/i - # Value is : so split it up - # Note that value is always left as-is, see: https://trac.openstreetmap.org/ticket/4315 - Regexp.last_match(1) - else - # Value is <title> so default to English Wikipedia - "en" - end + lang = "en" when /^wikipedia:(\S+)$/ - # Language is in the key, so assume value is the title lang = Regexp.last_match(1) else - # Not a wikipedia key! return nil end - if value =~ /^([^#]*)#(.*)/ + # This regex should match Wikipedia language codes, everything + # from de to zh-classical + if value =~ /^([a-z-]{2,12}):(.+)$/i + lang = Regexp.last_match(1) + title_section = Regexp.last_match(2) + else + title_section = value + end + + if title_section =~ /^([^#]*)#(.*)/ # Contains a reference to a section of the wikipedia article # Must break it up to correctly build the url - value = Regexp.last_match(1) - section = "##{Regexp.last_match(2)}" + title = Regexp.last_match(1) encoded_section = "##{CGI.escape(Regexp.last_match(2).gsub(/ +/, '_'))}" else - section = "" + title = title_section encoded_section = "" end { - :url => "https://#{lang}.wikipedia.org/wiki/#{value}?uselang=#{I18n.locale}#{encoded_section}", - :title => value + section + :url => "https://#{lang}.wikipedia.org/wiki/#{title}?uselang=#{I18n.locale}#{encoded_section}", + :title => value } end