Index: trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
===================================================================
--- trunk/src/org/openstreetmap/josm/tools/ImageProvider.java	(revision 16987)
+++ trunk/src/org/openstreetmap/josm/tools/ImageProvider.java	(revision 16988)
@@ -1085,6 +1085,5 @@
                 }
             } else {
-                final String fnMD5 = Utils.md5Hex(fn);
-                url = b + fnMD5.substring(0, 1) + '/' + fnMD5.substring(0, 2) + '/' + fn;
+                url = Mediawiki.getImageUrl(b, fn);
             }
             result = getIfAvailableHttp(url, type);
Index: trunk/src/org/openstreetmap/josm/tools/Mediawiki.java
===================================================================
--- trunk/src/org/openstreetmap/josm/tools/Mediawiki.java	(revision 16987)
+++ trunk/src/org/openstreetmap/josm/tools/Mediawiki.java	(revision 16988)
@@ -74,3 +74,15 @@
         return Optional.empty();
     }
+
+    /**
+     * Computes the URL for the given filename on the MediaWiki server
+     * @param fileBaseUrl the base URL of the file MediaWiki storage, such as {@code "https://upload.wikimedia.org/wikipedia/commons/"}
+     * @param filename    the filename
+     * @return the URL for the given filename on the MediaWiki server
+     * @see <a href="https://www.mediawiki.org/wiki/Manual:$wgHashedUploadDirectory">MediaWiki $wgHashedUploadDirectory</a>
+     */
+    public static String getImageUrl(String fileBaseUrl, String filename) {
+        final String md5 = Utils.md5Hex(filename);
+        return String.join("/", Utils.strip(fileBaseUrl, "/"), md5.substring(0, 1), md5.substring(0, 2), filename);
+    }
 }
