Page MenuHomePhabricator

ForeignApiRepo does not urldecode filenames
Closed, ResolvedPublic

Description

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

I run an non-Wikimedia MediaWiki on www.wikimania2010.pl. 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/www.wikimania2010.pl/thumb/5/52/WikimaniaGdańsk2010.svg/600px-WikimaniaGdańsk2010.svg.png
ForeignAPIRepo::getThumbUrl got remote thumb http://upload.wikimedia.org/wikipedia/commons/thumb/9/91/POL_Gda%C5%84sk_COA.svg/400px-POL_Gda%C5%84sk_COA.svg.p
ng
ForeignAPIRepo::getThumbUrlFromCache got local thumb http://www.wikimania2010.pl/upload/www.wikimania2010.pl/thumb/POL_Gdań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:
http://commons.wikimedia.org/w/api.php?titles=Image%3AO%C5%82owianka_Island_04.jpeg&iiprop=url&iiurlwidth=810&iiurlheight=-1&prop=imageinfo&format=json&actio
n=query

Response:
{"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:\/\/upload.wikimedia.org\/wikipedia\/commons\/thumb\/e
\/e2\/O%C5%82owianka_Island_04.jpeg\/810px-O%C5%82owianka_Island_04.jpeg","thumbwidth":810,"thumbheight":184,"url":"http:\/\/upload.wikimedia.org\/wikipedia\
/commons\/e\/e2\/O%C5%82owianka_Island_04.jpeg","descriptionurl":"http:\/\/commons.wikimedia.org\/wiki\/File:O%C5%82owianka_Island_04.jpeg"}]}}}}

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
URL: http://www.wikimania2010.pl/wiki/U%C5%BCytkownik:Saper/Brudnopis?action=purge

Attached:

Details

Reference
bz20751