Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update browse_helper.rb #814

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions app/helpers/browse_helper.rb
Expand Up @@ -117,7 +117,8 @@ def wikipedia_link(key, value)
# Some k/v's are wikipedia=http://en.wikipedia.org/wiki/Full%20URL
return nil if value =~ /^https?:\/\//

if key == "wikipedia"
# match wikipedia or xxxxx:wikipedia
if key =~ /^(?:.*:)*wikipedia$/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here (and on line 158 as well), would it be more efficient to use the String end_with() method? Not tested

# This regex should match Wikipedia language codes, everything
# from de to zh-classical
if value =~ /^([a-z-]{2,12}):(.+)$/i
Expand All @@ -128,7 +129,8 @@ def wikipedia_link(key, value)
# Value is <title> so default to English Wikipedia
lang = 'en'
end
elsif key =~ /^wikipedia:(\S+)$/
# match wikipedia:yy or xxxxx:wikipedia:yy
elsif key =~ /^(?:.*:)*wikipedia:(\S+)$/
# Language is in the key, so assume value is the title
lang = $1
else
Expand All @@ -151,8 +153,9 @@ def wikipedia_link(key, value)
}
end

# match wikidata or xxxx:wikidata
def wikidata_link(key, value)
if key == "wikidata" and value =~ /^[Qq][1-9][0-9]*$/
if key =~ /^(?:.*:)*wikidata$/ and value =~ /^[Qq][1-9][0-9]*$/
return {
:url => "//www.wikidata.org/wiki/#{value}?uselang=#{I18n.locale}",
:title => value
Expand Down