这可以应用于包括但不限于图片等可以被上传的文件类型。 所有文件存储在对应的"File:"命名空间中。 在 MediaWiki 1.14版本 之前，使用的是"Image:"命名空间 "Image:"仍然被保存以用于向下兼容。
- MediaWiki 必须启用了上传 $wgEnableUploads 设置为 true 。
- 文件类型必须被允许。 参见： $wgFileExtensions。
- 用户必须位于具有 "upload" 权限的用户组中。 所有登录的用户默认具有此权限。
If rendering fails silently, check and increase $wgMaxShellMemory.
GraphicsMagick can now also be used as an alternative to ImageMagick. You will need to set $wgCustomConvertCommand to the following. 例如：
$wgUseImageMagick = false; $wgCustomConvertCommand = "gm convert %s -resize %wx%h %d";
For thumbnailing GIF-Animations under windows, you need to install ImageMagick as described above.
为了开启 SVG 支持：
$wgSVGConverter到 LocalSettings.php 并设置要使用的渲染器
$wgSVGConverter = 'ImageMagick';
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. 参见SVG基准。 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
.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.
这是默认值，但最好应避免。 然而这能工作。 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.
- To prevent thumbnail creation errors with ImageMagick, if it's ≥ 7.0.9-25, then Inkscape must also be ≥ 1.x.x. Likewise, if ImageMagick is < 7.0.9-25, then Inkscape must also be < 1.x.x.
See ImageMagick issue.
- The PHP Imagick extension supports SVG rendering, however the same considerations as for the regular ImageMagick apply.
- Most current web browsers except Internet 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 (任务T5593), unless you install NativeSvgHandler extension.
$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
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 （使用 GD）
Simply add the following line to LocalSettings.php, this will cause auto fall back to GD library.
$wgUseImageMagick = false;
For errors with JPEG thumbnails, see JPEG (using GD).
Generating thumbnails of TIFF files requires MediaWiki 1.15.0 or newer.
- Allow upload of TIFF files in the LocalSettings.php file:
$wgFileExtensions = 'tif';
- Making thumbnails of TIFF files may require system resources beyond those needed for thumbnailing JPEG, GIF, or PNG files.
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).
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.
Files can be undeleted in exactly the same way as normal wiki pages. The directory in which deleted files are stored is defined by 手册:$wgDeletedDirectory. Information about deleted images are stored in the filearchive table.
Whenever an image is uploaded, several things are created:
- 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 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:
- This is the storage place for files that have been replaced by newer versions.
- used for temporary storage of files during image uploading.
(Due to 任务T11018, these files may not always be automatically deleted)
- 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:
$wgHashedUploadDirectoryis set to true (which is the default), images will be stored in subfolders of the images, thus making file paths look like
See 手册:$wgHashedUploadDirectory for more details on why this might be desired and how this system works.
- 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.
Files need considerably more space than articles. The following calculations assume a block size of 4KB with Linux/Unix servers.
默认设置为$wgHashedUploadDirectory = true。
- 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).
- 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)
- 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
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 Manual:Image authorization.
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). They 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.
*subst:license 1|license 2|License text
* Header 1:
** cc-by-sa-2.5|Attribution ShareAlike 2.5
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.
It is possible to access files stored in foreign repositories, without needing to upload them to the wiki, by setting the $wgForeignFileRepos array. 这个特性提供了如下可能：
- 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 从本地文件夹访问文件
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 1.9.x 及以上版本