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 has upload 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).

Bitmaps
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 boutell.com/gd Neither of these are part of the default MediaWiki installation.

To enable image thumbnailing, set $wgUseImageResize and $wgUseImageMagick to true in LocalSettings.php. Make sure the $wgImageMagickConvertCommand variable points to the proper location of the  command of your installation and that the command is executable by the web server process.

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 on demand. To enable SVG support:

First, 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.

Second, set $wgSVGConverter to the renderer you want to use. Available options are ImageMagick, sodipodi, inkscape, batik, and rsvg. The default is ImageMagick, but it is recommended to use one of the other renderers if possible. If the converter program is not in the system path, you have to specify the directory that contains the program using $wgSVGConverterPath.

deletion of images
Images can only be deleted by sysops (unless the user rights have been altered).

In this section the deletion of the files in the folder "/images" is described. The corresponding article can be deleted and restored like any other article in MediaWiki.

default behavior
The parameter $wgSaveDeletedFiles is set to false by default.

deletion of image revision
If a picture has been altered, there is a revision history of the image files which is displayed on the image article. Note: image article revision and image revision are separate things.

Each revision has a "delete" link. If this is clicked, the revision and the file are permanently deleted.

deletion of all revisions/article
You can use the "delete all versions" link or delete the article. Both have the same result:
 * The article is deleted (but restorable).
 * The original image is deleted (not restorable).
 * All thumbnails are deleted (not restorable). (There is a litte bug: the thumbnail directory is not deleted, as of MW 1.9.2)
 * All corresponding information in the db tables: image, imagelink and oldimages are removed

$wgSaveDeletedFiles = true
You can set your wiki to archive all deleted files, see $wgFileStore. This makes it possible to undelete pictures.


 * MediaWiki database table Filearchive table holds the information on the deleted images.
 * folder /imagesDeleted (needs to be defined) holds the deleted images.

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 then 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 haltet, 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. (This could have been stored in pagelinks, but someone decided to create a different table.)
 * 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.
 * table filearchive: holds the information on the deleted images.

space usage
Pictures need considerably more space than articles. I will assume a block size of 4KB with Linux/Unix servers.

The default setting is $wgHashedUploadDirectory = true.

So we calculate the sole space for all folders
 * image folders: 0-f/x0-f: max. 16*16 = 256 folders = 256*4 KB = 1024 KB
 * archiv folders: 0-f/x0-f: max. 16*16 = 256 folders = 256*4 KB = 1024 KB
 * thumb folders: 0-f/x0-f: max. 16*16 = 256 folders = 256*4 KB = 1024 KB
 * temp folders: 0-f/x0-f: max. 16*16 = 256 folders = 256*4 KB = 1024 KB

We need a basic space usage of 4 MB without any images saved.

For each picture we need: pictures with height > 600px or width > 800px
 * size of the original image file + 2KB medium space overhead
 * size of the created thumbnail(s) + 2KB medium space overhead
 * folder for thumbnail (4KB) (each image has its own thumbnail folder)

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 folder, 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 Authorisation

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