link_to(w[:title], w[:url], :title => t("browse.tag_details.wikidata_link", :page => w[:title].strip))
end
safe_join(wdt, ";")
+ elsif wmc = wikimedia_commons_link(key, value)
+ 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 phones = telephone_links(key, value)
nil
end
+ def wikimedia_commons_link(key, value)
+ if key == "wikimedia_commons" && value =~ /^(?:file|category):/i
+ return {
+ :url => "//commons.wikimedia.org/wiki/#{value}?uselang=#{I18n.locale}",
+ :title => value
+ }
+ end
+ nil
+ end
+
def telephone_links(_key, value)
# Does it look like a global phone number? eg "+1 (234) 567-8901 "
# or a list of alternate numbers separated by ;
tag: "The wiki description page for the %{key}=%{value} tag"
wikidata_link: "The %{page} item on Wikidata"
wikipedia_link: "The %{page} article on Wikipedia"
+ wikimedia_commons_link: "The %{page} item on Wikimedia Commons"
telephone_link: "Call %{phone_number}"
colour_preview: "Colour %{colour_value} preview"
note:
html = format_value("name:etymology:wikidata", "Q123")
assert_dom_equal "<a title=\"The Q123 item on Wikidata\" href=\"//www.wikidata.org/entity/Q123?uselang=en\">Q123</a>", html
+ html = format_value("wikimedia_commons", "File:Test.jpg")
+ assert_dom_equal "<a title=\"The File:Test.jpg item on Wikimedia Commons\" href=\"//commons.wikimedia.org/wiki/File:Test.jpg?uselang=en\">File:Test.jpg</a>", html
+
html = format_value("colour", "#f00")
assert_dom_equal %(<span class="colour-preview-box" data-colour="#f00" title="Colour #f00 preview"></span>#f00), html
end
assert_nil link
end
+ def test_wikimedia_commons_link
+ link = wikimedia_commons_link("wikimedia_commons", "http://commons.wikimedia.org/wiki/File:Full%20URL.jpg")
+ assert_nil link
+
+ link = wikimedia_commons_link("wikimedia_commons", "https://commons.wikimedia.org/wiki/File:Full%20URL.jpg")
+ assert_nil link
+
+ link = wikimedia_commons_link("wikimedia_commons", "Test.jpg")
+ assert_nil link
+
+ link = wikimedia_commons_link("wikimedia_commons", "File:Test.jpg")
+ assert_equal "//commons.wikimedia.org/wiki/File:Test.jpg?uselang=en", link[:url]
+ assert_equal "File:Test.jpg", link[:title]
+
+ link = wikimedia_commons_link("wikimedia_commons", "Category:Test_Category")
+ assert_equal "//commons.wikimedia.org/wiki/Category:Test_Category?uselang=en", link[:url]
+ assert_equal "Category:Test_Category", link[:title]
+
+ I18n.locale = "pt-BR"
+
+ link = wikimedia_commons_link("wikimedia_commons", "File:Test.jpg")
+ assert_equal "//commons.wikimedia.org/wiki/File:Test.jpg?uselang=pt-BR", link[:url]
+ assert_equal "File:Test.jpg", link[:title]
+
+ link = wikimedia_commons_link("foo", "Test")
+ assert_nil link
+ end
+
def test_telephone_links
links = telephone_links("foo", "Test")
assert_nil links