]> git.openstreetmap.org Git - rails.git/commitdiff
Merge remote-tracking branch 'upstream/pull/834'
authorTom Hughes <tom@compton.nu>
Thu, 7 Nov 2019 19:26:03 +0000 (19:26 +0000)
committerTom Hughes <tom@compton.nu>
Thu, 7 Nov 2019 19:26:03 +0000 (19:26 +0000)
.rubocop_todo.yml
app/helpers/browse_tags_helper.rb
config/locales/en.yml
test/helpers/browse_tags_helper_test.rb

index 57f876bd9cd53924d75faebf1f29c58d98002f52..518e1eda47fde8461c99941b0e88ab12c2aace70 100644 (file)
@@ -1,12 +1,12 @@
 # This configuration was generated by
 # `rubocop --auto-gen-config`
-# on 2019-10-07 20:37:25 +0100 using RuboCop version 0.75.0.
+# on 2019-10-19 16:05:52 +0000 using RuboCop version 0.75.0.
 # The point is for the user to remove these configuration records
 # one by one as the offenses are removed from the code base.
 # Note that changes in the inspected code, or installation of new
 # versions of RuboCop, may require this file to be generated again.
 
-# Offense count: 34
+# Offense count: 35
 # Configuration parameters: AllowSafeAssignment.
 Lint/AssignmentInCondition:
   Exclude:
@@ -32,7 +32,7 @@ Lint/HandleExceptions:
     - 'app/controllers/api/amf_controller.rb'
     - 'app/controllers/users_controller.rb'
 
-# Offense count: 700
+# Offense count: 701
 Metrics/AbcSize:
   Max: 189
 
@@ -52,11 +52,11 @@ Metrics/BlockNesting:
 Metrics/ClassLength:
   Max: 645
 
-# Offense count: 73
+# Offense count: 74
 Metrics/CyclomaticComplexity:
   Max: 22
 
-# Offense count: 721
+# Offense count: 722
 # Configuration parameters: CountComments, ExcludedMethods.
 Metrics/MethodLength:
   Max: 179
@@ -64,14 +64,14 @@ Metrics/MethodLength:
 # Offense count: 2
 # Configuration parameters: CountComments.
 Metrics/ModuleLength:
-  Max: 107
+  Max: 117
 
 # Offense count: 4
 # Configuration parameters: CountKeywordArgs.
 Metrics/ParameterLists:
   Max: 9
 
-# Offense count: 71
+# Offense count: 72
 Metrics/PerceivedComplexity:
   Max: 25
 
@@ -209,7 +209,7 @@ Style/IfUnlessModifier:
 Style/NumericLiterals:
   MinDigits: 11
 
-# Offense count: 3330
+# Offense count: 3338
 # Cop supports --auto-correct.
 # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
 # URISchemes: http, https
index 375300e14cb67527b0e466d0ec91b6b87bce304a..bbf6f3cf72ea6a79436a9add4df38aeed80a110e 100644 (file)
@@ -17,6 +17,8 @@ module BrowseTagsHelper
         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)
@@ -111,6 +113,16 @@ module BrowseTagsHelper
     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 ;
index 35da13709689473cc3151f7837bee623eb5cc13e..917c06a954de363ac0252424575fc8208b6fa87d 100644 (file)
@@ -278,6 +278,7 @@ en:
         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:
index 222c7c6692678af91a4a8eedfd5ba3335d039cba..a6390df38ca5bbe113f346bdb352cf99ae4c7de4 100644 (file)
@@ -48,6 +48,9 @@ class BrowseTagsHelperTest < ActionView::TestCase
     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
@@ -190,6 +193,34 @@ class BrowseTagsHelperTest < ActionView::TestCase
     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