手册:$wgFileExtensions

From mediawiki.org
This page is a translated version of the page Manual:$wgFileExtensions and the translation is 77% complete.
Outdated translations are marked like this.
文件及文件上传: $wgFileExtensions
这是上传文件的首选扩展的列表 上传不在此列表中的扩展名的文件将触发警告
引进版本:1.2.0
移除版本:仍在使用
允许的值:(字符串数组)
默认值:参见下方

详情

$wgFileExtensions是在LocalSettings.php 上传文件的首选扩展的列表 这是比$wgProhibitedFileExtensions $wgMimeTypeExclusions 更重要的

如果$wgStrictFileExtensions 被设置成功,这样$wgFileExtensions的列表是被允许的扩展,并且其他的全部都是被封禁的。

如果$wgStrictFileExtensions 被设置失败,这样用户在上传界面的时候将只有得到一个关于扩展不在支持列表的警告 即$wgFileExtensions是后续唯一一个完美的扩展设置 在这种情况下一些特别的危险文件扩展将会仍然被屏蔽用$wgFileBlacklist和$wgMimeTypeBlacklist

如果$wgCheckFileExtensions 是失败的,功能是没有影响的,因为所有文件扩展将会被信任而不会执行任何检查

如果$wgEnableUploads 设置失败,功能是无效的,因为所有的上传都是无效的。

Some files, for example OpenDocument files (e.g. used by OpenOffice.org as odt, ods, odg, ...), use MIME types that don't match with their extension (or something similar). Uploading such files results in an error message like The file is corrupt or has an incorrect extension. Please check the file and upload again.. In such cases you can adjust the mapping of file extensions to MIME types, see MIME type validation.

默认值

MediaWiki版本:
1.27
$wgFileExtensions = [ 'png', 'gif', 'jpg', 'jpeg', 'webp', ];
MediaWiki版本:
1.3 – 1.26
$wgFileExtensions = array( 'png', 'gif', 'jpg', 'jpeg' );
MediaWiki版本:
1.2
$wgFileExtensions = array( "png", "jpg", "jpeg", "ogg" );

示例

$wgFileExtensions是一个php数组,被初始化的默认文件扩展 在LocalSettings.php,你可能用数组操作例如...

// 添加仅仅一个文件类型到默认数组
$wgFileExtensions[] = 'pdf';

// 添加许多文件扩展到默认数组中
$wgFileExtensions = array_merge(
    $wgFileExtensions, [
        'pdf', 'ppt', 'jp2', 'doc', 'docx', 'xls', 'xlsx'
    ]
);

// Override the default with a bundle of filetypes:
// This is usually not a good idea because newer important file extensions could be added in the defaults in later versions of MediaWiki.
$wgFileExtensions = [
    'png', 'gif', 'jpg', 'jpeg', 'jp2', 'webp', 'ppt', 'pdf', 'psd',
    'mp3', 'xls', 'xlsx', 'swf', 'doc', 'docx', 'odt', 'odc', 'odp',
    'odg', 'mpp', 'pptx'
];

参见