4 def printable_name(object, version = false)
5 if object.id.is_a?(Array)
10 name = t "printable_name.with_id", :id => id.to_s
12 name = t "printable_name.with_version", :id => name, :version => object.version.to_s
15 # don't look at object tags if redacted, so as to avoid giving
16 # away redacted version tag information.
17 unless object.redacted?
18 locale = I18n.locale.to_s
20 while locale =~ /-[^-]+/ && !object.tags.include?("name:#{I18n.locale}")
21 locale = locale.sub(/-[^-]+/, "")
24 if object.tags.include? "name:#{locale}"
25 name = t "printable_name.with_name_html", :name => content_tag(:bdi, object.tags["name:#{locale}"].to_s), :id => content_tag(:bdi, name)
26 elsif object.tags.include? "name"
27 name = t "printable_name.with_name_html", :name => content_tag(:bdi, object.tags["name"].to_s), :id => content_tag(:bdi, name)
34 def link_class(type, object)
40 classes += icon_tags(object).flatten.map { |t| h(t) }
41 classes << "deleted" unless object.visible?
47 def link_title(object)
51 h(icon_tags(object).map { |k, v| k + "=" + v }.to_sentence)
56 if url = wiki_link("key", key)
57 link_to h(key), url, :title => t("browse.tag_details.wiki_link.key", :key => key)
63 def format_value(key, value)
64 if wp = wikipedia_link(key, value)
65 link_to h(wp[:title]), wp[:url], :title => t("browse.tag_details.wikipedia_link", :page => wp[:title])
66 elsif wdt = wikidata_link(key, value)
67 link_to h(wdt[:title]), wdt[:url], :title => t("browse.tag_details.wikidata_link", :page => wdt[:title])
68 elsif url = wiki_link("tag", "#{key}=#{value}")
69 link_to h(value), url, :title => t("browse.tag_details.wiki_link.tag", :key => key, :value => value)
70 elsif url = telephone_link(key, value)
71 link_to h(value), url, :title => t("browse.tag_details.telephone_link", :phone_number => value)
77 def type_and_paginated_count(type, pages)
78 if pages.page_count == 1
79 t "browse.changeset.#{type}",
80 :count => pages.item_count
82 t "browse.changeset.#{type}_paginated",
83 :x => pages.current_page.first_item,
84 :y => pages.current_page.last_item,
85 :count => pages.item_count
91 ICON_TAGS = %w(aeroway amenity barrier building highway historic landuse leisure man_made natural railway shop tourism waterway)
94 object.tags.find_all { |k, _v| ICON_TAGS.include? k }.sort
97 def wiki_link(type, lookup)
98 locale = I18n.locale.to_s
100 # update-wiki-pages does s/ /_/g on keys before saving them, we
101 # have to replace spaces with underscore so we'll link
102 # e.g. `source=Isle of Man Government aerial imagery (2001)' to
104 lookup_us = lookup.tr(" ", "_")
106 if page = WIKI_PAGES[locale][type][lookup_us] rescue nil
107 url = "http://wiki.openstreetmap.org/wiki/#{page}?uselang=#{locale}"
108 elsif page = WIKI_PAGES["en"][type][lookup_us] rescue nil
109 url = "http://wiki.openstreetmap.org/wiki/#{page}?uselang=#{locale}"
115 def wikipedia_link(key, value)
116 # Some k/v's are wikipedia=http://en.wikipedia.org/wiki/Full%20URL
117 return nil if value =~ %r{^https?://}
119 if key == "wikipedia"
120 # This regex should match Wikipedia language codes, everything
121 # from de to zh-classical
122 if value =~ /^([a-z-]{2,12}):(.+)$/i
123 # Value is <lang>:<title> so split it up
124 # Note that value is always left as-is, see: https://trac.openstreetmap.org/ticket/4315
127 # Value is <title> so default to English Wikipedia
130 elsif key =~ /^wikipedia:(\S+)$/
131 # Language is in the key, so assume value is the title
134 # Not a wikipedia key!
138 if value =~ /^([^#]*)#(.*)/
139 # Contains a reference to a section of the wikipedia article
140 # Must break it up to correctly build the url
143 encoded_section = "#" + URI.encode($2.gsub(/ +/, "_"), /[^A-Za-z0-9:_]/).tr("%", ".")
150 :url => "http://#{lang}.wikipedia.org/wiki/#{value}?uselang=#{I18n.locale}#{encoded_section}",
151 :title => value + section
155 def wikidata_link(key, value)
156 if key == "wikidata" && value =~ /^[Qq][1-9][0-9]*$/
158 :url => "//www.wikidata.org/wiki/#{value}?uselang=#{I18n.locale}",
165 def telephone_link(_key, value)
166 # does it look like a phone number? eg "+1 (234) 567-8901 " ?
167 return nil unless value =~ %r{^\s*\+[\d\s\(\)/\.-]{6,25}\s*$}
169 # remove all whitespace instead of encoding it http://tools.ietf.org/html/rfc3966#section-5.1.1
170 # "+1 (234) 567-8901 " -> "+1(234)567-8901"
171 value_no_whitespace = value.gsub(/\s+/, "")
173 "tel:#{value_no_whitespace}"