Changeset 17736 in josm
- Timestamp:
- 2021-04-09T23:18:01+02:00 (4 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/Tag2Link.java
r17735 r17736 27 27 import javax.json.JsonValue; 28 28 29 import com.google.gdata.util.common.base.PercentEscaper; 29 30 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 30 31 import org.openstreetmap.josm.data.osm.OsmUtils; … … 202 203 if (key.matches("wikimedia_commons|image") && value.matches("(?i:File):.*")) { 203 204 OsmUtils.splitMultipleValues(value).forEach(i -> linkConsumer.acceptLink( 204 tr("View image on Wikimedia Commons"), "https://commons.wikimedia.org/wiki/" + i, imageResource.get()));205 tr("View image on Wikimedia Commons"), getWikimediaCommonsUrl(i), imageResource.get())); 205 206 } 206 207 if (key.matches("wikimedia_commons|image") && value.matches("(?i:Category):.*")) { 207 208 OsmUtils.splitMultipleValues(value).forEach(i -> linkConsumer.acceptLink( 208 tr("View category on Wikimedia Commons"), "https://commons.wikimedia.org/wiki/" + i, imageResource.get()));209 tr("View category on Wikimedia Commons"), getWikimediaCommonsUrl(i), imageResource.get())); 209 210 } 210 211 … … 216 217 } 217 218 219 private static String getWikimediaCommonsUrl(String i) { 220 return "https://commons.wikimedia.org/wiki/" + new PercentEscaper(PercentEscaper.SAFEPATHCHARS_URLENCODER, false).escape(i); 221 } 222 218 223 private static String getLinkName(String url, String fallback) { 219 224 return tr("Open {0}", getHost(url, fallback)); -
trunk/test/unit/org/openstreetmap/josm/tools/Tag2LinkTest.java
r17735 r17736 87 87 void testImageCommonsImage() { 88 88 Tag2Link.getLinksForTag("image", "File:Witten Brücke Gasstraße.jpg", this::addLink); 89 checkLinks("View image on Wikimedia Commons // https://commons.wikimedia.org/wiki/File:Witten Brücke Gasstraße.jpg");89 checkLinks("View image on Wikimedia Commons // https://commons.wikimedia.org/wiki/File:Witten%20Br%C3%BCcke%20Gasstra%C3%9Fe.jpg"); 90 90 links.clear(); 91 91 // non-regression test for #19754 … … 93 93 checkLinks("View image on Wikimedia Commons // https://commons.wikimedia.org/wiki/File:Foo.jpg", 94 94 "View image on Wikimedia Commons // https://commons.wikimedia.org/wiki/File:Bar.jpg"); 95 links.clear(); 96 // non-regression test for #19771 97 Tag2Link.getLinksForTag("image", "File:Côte de granite rose - Trégastel à Ploumanac'h - 20190723 - 025.jpg", this::addLink); 98 checkLinks("View image on Wikimedia Commons // " + 99 "https://commons.wikimedia.org/wiki/" + 100 "File:C%C3%B4te%20de%20granite%20rose%20-%20Tr%C3%A9gastel%20%C3%A0%20Ploumanac'h%20-%2020190723%20-%20025.jpg"); 95 101 } 96 102
Note:
See TracChangeset
for help on using the changeset viewer.