Last modified: 2010-05-15 15:42:51 UTC
Platform: XAMPP 1.5.4a running on Windows XP Professional. PHP 5.1.6. Apache reports
Server: Apache/2.2.3 (Win32) DAV/2 mod_ssl/2.2.3 OpenSSL/0.9.8d mod_autoindex_color
When a PNG image is uploaded, and then the Image: page is viewed, on the first viewing it
displays correctly as expected with an appropriate size thumbnail, but if you refresh the
page, the PNG is replaced by fileicon.png, which is used when an unknown file type is
So what happened between first and second loadings of the page ?
Well, I discovered that my PHP magic.mime file from XAMPP is broken. Running php -i from
the command line showed:
mime_magic support => invalid magic file, disabled
Directive => Local Value => Master Value
mime_magic.debug => Off => Off
mime_magic.magicfile => C:\Program Files\xampp\php\extras\magic.mime => C:\Program
I noticed something odd, it was mapping PNG files into image/x-png
I had another look at an affected file, in this case one from Wikimedia Commons
which I had copied onto my system (since it was referred to by some Help: pages).
The first time I looked at it, it displayed with
Canterbury_Tales.png (26KB, MIME type: image/png)
but when I reloaded it it changed to
Canterbury_Tales.png (26KB, MIME type: image/x-png)
and the image was replaced by the generic fileicon.png in function iconThumb of Image.php
What was going on ?
I looked into image table of MySQL using phpMyAdmin, and sure enough, all my PNG images
had img_minor_mime field set in their records to x-png instead of png. That explained
what was going on for the SECOND time I viewed the page - somehow it was getting the mime
type from the image table as image/x-png, then deciding it couldn't handle it.
But why was it working for the FIRST time I viewed the Image: page ?
I am still not sure what changes in this case. But it definitely looks as though
MediaWiki is using two different methods for getting the MIME type, possibly one related
directly to file extension and the other relating to file magic numbers derived by PHP.
I fixed up my magic.mime file, ran php maintenance/rebuildImages.php to fix up the image
table. The problem has not re-appeared.
Yes, part of the problem was the broken magic.mime file supplied with XAMPP, but the
other problem, and the one I want to highlight is the broken way that MediaWiki displayed
the Image: page OK the first time but not the second (and subsequent) times. The code is
somehow inconsistent. I suspect that without my broken magic.mime file, I may never have
uncovered this bug.
It's quite simple; MediaWiki used a PHP function to do the MIME detection, and
then saved this result in the database to save time later, among other things.
The trouble is, if the result we get is wrong, we don't know that, and we store
The "fix" for this, as discovered, is to run maintenance/rebuildImages.php to
fix up the MIME types in the database.
Thanks Rob for your reply
In my situation, I have an SQL dump taken from a server with broken magic.mime file.
The image table fields already say x-png for img_minor_mime
Yet when I view any of these Image: pages which are PNG files the first time, it isn't
looking at the database (or doesn't appear to be). It's somehow getting it right
first time and displaying the image, and then getting it wrong (which I guess is when
it IS referring to the stored copy you refer to) and showing the MIME type of image/x-
I expected it to either get it wrong all the time or get it right all the time, which
does not coincide with my experience.
Closing this bug since it is more like a support request.