Manual:Image administration/zh

这篇文章描述了MediaWiki如何存储于处理文件，并给出了配置的相关信息.

这可以应用于包括但不限于图片等可以被上传的文件类型. 所有文件存储在对应的"File:"命名空间中. 在 MediaWiki 1.14版本 之前，使用的是"Image:"命名空间 "Image:"仍然被保存以用于向下兼容.

图片的上传与使用
参见

启用图片上传
需要满足以下的条件才能上传文件：


 * 1) MediaWiki 必须启用了上传  设置为 true.
 * 2) 文件类型必须被允许.  参见：.
 * 3) 用户必须位于具有 "upload" 权限的用户组中.  所有登录的用户默认具有此权限.

上传通过Special:Upload完成.

参见 ，及

与文件处理有关的参数
以下参数与之相关：



图片缩略图
MediaWiki的扩展图像语法允许自动缩略图（参见获取文件上传的帮助）

图像缩略图需要 ImageMagick 或 GD library - 两者都不是默认 MediaWiki 安装的一部分，尽管某些版本的 PHP 包含 GD. 如果需要更高質量的縮略圖，建議使用ImageMagick. 可以從官方網站下載. GD包含在某些版本的PHP中及建議在windows系統中使用GD系統 可從LibGD GitHub中下載GD. 不需要使用較新的版本.

如果需要使用ImageMagick，在LocalSettings.php中將設置為true. 確保變量指向安裝的convert命令的位置，並且該命令可由網站服務器執行. 例如，Windows用戶將需要將默認值更改為“C:\ImageMagick\convert.exe”（或類似名稱）.

要在使用ImageMagick之前重新創建舊的縮略圖文件，可以使用.

If rendering fails silently, check and increase.

GraphicsMagick can also be used as an alternative to ImageMagick. You will need to set to the following. 例如：

GIF
要在windows下使用缩略图绘制GIF-“动画”，需要如上所述安装ImageMagick.

SVG


Mediawiki支持SVG图像呈现：如果启用，SVG图像可以像其他图像文件一样使用-它们将自动呈现为PNG文件，并根据需要动态缩略图. 如果您在共享主机上，并且没有预先安装SVG渲染器，您可能应该要求提供商为您安装它.

为了开启 SVG 支持：

Its SVG parsing is more strict, causing it to reject "almost valid" SVG files that other renderers accept (e.g. ). 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. Since it will be running as user  or something similar, it will try to create   and   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. The same considerations apply. Sodipod is no longer under active development. 这是默认值，但最好应避免. 然而这能工作. 在Windows上，必须设置$wgConvertPath以避免与Windows自带的convert.exe软件冲突. One simple alternative in this scenario is to add to LocalSettings.php the line, which also allows for spaces in the path. See ImageMagick issue. 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, unless you install extension.
 * 1) 允许在localsettings.php文件中上载SVG文件： 请注意，出于安全原因，Mediawiki将拒绝包含javascript的SVG文件.
 * 要避免误报，请将 添加到文件中.
 * If you are using MediaWiki 1.34 or higher, is never applied and now always true. You can safely remove this in your LocalSettings.php file.
 * 如果您收到文件损坏的错误消息，请确保正常工作.
 * 1) 添加   到  并设置要使用的渲染器
 * Available options are ImageMagick, ImagickExt , sodipodi , inkscape , batik , rsvg , and imgserv.
 * 例如：
 * 1) * librsvg很快但不是很准确， 它依赖于大量的资料. 要自动安装所有这些库，您可能需要使用软件包管理器. 非维基媒体计划参与者
 * 1) * librsvg很快但不是很准确， 它依赖于大量的资料. 要自动安装所有这些库，您可能需要使用软件包管理器. 非维基媒体计划参与者
 * 1) * Batik is the most accurate SVG renderer available, although its anti-aliasing is sometimes suboptimal.
 * 1) * 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.
 * 1) * Sodipodi is the program Inkscape was forked from.
 * 1) * Since version 6.x.x ImageMagick renders SVGs, but imperfectly.
 * 1) ** 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.
 * 1) * The PHP Imagick extension supports SVG rendering, however the same considerations as for the regular ImageMagick apply.
 * 1) * 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.
 * 1) * Most current web browsers except Internet Explorer (until version 9) can display SVGs directly.

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

Troubleshooting
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 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 （使用 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
生成TIFF文件的缩略图需要MediaWiki 1.15.0或更新的版本.

Consider appropriate settings for  and
 * 1) 允许在LocalSettings.php文件中上载TIFF文件：
 * 2) 将 添加到并设置为jpg或png，以指定希望生成的缩略图类型.
 * 1) 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.

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

恢复文件
可以使用与普通wiki页面完全相同的方式取消删除文件. 存储已删除文件的目录由定义. Information about deleted images are stored in the table.

删除档案文件
自 MediaWiki 1.11版起，被删除的图片默认仍然存储在服务器上. 如果您需要删除特定的档案图片，您可以使用eraseArchivedFile.php 维护脚本. 如果您想要彻底删除它们，可以通过deleteArchivedFiles.php维护脚本. 如果您删除了档案文件，您将不能恢复这些文件.

删除文件的理由
When choosing to delete a file, as described 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.

数据存储
Whenever an image is uploaded, several things are created:

This page is stored and can be edited like any other page. These are stored in the thumb directory of the image directory, in a separate directory for each main file.
 * 1) An article in the file namespace with the name of the file, e.g. File:MyPicture.png.
 * 1) The file itself is stored in a folder on the file system with whitespaces merged and replaced with.
 * 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 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 (, by default).

Description of named image subfolders:

(Due to, these files may not always be automatically deleted) If these are deleted, they are automatically regenerated when needed.
 * 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.
 * thumb: Thumbnails (automatically generated) for the files.

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

See for more details on why this might be desired and how this system works.
 * math: Folder to store your rendered TeX input, see also Extension:Math or Manuel:Math.
 * 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.

数据表

 * The file description page is stored as any page in the page, text, revision etc. tables
 * - Holds some metadata such as the size of the file and the upload date.
 * - This is stores information for files that have been replaced with newer versions.
 * - holds the information on the deleted files.
 * - 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.

默认设置为 = 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, 4 KB for the thumb directory, 64KB 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 (e.g. /c/c4/...) if 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.

Upload form
See the documentation on configuring the upload form.

许可
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.

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.

外部仓库
通过设置数组，可以访问存储在外部存储库中的文件，而无需将其上载到wiki. 这个特性提供了如下可能：


 * “'ForeignAPIRepo'”通过其API访问远程MediaWiki安装中的文件，例如 Wikimedia commons
 * “'ForeignDBRepo'”通过数据库访问文件，对于创建wiki families非常有用
 * "‘FSRepo'" 从本地文件夹访问文件

在所有情况下，都可以使用普通 image语法将文件嵌入到页面中，并在外部存储库中指定文件名. 请注意，上面的一些实现仍然是实验性的，可能不适合生成站点.