X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/816ee8ec92735b5c80b382857953ac4325096a71..53817fa9e8d955df0891d156f21b7269b4ed08fc:/app/helpers/browse_tags_helper.rb diff --git a/app/helpers/browse_tags_helper.rb b/app/helpers/browse_tags_helper.rb index bbf6f3cf7..bbe4c63b1 100644 --- a/app/helpers/browse_tags_helper.rb +++ b/app/helpers/browse_tags_helper.rb @@ -1,4 +1,8 @@ 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|buried|flag|genus|name:etymology|network|operator|species|subject".freeze + def format_key(key) if url = wiki_link("key", key) link_to h(key), url, :title => t("browse.tag_details.wiki_link.key", :key => key) @@ -21,6 +25,8 @@ module BrowseTagsHelper link_to h(wmc[:title]), wmc[:url], :title => t("browse.tag_details.wikimedia_commons_link", :page => wmc[:title]) elsif url = wiki_link("tag", "#{key}=#{value}") link_to h(value), url, :title => t("browse.tag_details.wiki_link.tag", :key => key, :value => value) + elsif email = email_link(key, value) + mail_to(email, :title => t("browse.tag_details.email_link", :email => email)) elsif phones = telephone_links(key, value) # similarly, telephone_links() returns an array of phone numbers phones = phones.map do |p| @@ -28,9 +34,13 @@ module BrowseTagsHelper end safe_join(phones, "; ") elsif colour_value = colour_preview(key, value) - content_tag(:span, "", :class => "colour-preview-box", :"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 - linkify h(value) + safe_join(value.split(";", -1).map { |x| linkify(h(x)) }, ";") end end @@ -45,20 +55,20 @@ module BrowseTagsHelper # the correct page. lookup_us = lookup.tr(" ", "_") - if page = WIKI_PAGES.dig(locale, type, lookup_us) - url = "https://wiki.openstreetmap.org/wiki/#{page}?uselang=#{locale}" - elsif page = WIKI_PAGES.dig("en", type, lookup_us) - url = "https://wiki.openstreetmap.org/wiki/#{page}?uselang=#{locale}" - end + page = WIKI_PAGES.dig(locale, type, lookup_us) || + WIKI_PAGES.dig("en", type, lookup_us) + + url = "https://wiki.openstreetmap.org/wiki/#{page}?uselang=#{locale}" if page url end def wikipedia_link(key, value) # Some k/v's are wikipedia=http://en.wikipedia.org/wiki/Full%20URL - return nil if value =~ %r{^https?://} + return nil if %r{^https?://}.match?(value) - if key == "wikipedia" + 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 @@ -69,7 +79,7 @@ module BrowseTagsHelper # Value is