Manual:Image administration

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

This applies to images as well as to any other type of file that can be uploaded.

All files are stored with a corresponding article in the "File:" namespace.

Prior to MediaWiki 1.14, the "Image:" namespace was used instead.

"Image:" is still retained as an alias for backward compatibility.

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

Image thumbnailing requires either ImageMagick or GD library - neither are part of the default MediaWiki installation, although some versions of PHP include GD.

ImageMagick is recommended if better quality thumbnails are needed; it can be downloaded from imagemagick.org.

GD is included in some versions of PHP, and it is recommended to use GD on Windows systems.

A standalone download of GD is available from LibGD GitHub.

In newer versions this is not required.

If you use ImageMagick, set  to true in LocalSettings.php.

Make sure the  variable points to the (absolute) location of the convert command of your installation and that the command is executable by the web server process.

For example, Windows users will want to change the default to "C:\ImageMagick\convert.exe" (or similar).

To re-create old thumbnail files before you used ImageMagick you can use .

If rendering fails silently, check and increase .

[http://www.graphicsmagick.org/ GraphicsMagick] can now also be used as an alternative to ImageMagick.

You will need to set $wgCustomConvertCommand to the following.

E.g.:

$wgUseImageMagick = false; $wgCustomConvertCommand = "gm convert %s -resize %wx%h %d";

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

JPEG (using GD)
Simply add the following line to LocalSettings.php, this will cause auto fall back to GD library.

For errors with JPEG thumbnails, see JPEG (using GD).

TIFF
Generating thumbnails of TIFF files requires MediaWiki 1.15.0 or newer.


 * 1) Allow upload of TIFF files in the LocalSettings.php file:


 * 1) Add   to <tvar|2></> and set to either jpg or png to specify which type of thumbnail you wish to have generated.

Consider appropriate settings for <tvar|1> </> and <tvar|2> </>
 * 1) Making thumbnails of TIFF files may require system resources beyond those needed for thumbnailing JPEG, GIF, or PNG files.

Deletion of images
Files, like wiki pages, can only be deleted by users with the " (delete)" permission ( by default).

Deletion of files is done by deleting the associated description page (or by clicking the "" link in the "" table).

Deletion of individual revision
If a file has been altered, there is a revision history of the files which is displayed on the file article page.

Each revision has a "" link.

If this is clicked, the revision and the file are deleted.

Information about old revisions of files are stored in the <tvar|oldimage></> table while information on old revisions of the pages are stored in the <tvar|revision></> table.

Undeleting files
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 <tvar|1> = true</>.

Since MediaWiki version 1.11, this is enabled per default, and $wgSaveDeletedFiles is deprecated.

Since 1.23 the behavior was instead controlled by <tvar|FileStore></>.

Since 1.24 its controlled by <tvar|1></>

Information about deleted images are stored in the filearchive table.

Deletion of Archived Files
Since MediaWiki version 1.11, deleted images are still stored on the server by default.

If you want to delete selected archived images, you can do so using the <tvar|eraseArchivedFile></> maintenance script.

If you want to delete all of them completely, you can do that with the <tvar|deleteArchivedFiles></> script.

If you delete archived files, you can not undelete those files anymore.

Reasons for Deleting a File
When choosing to delete a file, as described 1>#Deletion of images</>|above, users will be asked to provide a reason for deletion.

The available reasons can be edited on the MediaWiki:Filedelete-reason-dropdown of your wiki.

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


 * 1) An article in the file namespace with the name of the file, e.g. File:MyPicture.png.  This page is stored and can be edited like any other page.


 * 1) The file itself is stored in a folder on the file system with whitespaces merged and replaced with.

These are stored in the thumb directory of the image directory, in a separate directory for each main file.
 * 1) If necessary and thumbnailing is available, thumbnailed versions of the file will be created when necessary (such as for the usage on the file description page.

If <tvar|HashedUploadDirectory></> is enabled (by default), MediaWiki creates several subdirectories in the images directory.

The directory names are from the first two characters of the md5 hash of the final filename.

Folders
All image files are stored in a folder determined by <tvar|UploadPath></> (<tvar|path> </>, by default).

Description of named image subfolders:


 * archive: This is the storage place for files that have been replaced by newer versions.


 * temp: used for temporary storage of files during image uploading. (Due to <tvar|bug></>, these files may not always be automatically deleted)


 * thumb: Thumbnails (automatically generated) for the files. If these are deleted, they are automatically regenerated when needed.

Depending on the configuration, there may be additional image subfolders:


 * math: Folder to store your rendered TeX input, see also Manual:Enable TeX or Math.

See <tvar|1></> for more details on why this might be desired and how this system works.
 * x/xy: If  is set to true (which is the default), images will be stored in subfolders of the images, thus making file paths look like.

Database tables

 * The file description page is stored as any page in the page, text, revision etc. tables


 * image table: Holds some metadata such as the size of the file and the upload date.


 * oldimage table: This is stores information for files that have been replaced with newer versions.


 * filearchive table: holds the information on the deleted files.


 * imagelinks table: Records what pages use a file.

Space usage
Files need considerably more space than articles.

The following calculations assume a block size of 4KB with Linux/Unix servers.

The default setting is <tvar|1> = 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 in theory (although the directories are created only when needed).

For each file we need:


 * size of the original image file + 2 KB average overhead

For files that need to be thumbnailed:


 * 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 <tvar|1></> 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 <tvar|1></>.

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

S/he can do this by going to the MediaWiki:Licenses page of their wiki and clicking 'create' or 'edit'.

The page MediaWiki: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 Wikipedia:MediaWiki:Licenses or Commons:MediaWiki:Licenses.

Foreign Repositories
It is possible to access files stored in foreign repositories, without needing to upload them to the wiki, by setting the <tvar|1></> array.

This feature offers several possibilities:


 * ForeignAPIRepo accesses files from a remote MediaWiki installation, such as Wikimedia Commons, through its API


 * ForeignDBRepo accesses files through a database, and is useful for creating wiki families


 * FSRepo accesses files from a local folder

In all cases, one would be able to embed files into a page using ordinary image syntax and specifying the name of the file in the foreign repository.

Note that some of the above implementations are still experimental, and might not be suitable for production sites.

MediaWiki Version
This applies to:


 * MediaWiki 1.9.x and above


 * other versions not verified