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.
SeeHelp:Images
To upload files, these conditions have to be met:
true
.Uploads are done usingSpecial:Upload.
SeeConfiguring file uploads,MIME type detection andAdding support for new filetypes
These parameters are relevant:
MediaWiki'simage syntax allows dynamic resizing andthumbnailing of images (seeManual:Configuring file uploads for general help on file uploads).
Image thumbnailing requires eitherImageMagick orGD library – neither are part of the default MediaWiki installation.
PHP comes with GD graphics library enabled by default. GD will not require any configuration or modification to be used.
It is recommended to use GD on Windows systems.
GD can be downloaded fromhttps://libgd.github.io/.In recent PHP versions this is not required.
In MediaWiki, enable ImageMagick inLocalSettings.php
by setting$wgUseImageMagick totrue
.
ImageMagick can be downloaded fromhttps://imagemagick.org/.
Once ImageMagick is installed, you must enable ImageMagick and point MediaWiki to theconvert
orconvert.exe
program on your computer inLocalSettings.php like this:
$wgUseImageMagick=true;#$wgImageMagickConvertCommand = 'C:/ImageMagick/convert.exe'; # for Windows$wgImageMagickConvertCommand='/usr/bin/convert';# for Linux
If you use ImageMagick, set$wgUseImageMagick totrue
in LocalSettings.php.Make sure 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.
If rendering fails silently, check and increase$wgMaxShellMemory.
GraphicsMagick can 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";
MediaWiki core does not supportlibvips but there are extensions that let use this image processing library.
For thumbnailing GIF-Animations under windows, you need to install ImageMagick as described above.
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.
To enable SVG support:
LocalSettings.php
file:$wgFileExtensions[] = 'svg';
. Note that MediaWiki will refuse SVG files containing JavaScript, for security reasons.$wgSVGConverter
toLocalSettings.php and set the renderer you want to use.$wgSVGConverter='ImageMagick';
$wgSVGConverterPath
.www
or something similar, it will try to create.inkscape/
and.gnome2/
directories in the corresponding home directory, and will fail silently,crash orhang 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.LocalSettings.php
the line$wgSVGConverters['ImageMagick']='"'.$wgImageMagickConvertCommand.'" -background white -thumbnail $widthx$height^! $input PNG:$output';
, which also allows for spaces in the path.$wgSVGNativeRendering =true
.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 tofalse
may make SVG transformation deferred always.Make sure thatproc_open andsymlink PHP methods are enabled (they may be disabled in php.ini for security or performance reasons).
Simply adding the following line toLocalSettings.php
will cause auto fall back to the GD library:
$wgUseImageMagick=false;
For errors with JPEG thumbnails, seeJPEG (using GD).
Generating thumbnails of TIFF files requires MediaWiki 1.15.0 or newer.
LocalSettings.php
file:$wgFileExtensions[] = 'tif';
$wgTiffThumbnailType
toLocalSettings.php and set to either jpg or png to specify which type of thumbnail you wish to have generated.$wgMaxImageArea
and$wgMaxShellMemory
Files, like wiki pages, can only be deleted by users with theDelete pages
(delete) permission (administrators by default).Deletion of files is done by deleting the associated description page (or by clicking thedelete all
link in theFile history
table).
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 adelete
link.If this is clicked, the revision and the file are deleted.
Information about old revisions offiles are stored in theoldimage table while information on old revisions of thepages are stored in therevision table.
Files can be undeleted in exactly the same way as normal wiki pages.The directory in which deleted files are stored is defined byManual:$wgDeletedDirectory.Information about deleted images are stored in thefilearchive table.
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 theeraseArchivedFile.php maintenance script.If you want to delete all of them completely, you can do that with thedeleteArchivedFiles.php script.If you delete archived files, you can not undelete those files anymore.
When choosing to delete a file, as describedabove, users will be asked to provide a reason for deletion.The available reasons can be edited on theMediaWiki:Filedelete-reason-dropdown of your wiki.
MediaWiki:Filepage.css is astandard stylesheet which can be used to modify the display of file pages.The contents of Filepage.css will be loaded only on File namespace pages.If remote files are enabled, the remote wiki's version of this page will also load.
Whenever an image is uploaded, several things are created:
_
.If$wgHashedUploadDirectory 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.
All image files are stored in a folder determined by$wgUploadPath (images/
, by default).
Description of named image subfolders:
Depending on the configuration, there may be additional image subfolders:
$wgHashedUploadDirectory
is set totrue
(which is the default), images will be stored in subfolders of the images, thus making file paths look likeimages/a/ab/filename.jpg
. SeeManual:$wgHashedUploadDirectory for more details on why this might be desired and how this system works.page
,text
,revision
etc. tablesFiles 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:
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:
For files that need to be thumbnailed:
Examples:
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 (e.g. /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, seeManual:Image authorization.
See thedocumentation on configuring the upload form.
MediaWiki allows licenses to be added to files uploaded from theSpecial:Upload page.The list of licenses that appear in the license selection dropdown can be edited on theMediaWiki:Licenses page by a sysop.
The page should be a bulleted list of items, and can have sub-items.Each item can have one or more parameters, with the parameter separated by the pipe character (|
).
To make headers/categories, use only one parameter in a list item.The text will be what appears in the dropdown list, and will appear greyed-out and unclickable.
To add license options, two or more parameters are required.The first parameter will be the template name to use, without the double square brackets.The last parameter will be what appears in the dropdown list for that license.Any additional parameters between the first and last parameters will be passed as arguments to the template.When a license is selected, a preview of what it would look like on the final page is shown in the upload wizard.
Below is asimple example (not using real templates) of howMediaWiki:Licenses should be formatted:
Work type | Coverage | Used template |
---|---|---|
Work without licence | — | {{no-lic|No license.}} |
Work made be me | Used on this wiki | {{self-lic|And it can only be used on this wiki.}} |
Used anywhere | {{self-lic|free=yes|And I allow it to be used anywhere.}} | |
Work made by someone else | Work belongs to thepublic domain | {{pd-lic|It's in the public domain.}} |
Work iscopyrighted | {{copyright-lic|It's copyrighted.}} | |
Work is under aCreativeCommons license | {{cc-lic|It uses some CreativeCommons license.}} | |
Work is under theCC-BY-SA license | {{cc-lic|by-sa|It uses the CC-BY-SA license.}} |
The above assumes each template ending in "-lic" exists, where some of those templates take positional arguments such as "by-sa" and others take named arguments such as "free=yes".Selecting the option "And I allow it to be used anywhere", for example, would add the following template call to the page of the new file:
{{self-lic|free=yes}}
Sites like Wikipedia and WikiMedia Commons will also use thesubst:
tag, such as WikiMedia Common's usage of it below:
** subst:Template 2|flickrreview|subst:uwl|Image from Flickr and I do not know the license
"Template 2" is an actual template that will take two parameters (being template names) and surround them with double curly brackets so they get transcluded on the page of the new image."uwl" is a template, whose documentation requires using it with the "subst:" tag instead of directly.The above will result in the following being added to the uploaded file's page:
{{flickrreview}}{{subst:uwl}}
On Wikipedia, substitution is used in other ways, such as adding a timestamp with the license at the time of upload.
For detailed real world example, seeWikipedia:MediaWiki:Licenses orCommons:MediaWiki:Licenses.
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:
In all cases, one would be able to embed files into a page using ordinaryimage 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.