Changeset 16988 in josm


Ignore:
Timestamp:
2020-08-30T23:20:05+02:00 (3 weeks ago)
Author:
simon04
Message:

Extract and test Mediawiki.getImageUrl

Location:
trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/ImageProvider.java

    r16984 r16988  
    10851085                }
    10861086            } else {
    1087                 final String fnMD5 = Utils.md5Hex(fn);
    1088                 url = b + fnMD5.substring(0, 1) + '/' + fnMD5.substring(0, 2) + '/' + fn;
     1087                url = Mediawiki.getImageUrl(b, fn);
    10891088            }
    10901089            result = getIfAvailableHttp(url, type);
  • trunk/src/org/openstreetmap/josm/tools/Mediawiki.java

    r15261 r16988  
    7474        return Optional.empty();
    7575    }
     76
     77    /**
     78     * Computes the URL for the given filename on the MediaWiki server
     79     * @param fileBaseUrl the base URL of the file MediaWiki storage, such as {@code "https://upload.wikimedia.org/wikipedia/commons/"}
     80     * @param filename    the filename
     81     * @return the URL for the given filename on the MediaWiki server
     82     * @see <a href="https://www.mediawiki.org/wiki/Manual:$wgHashedUploadDirectory">MediaWiki $wgHashedUploadDirectory</a>
     83     */
     84    public static String getImageUrl(String fileBaseUrl, String filename) {
     85        final String md5 = Utils.md5Hex(filename);
     86        return String.join("/", Utils.strip(fileBaseUrl, "/"), md5.substring(0, 1), md5.substring(0, 2), filename);
     87    }
    7688}
Note: See TracChangeset for help on using the changeset viewer.