Forcing "utf-8" encoding when doing mb_strtoupper seems to cause problems when parsing odd filenames (e.g. File:Żółty bratek.jpg). Removing it seems to help, but I'm not 100% sure why.