[Mediawiki-api] Does wikipedia use different methods to compute the hash part of an image path?

Tommy Chheng tommy.chheng at gmail.com
Mon Dec 5 23:25:42 UTC 2011


I'm computing the url of an image by the following:
(the md5 of the first char and the second two chars concat)

   val md = MessageDigest.getInstance("MD5")
   val messageDigest = md.digest(fileName.getBytes)
   val md5 = (new BigInteger(1, messageDigest)).toString(16)

   val hash1 = md5.substring(0, 1)
   val hash2 = md5.substring(0, 2)

   val urlPart = hash1 + "/" + hash2 + "/" + fileName

Most of the time, the function works correctly but on a few cases, it
is incorrect:

For "Stewie_Griffin.png", I get 2/26/Stewie_Griffin.png but the real
one is 0/02/Stewie_Griffin.png

The source file info is here:
http://en.wikipedia.org/wiki/File:Stewie_Griffin.png
http://upload.wikimedia.org/wikipedia/en/0/02/Stewie_Griffin.png

Any ideas why the hashing scheme doesn't work sometimes?

I posted this question on stackoverflow but I might be able to get a
better answer here.http://stackoverflow.com/questions/8389616/does-wikipedia-use-different-methods-to-compute-the-hash-part-of-an-image-path

-- 
@tommychheng
http://tommy.chheng.com



More information about the Mediawiki-api mailing list