end
def wikimedia_commons_link(key, value)
- if key == "wikimedia_commons" && value =~ /^(?:file|category):/i
+ if key == "wikimedia_commons" && value =~ /^(file|category):(.+)$/i
+ namespace = Regexp.last_match(1)
+ title = Regexp.last_match(2)
return {
- :url => "//commons.wikimedia.org/wiki/#{value}?uselang=#{I18n.locale}",
+ :url => "//commons.wikimedia.org/wiki/#{namespace}:#{u title}?uselang=#{I18n.locale}",
:title => value
}
end
assert_equal "//commons.wikimedia.org/wiki/Category:Test_Category?uselang=en", link[:url]
assert_equal "Category:Test_Category", link[:title]
+ link = wikimedia_commons_link("wikimedia_commons", "Category:What If? (Bonn)")
+ assert_equal "//commons.wikimedia.org/wiki/Category:What%20If%3F%20%28Bonn%29?uselang=en", link[:url]
+ assert_equal "Category:What If? (Bonn)", link[:title]
+
I18n.with_locale "pt-BR" do
link = wikimedia_commons_link("wikimedia_commons", "File:Test.jpg")
assert_equal "//commons.wikimedia.org/wiki/File:Test.jpg?uselang=pt-BR", link[:url]