Manual:Image administration

This article describes how MediaWiki handles and stores images, and gives some information on configuring.

The same applies to any other type of file that can be uploaded. Since all files are stored with a corresponding article in the namespace image, it is refered as image only.

Upload and usage of images
See: Help:Images

Enable upload of images
To upload images, three conditions have to be met:


 * 1) MediaWiki must have uploads enabled. Set $wgEnableUploads to true.
 * 2) The file type must be allowed. More information: $wgFileExtensions.
 * 3) The user has to be logged in.

Uploads are done with the Specialpage Upload.

See Manual:Configuring file uploads, Manual:Mime type detection

Relevant parameters for image handling
These parameters are relevant:
 * Image configuration
 * Path configuration
 * Upload configuration

Image thumbnailing
MediaWiki's extended image syntax allows images to be automatically thumbnailed (see Manual:Configuring file uploads for general help on file uploads).

Image thumbnailing requires either ImageMagick or GD library. ImageMagick is recommended since it produces better quality thumbnails; it can be downloaded from imagemagick.org. GD can be downloaded from libgd.org. Neither of these are part of the default MediaWiki installation, although PHP can come with GD.

For older versions of MediaWiki (prior to 1.10.0) set $wgUseImageResize to true to enable thumbnailing. In newer versions this is not needed anymore.

If you use ImageMagick, set $wgUseImageMagick to true in LocalSettings.php. Make sure the $wgImageMagickConvertCommand variable points to the (absolute) location of the convert command of your installation and that the command is executable by the web server process.

GIF
For thumbnailing GIF-Animations under windows, you need to install ImageMagick as described as above.

SVG
MediaWiki supports SVG image rendering: if enabled, SVG images can be used like other image files: they will automatically be rendered as a PNG file and thumbnailed as needed on the fly.

To enable SVG support:


 * 1) Allow upload of SVG files in the LocalSettings.php file: $wgFileExtensions[] = 'svg'; Note that MediaWiki will refuse SVG files containing JavaScript, for security reasons. To avoid some false positives, set $wgAllowTitlesInSVG = true;. If you get an error saying the file is corrupt, make sure mime type detection is  working properly.
 * 2) Set $wgSVGConverter to the renderer you want to use. Available options are ImageMagick, sodipodi, inkscape, batik, and rsvg.
 * 3) * If the converter program is not in the system path, you have to specify the directory that contains the program using $wgSVGConverterPath.


 * librsvg is very accurate and fast. It has a ridiculously large chain of dependencies, so you may not want to bother unless you have a repository that includes it and resolves the dependencies for you. The Wikimedia projects use rsvg. Note: As of version 2.22.3, there is a bug in locale handling (see Wikimedia bug report and GNOME bug report). A patch is available for the   tool.
 * Batik is the most accurate SVG renderer available. It relies on Java. It is also much slower than rsvg, though this may not be a huge issue unless you're constantly adding SVG files. See SVG benchmarks.
 * Inkscape also does an accurate job of SVGs, half the speed of rsvg, but was designed for interactive graphical use - it requires a writable home directory for the user it's run as. Since it will be running as user www or something similar, it will try to create .inkscape/ and .gnome2/ directories in the corresponding home directory, and will fail silently if it is not able to. Inkscape is preferable to rsvg (a) on Windows (it comes as a standalone package) or (b) if you have important SVGs drawn in Inkscape that do not render correctly in rsvg. Inkscape has as complicated a dependency chain as librsvg &mdash; use only if it's in your distribution or available as a complete standalone package.
 * Sodipodi is the program Inkscape was forked from. The same considerations apply. Sodipod is no longer under active development.
 * ImageMagick renders SVGs, but very buggily. Also slow. This is the default, but avoid it if possible.
 * The GD library is not capable of converting SVG images to the PNG format, at least according to Joen Asmussen's June 2008 NoScope blog.
 * Most current web browsers except Internet Explorer can display SVGs directly, fast but inaccurately (about as well as ImageMagick). Using librsvg to render SVGs to a PNG will give much more accurate results. Direct SVG display is not supported in MediaWiki by default.

Deletion of images
Images, like wiki pages, can only be deleted by sysops (unless the user rights have been altered). Deletion of images is done by deleting the associated description page (or by clicking the "delete all versions" link).

Deletion of individual revision
If a picture has been altered, there is a revision history of the image files which is displayed on the image article. Each revision has a "delete" link. If this is clicked, the revision and the file are permanently deleted.

image article (aka description page) revision and image revision are separate things.

Information about old revisions of images are stored in the oldimage table.

Undeleting images
Before MediaWiki version 1.8, deleted images/files can not be undeleted (only the associated description page can be restored).

From MediaWiki version 1.8 up to 1.10, archiving deleted images/files (and thus undeleting them) is disabled per default, but can be enabled by setting $wgSaveDeletedFiles = true.

Since MediaWiki version 1.11, this is enabled per default, and $wgSaveDeletedFiles is deprecated. Instead, the behavior is controlled by $wgFileStore.

Information about deleted images are stored in the filearchive table.

Data storage
Whenever an image is uploaded, several things are created:


 * 1) An article in the namespace image with the exact name of the file, e.g. Image:MyPicture.png. This article is stored and behaves like any other article.
 * 2) The file itself is stored in a folder of the hosting (unix) system.
 * 3) If the file is wider than 800px or higher than 600px, a thumb with either 800px width or 600px height will be created. The thumb is stored in the folder pathofwiki/images/thumb/x/xy/MyPicture.png/MyPicture.png. Each thumb gets its own folder by the name of the original picture. Any time you create a thumb or resized image within an article, another thumb is created and stored here, prefixed by its width in px, e.g. 800px-MyPicture.png.

MediaWiki creates several subfolders in the folder images: x/xy, where:
 * x: 0 to F
 * xy: with x equals the x of the upper folder and y: 0 to F.

This subfolders only appear if you have $wgHashedUploadDirectory = true (default). xy are the two first characters of the md5 hash of the final image filename.

Folders
All image files are stored in a separate folder. Default is pathofwiki/images/x/xy/MyPicture.png. See $wgUploadPath for details.

Description of /image subfolders:

Note: If $wgHashedUploadDirectory = true, MediaWiki uses the /a/ab/foo.png directory structure. If set to false, these folders are not created and all pictures are stored in the image directory itself (this saves about 3 MB of space on disks).


 * 0-f/x0-xf: This is the storage place for the original image files (most recent version).
 * archive/0-f/x0-xf: This is the storage place for the original image files, that have been replaced by newer versions.
 * temp/0-f/x0-xf: used for image uploading. Often old files remain here. They should be deleted regulary (for space reasons). (Bug description: When you upload a picture, it is first stored in temp and then moved. If the image already exists, the user gets a warning. If he then clicks on cancel, the upload process is halted, but the image remains in the folder temp.)
 * thumb/0-f/x0-xf: corresponds with 0-f: Thumbnails (automatically generated) for the pictures in 0-f. If these get lost, they are automatically regenerated. If you delete the whole folder thumb, it will build itself up. You may experience some cache problems.

Database tables

 * The article Image:MyPicture.png: is stored as any article in page, text, revision etc.
 * table image: Holds some meta data like the size of the image. It does not contain the link to the file. This is probably calculated by the name of the file and the reason why it is not possible to move articles in the namespace image.
 * table imagelinks: Holds the information in which article an image is used.
 * table oldimage: This is the archive for pictures that have been replaced with newer versions. Note: Deleted pictures are not stored here, they are permanently deleted (or, in newer MediaWiki versions, moved to the filearchive).
 * table filearchive: holds the information on the deleted images.

Space usage
Pictures need considerably more space than articles. The following calculations assume a block size of 4KB with Linux/Unix servers.

The default setting is $wgHashedUploadDirectory = true.

Space requirements for all directories:


 * image directories: 0-f/x0-f: max. 16*16 = 256 directories = 256*4 KB = 1024 KB
 * archive directories: 0-f/x0-f: max. 16*16 = 256 directories = 256*4 KB = 1024 KB
 * thumb directories: 0-f/x0-f: max. 16*16 = 256 directories = 256*4 KB = 1024 KB
 * temp directories: 0-f/x0-f: max. 16*16 = 256 directories = 256*4 KB = 1024 KB

Therefore, the basic amount of space needed without any images uploaded is 4 MB. (Vague: Say if all this gets eaten up right off the bat with not even one file added yet, or do directories get added only as needed? 02:31, 2 June 2008 (UTC))

For each picture we need:
 * size of the original image file + 2 KB average overhead

For pictures with a height of more than 600 pixels or a width of more than 800 pixels:
 * size of the created thumbnail(s) + 2 KB average overhead (each)
 * directory for thumbnail (4KB) (each image has its own thumbnail directory)

Examples:
 * image 20778 Byte png (small size, no thumb): 24 KB for the image: Total 24 KB
 * image 123.000 Byte jpeg (big size, auto thumb): 124 KB for the image, 4KB for the thumb directory, 64 KB for the thumb: Total: 192 KB

File Access
Uploaded files are generally served directly by the web server, not through MediaWiki. While there may be a minimal level of security through obscurity with path encryption (eg. /c/c4/...) if $wgHashedUploadDirectory is set, the path can be calculated easily from the file name and does not provide true protection.

For limiting access to authorized users, see Image Authorization

Licensing
A feature of MediaWiki allows the Special:Upload Page to streamline licensing of images. Wikipedia's Upload Page has a Licensing drop down box below image summary. This feature is turned off in default MediaWiki. To turn this feature on a sysop needs to edit Licenses in the MediaWiki namespace. Example: MediaWiki:Licenses

Licenses expects a certain format in a wiki list.

Line 1 will produce "License text" and substitute the license 1 template in the image page and transclude license 2.

Line 2 will show a greyed out header with text "Header 1:"

Line 3 will produce "Attribution ShareAlike 2.5" and transclude template cc-by-sa-2.5 on the image page.

For detailed real world example, see http://en.wikipedia.org/wiki/MediaWiki:Licenses

MediaWiki Version
This applies to:
 * MediaWiki 1.9.x and above
 * other versions not verified

Alternative simple setup
If one merely wants make a file accessible from one's site, an alternative to implementing all of the above is: (To embed, rather than just offering the above hyperlink, is more complicated...)
 * 1) Place the file in e.g., images/
 * 2) Link to it in wikitext via [/images/lawnmower.png My lawnmower]