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.

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.
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 $wgThumbnailEpoch.

GraphicsMagick can now also be used as an alternative to ImageMagick.
You will need to set $wgImageMagickConvertCommand to the (absolute) location of the 'gm' command.
E.g.:

$wgImageMagickConvertCommand = "/usr/bin/gm";

GIF

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

SVG

Wikimania 2016 presentation on Dynamic 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.
If you're on a shared host and no SVG renderer is pre-installed, you should probably ask your provider to install it for you.

If the converter program is not in the system path, you have to specify the directory that contains the program using $wgSVGConverterPath..

librsvg is fast but not very accurate. It depends on a large number of libraries. To automatically install all these libraries, you may want to use a package manager. The Wikimedia projects use rsvg.

Batik is the most accurate SVG renderer available, although its anti-aliasing is sometimes suboptimal. Its SVG parsing is more strict, causing it to reject "almost valid" SVG files that other renderers accept (e.g. commons:File:UbuntuCoF.svg). Batik relies on Java, and is much slower than rsvg, though this may not be a huge issue unless you're constantly adding SVG files. See SVG benchmarks. Requires a lot of work to get running, if not included in your distribution.

Inkscape also does an accurate job of SVGs, half the speed of rsvg, but was designed for interactive graphical use; however, it comes with inkview which is a viewer/converter program - 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, crash or hang indefinitely 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 — 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.

Since version 6.x.x ImageMagick renders SVGs, but imperfectly. This is the default, but avoid it if possible. However, it does work. On Windows, $wgConvertPath must be set to avoid a conflict with Windows' own convert.exe. One simple alternative in this scenario is to add to LocalSettings.php the line $wgSVGConverters['ImageMagick'] = '"' . $wgImageMagickConvertCommand . '" -background white -thumbnail $widthx$height^! $input PNG:$output';, which also allows for spaces in the path.

The PHP Imagick extension supports SVG rendering, however the same considerations as for the regular ImageMagick apply.

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 exceptInternet Explorer (until version 9) can display SVGs directly. Using librsvg to render SVGs to a PNG will give much more accurate results, as well as less bandwidth consumption. Direct SVG display is not supported in MediaWiki by default (task T5593), unless you install NativeSvgHandler extension.

Set $wgSVGConverter = false if SVG rendering is not needed and you wish to make your users download the svg file in order to view it.

استكشاف الأخطاء وإصلاحها

If you see a blank square instead of SVG (Chrome) or no image at all (Firefox) and all PNG links lead to 404 error and you don't see any other error message anywhere please check $wgGenerateThumbnailOnParse variable.
Setting it to false may make SVG transformation deferred always. Make sure that proc_open and symlink PHP methods are enabled (they may be disabled in php.ini for security or performance reasons).

JPEG (using GD)

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

DjVu

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.

The versions of files are separate from the page history of the file description page.

Information about old revisions of files are stored in the oldimage table while information on old revisions of the pages are stored in the revision table.

Undeleting files

تحذير:

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.
Since 1.23 the behavior was instead controlled by $wgFileStore.

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 eraseArchivedFile.php maintenance script.
If you want to delete all of them completely, you can do that with the deleteArchivedFiles.php script.
If you delete archived files, you can not undelete those files anymore.

Data storage

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.

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

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. These are stored in the thumb directory of the image directory, in a separate directory for each main file.

If $wgHashedUploadDirectory is set to true (which is the default), images will be stored in subfolders of the images, thus making file paths look like images/a/ab/filename.jpg. See Manual:$wgHashedUploadDirectory for more details on why this might be desired and how this system works.

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.

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.

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

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.

Foreign Repositories

It is possible to access files stored in foreign repositories, without needing to upload them to the wiki, by setting the $wgForeignFileRepos 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.