Page MenuHomePhabricator

ForeignApiRepo does not urldecode filenames
Closed, ResolvedPublic


patch to ForeignAPIRepo.php rev 56620 that seems to fix the issue

I run an non-Wikimedia MediaWiki on This MediaWiki installation uses commons as its image backend,
this was working properly since we setup the site.

The site was running rev502xx-something but the users complained that some images from Commons do not get displayed on the site. I have upgraded the site to 1.16alpha (r56620) but the problem remained. In the debug log one can see:

Saved preprocessor XML to memcached (key wikimania2010db:preprocess-xml:fba7984c25b803a608bd8d256bb00be0:0)
File::transform: Doing stat for /home/upload/ńsk2010.svg/600px-WikimaniaGdańsk2010.svg.png
ForeignAPIRepo::getThumbUrl got remote thumb
ForeignAPIRepo::getThumbUrlFromCache got local thumbńsk_COA.svg/400px-POL_Gda%C5%84sk_C
OA.svg.png, saving to cache

Please note that URL is full URL-encoded. But the "local thumb" URL is partially encoded: the directory path is in plain UTF-8, the file name is URL-encoded. Actually the Apache webserver requires that names will be stored in UTF-8, otherwise a 404 will be returned (if 400px-POL_Gda%C5%84sk_COA.svg.png is requested and 400px-POL_Gda%C5%84sk_COA.svg.png exists).

As of 1.16alpha-wmf (r56620), Commons returns URL-encoded thumbnail URL as a reponse to the query (examples from a different image):


{"query":{"normalized":[{"from":"Image:O\u0142owianka_Island_04.jpeg","to":"File:O\u0142owianka Island 04.jpeg"}],"pages":{"6530939":{"pageid":6530939,"ns":6
,"title":"File:O\u0142owianka Island 04.jpeg","imagerepository":"local","imageinfo":[{"thumburl":"http:\/\/\/wikipedia\/commons\/thumb\/e

However, ForeignAPIRepo->getThumbUrlFromCache just takes the last element of the filename and passes it as-is over to the filesystem. Unfortunately, any URL-encoded characters in the thumbnail URL will be used as they are in the filename.

Unfortunately I couldn't replicate this problem on Wikimedia wikis.

I don't know if the API output has changed or is this some older problem - the patch attached seems to fix the issue for me.

Version: 1.16.x
Severity: major
OS: Linux
Platform: PC