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 if object.tags.include? "name:#{I18n.locale}"
17 name = t 'printable_name.with_name', :name => object.tags["name:#{I18n.locale}"].to_s, :id => name
18 elsif object.tags.include? 'name'
19 name = t 'printable_name.with_name', :name => object.tags['name'].to_s, :id => name
26 def link_class(type, object)
32 classes += icon_tags(object).flatten.map { |t| h(t) }
33 classes << "deleted" unless object.visible?
39 def link_title(object)
43 h(icon_tags(object).map { |k,v| k + '=' + v }.to_sentence)
48 if url = wiki_link("key", key)
49 link_to h(key), url, :title => t('browse.tag_details.wiki_link.key', :key => key)
55 def format_value(key, value)
56 if wp = wikipedia_link(key, value)
57 link_to h(wp[:title]), wp[:url], :title => t('browse.tag_details.wikipedia_link', :page => wp[:title])
58 elsif url = wiki_link("tag", "#{key}=#{value}")
59 link_to h(value), url, :title => t('browse.tag_details.wiki_link.tag', :key => key, :value => value)
65 def type_and_paginated_count(type, pages)
66 if pages.page_count == 1
67 t "browse.changeset.#{type}",
68 :count => pages.item_count
70 t "browse.changeset.#{type}_paginated",
71 :x => pages.current_page.first_item,
72 :y => pages.current_page.last_item,
73 :count => pages.item_count
80 "aeroway", "amenity", "barrier", "building", "highway", "historic", "landuse",
81 "leisure", "man_made", "natural", "railway", "shop", "tourism", "waterway"
85 object.tags.find_all { |k,v| ICON_TAGS.include? k }
88 def wiki_link(type, lookup)
89 locale = I18n.locale.to_s
91 # update-wiki-pages does s/ /_/g on keys before saving them, we
92 # have to replace spaces with underscore so we'll link
93 # e.g. `source=Isle of Man Government aerial imagery (2001)' to
95 lookup_us = lookup.tr(" ", "_")
97 if page = WIKI_PAGES[locale][type][lookup_us] rescue nil
98 url = "http://wiki.openstreetmap.org/wiki/#{page}?uselang=#{locale}"
99 elsif page = WIKI_PAGES["en"][type][lookup_us] rescue nil
100 url = "http://wiki.openstreetmap.org/wiki/#{page}?uselang=#{locale}"
106 def wikipedia_link(key, value)
107 # Some k/v's are wikipedia=http://en.wikipedia.org/wiki/Full%20URL
108 return nil if value =~ /^https?:\/\//
110 if key == "wikipedia"
111 # This regex should match Wikipedia language codes, everything
112 # from de to zh-classical
113 if value =~ /^([a-z-]{2,12}):(.+)$/i
114 # Value is <lang>:<title> so split it up
115 # Note that value is always left as-is, see: https://trac.openstreetmap.org/ticket/4315
118 # Value is <title> so default to English Wikipedia
121 elsif key =~ /^wikipedia:(\S+)$/
122 # Language is in the key, so assume value is the title
125 # Not a wikipedia key!
129 if value =~ /^([^#]*)(#.*)/ then
130 # Contains a reference to a section of the wikipedia article
131 # Must break it up to correctly build the url
139 :url => "http://#{lang}.wikipedia.org/wiki/#{value}?uselang=#{I18n.locale}#{section}",
140 :title => value + section