+require "uri"
+
module BrowseHelper
def printable_name(object, version = false)
if object.id.is_a?(Array)
return nil
end
- if value =~ /^([^#]*)(#.*)/
+ if value =~ /^([^#]*)#(.*)/
# Contains a reference to a section of the wikipedia article
# Must break it up to correctly build the url
value = $1
- section = $2
+ section = "#" + $2
+ encoded_section = "#" + URI.encode($2.gsub(" ", "_")).gsub("%3A", ":").gsub("%", ".")
else
section = ""
+ encoded_section = ""
end
{
- :url => "http://#{lang}.wikipedia.org/wiki/#{value}?uselang=#{I18n.locale}#{section}",
+ :url => "http://#{lang}.wikipedia.org/wiki/#{value}?uselang=#{I18n.locale}#{encoded_section}",
:title => value + section
}
end
assert_equal "http://fr.wikipedia.org/wiki/de:Test?uselang=en", link[:url]
assert_equal "de:Test", link[:title]
+ link = wikipedia_link("wikipedia", "de:Englischer Garten (München)#Japanisches Teehaus")
+ assert_equal "http://de.wikipedia.org/wiki/de:Englischer Garten (München)?uselang=en#Japanisches_Teehaus", link[:url]
+ assert_equal "de:Englischer Garten (München)#Japanisches Teehaus", link[:title]
+
+ link = wikipedia_link("wikipedia", "de:Alte Brücke (Heidelberg)#Brückenaffe")
+ assert_equal "http://de.wikipedia.org/wiki/de:Alte Brücke (Heidelberg)?uselang=en#Br.C3.BCckenaffe", link[:url]
+ assert_equal "de:Alte Brücke (Heidelberg)#Brückenaffe", link[:title]
+
I18n.locale = "pt-BR"
link = wikipedia_link("wikipedia", "zh-classical:Test#Section")