def format_value(key, value)
if wp = wikipedia_link(key, value)
link_to h(wp[:title]), wp[:url], :title => t('browse.tag_details.wikipedia_link', :page => wp[:title])
+ elsif wdt = wikidata_link(key, value)
+ link_to h(wdt[:title]), wdt[:url], :title => t('browse.tag_details.wikidata_link', :page => wdt[: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 url = telephone_link(key, value)
]
def icon_tags(object)
- object.tags.find_all { |k,v| ICON_TAGS.include? k }
+ object.tags.find_all { |k,v| ICON_TAGS.include? k }.sort
end
def wiki_link(type, lookup)
}
end
+ def wikidata_link(key, value)
+ if key == "wikidata" and value =~ /^[Qq][1-9][0-9]*$/
+ return {
+ :url => "//www.wikidata.org/wiki/#{value}?uselang=#{I18n.locale}",
+ :title => value
+ }
+ end
+ return nil
+ end
+
def telephone_link(key, value)
# does it look like a phone number? eg "+1 (234) 567-8901 " ?
return nil unless value =~ /^\s*\+[\d\s\(\)\/\.-]{6,25}\s*$/
I18n.locale = "en"
end
+ def teardown
+ I18n.locale = "en"
+ end
+
def test_printable_name
assert_equal "17", printable_name(current_nodes(:redacted_node))
assert_equal "<bdi>Test Node</bdi> (<bdi>18</bdi>)", printable_name(current_nodes(:node_with_name))
assert_equal "http://wiki.openstreetmap.org/wiki/Tag:highway=primary?uselang=tr", link
end
+ def test_wikidata_link
+ link = wikidata_link("foo", "Test")
+ assert_nil link
+
+ link = wikidata_link("wikidata", "http://www.wikidata.org/wiki/Q1")
+ assert_nil link
+
+ link = wikidata_link("wikidata", "en:Q1")
+ assert_nil link
+
+ link = wikidata_link("wikidata", "1")
+ assert_nil link
+
+ link = wikidata_link("wikidata", "Q0123")
+ assert_nil link
+
+ link = wikidata_link("wikidata", "Q42")
+ assert_equal "//www.wikidata.org/wiki/Q42?uselang=en", link[:url]
+ assert_equal "Q42", link[:title]
+
+ I18n.locale = "zh-CN"
+
+ link = wikidata_link("wikidata", "Q1234")
+ assert_equal "//www.wikidata.org/wiki/Q1234?uselang=zh-CN", link[:url]
+ assert_equal "Q1234", link[:title]
+ end
+
def test_wikipedia_link
link = wikipedia_link("wikipedia", "http://en.wikipedia.org/wiki/Full%20URL")
assert_nil link