设定 MediaWiki 可以上传 zip 档

MediaWiki 默认只能上传 png、gif、jpg、jpeg 这些图档,我们可以在 LocalSettings.php 编辑:

$wgEnableUploads  = false;
$wgFileExtensions = array( 'png', 'gif', 'jpg', 'jpeg' );

加入你额外想要上传的档案类型 (找不到这两行的话就自己加上去):

$wgEnableUploads  = true;
$wgFileExtensions = array( 'png', 'gif', 'jpg', 'jpeg', 'zip', 'pdf', 'rar' );

上面的目的是为了可以额外再上传 zip、pdf、rar 类型的档案。可惜事与愿违,上传 pdf 与 rar 档都没问是,但要上传 zip 档却给我出现:

MIME 类别 "application/zip" 不是容许的档案格式。

原来是因为 MediaWiki 有设一些副档名的“黑名单”,刚好 zip 就在其中,设定档在: includes/DefaultSettings.php

找到内容:

$wgMimeTypeBlacklist= array(
        # HTML may contain cookie-stealing JavaScript and web bugs
        'text/html', 'text/javascript', 'text/x-javascript',  'application/x-shellscript',
        # PHP scripts may execute arbitrary code on the server
        'application/x-php', 'text/x-php',
        # Other types that may be interpreted by some servers
        'text/x-python', 'text/x-perl', 'text/x-bash', 'text/x-sh', 'text/x-csh',
        # Client-side hazards on Internet Explorer
        'text/scriptlet', 'application/x-msdownload',
        # Windows metafile, client-side vulnerability on some systems
        'application/x-msmetafile',
        # A ZIP file may be a valid Java archive containing an applet which exploits the
        # same-origin policy to steal cookies
        'application/zip',
);

将“'application/zip',”删除即可。

至于上传 zip 档未来的后果会是如何...这我就不能预料了。

  1. No comments yet.

  1. No trackbacks yet.

return top

%d 位部落客按了赞: