2 def printable_name(object, version=false)
3 if object.id.is_a?(Array)
8 name = t 'printable_name.with_id', :id => id.to_s
10 name = t 'printable_name.with_version', :id => name, :version => object.version.to_s
13 # don't look at object tags if redacted, so as to avoid giving
14 # away redacted version tag information.
15 unless object.redacted?
16 locale = I18n.locale.to_s
18 while locale =~ /-[^-]+/ and not object.tags.include? "name:#{I18n.locale}"
19 locale = locale.sub(/-[^-]+/, "")
22 if object.tags.include? "name:#{locale}"
23 name = t 'printable_name.with_name_html', :name => content_tag(:bdi, object.tags["name:#{locale}"].to_s ), :id => content_tag(:bdi, name)
24 elsif object.tags.include? 'name'
25 name = t 'printable_name.with_name_html', :name => content_tag(:bdi, object.tags['name'].to_s ), :id => content_tag(:bdi, name)
32 def link_class(type, object)
38 classes += icon_tags(object).flatten.map { |t| h(t) }
39 classes << "deleted" unless object.visible?
45 def link_title(object)
49 h(icon_tags(object).map { |k,v| k + '=' + v }.to_sentence)
54 if url = wiki_link("key", key)
55 link_to h(key), url, :title => t('browse.tag_details.wiki_link.key', :key => key)
61 def format_value(key, value)
62 if wp = wikipedia_link(key, value)
63 link_to h(wp[:title]), wp[:url], :title => t('browse.tag_details.wikipedia_link', :page => wp[:title])
64 elsif wdt = wikidata_link(key, value)
65 link_to h(wdt[:title]), wdt[:url], :title => t('browse.tag_details.wikidata_link', :page => wdt[:title])
66 elsif url = wiki_link("tag", "#{key}=#{value}")
67 link_to h(value), url, :title => t('browse.tag_details.wiki_link.tag', :key => key, :value => value)
68 elsif url = telephone_link(key, value)
69 link_to h(value), url, :title => t('browse.tag_details.telephone_link', :phone_number => value)
75 def type_and_paginated_count(type, pages)
76 if pages.page_count == 1
77 t "browse.changeset.#{type}",
78 :count => pages.item_count
80 t "browse.changeset.#{type}_paginated",
81 :x => pages.current_page.first_item,
82 :y => pages.current_page.last_item,
83 :count => pages.item_count
90 "aeroway", "amenity", "barrier", "building", "highway", "historic", "landuse",
91 "leisure", "man_made", "natural", "railway", "shop", "tourism", "waterway"
95 object.tags.find_all { |k,v| ICON_TAGS.include? k }
98 def wiki_link(type, lookup)
99 locale = I18n.locale.to_s
101 # update-wiki-pages does s/ /_/g on keys before saving them, we
102 # have to replace spaces with underscore so we'll link
103 # e.g. `source=Isle of Man Government aerial imagery (2001)' to
105 lookup_us = lookup.tr(" ", "_")
107 if page = WIKI_PAGES[locale][type][lookup_us] rescue nil
108 url = "http://wiki.openstreetmap.org/wiki/#{page}?uselang=#{locale}"
109 elsif page = WIKI_PAGES["en"][type][lookup_us] rescue nil
110 url = "http://wiki.openstreetmap.org/wiki/#{page}?uselang=#{locale}"
116 def wikipedia_link(key, value)
117 # Some k/v's are wikipedia=http://en.wikipedia.org/wiki/Full%20URL
118 return nil if value =~ /^https?:\/\//
120 if key == "wikipedia"
121 # This regex should match Wikipedia language codes, everything
122 # from de to zh-classical
123 if value =~ /^([a-z-]{2,12}):(.+)$/i
124 # Value is <lang>:<title> so split it up
125 # Note that value is always left as-is, see: https://trac.openstreetmap.org/ticket/4315
128 # Value is <title> so default to English Wikipedia
131 elsif key =~ /^wikipedia:(\S+)$/
132 # Language is in the key, so assume value is the title
135 # Not a wikipedia key!
139 if value =~ /^([^#]*)(#.*)/ then
140 # Contains a reference to a section of the wikipedia article
141 # Must break it up to correctly build the url
149 :url => "http://#{lang}.wikipedia.org/wiki/#{value}?uselang=#{I18n.locale}#{section}",
150 :title => value + section
154 def wikidata_link(key, value)
155 if key == "wikidata" and value =~ /^[Qq][1-9][0-9]*$/
157 :url => "//www.wikidata.org/wiki/#{value}?uselang=#{I18n.locale}",
164 def telephone_link(key, value)
165 # does it look like a phone number? eg "+1 (234) 567-8901 " ?
166 return nil unless value =~ /^\s*\+[\d\s\(\)\/\.-]{6,25}\s*$/
168 # remove all whitespace instead of encoding it http://tools.ietf.org/html/rfc3966#section-5.1.1
169 # "+1 (234) 567-8901 " -> "+1(234)567-8901"
170 valueNoWhitespace = value.gsub(/\s+/, '')
172 return "tel:#{valueNoWhitespace}"