Manual:$wgFileExtensions

From MediaWiki.org
Jump to: navigation, search
Uploads: $wgFileExtensions
This is the list of preferred extensions for uploading files. Uploading files with extensions not in this list will trigger a warning.
Introduced in version: 1.2.0
Removed in version: still in use
Allowed values: array of strings
Default value: array( 'png', 'gif', 'jpg', 'jpeg' )

array( 'png', 'jpg', 'jpeg', 'ogg' ) in 1.2

Other settings: Alphabetical | By Function

Details[edit | edit source]

$wgFileExtensions is the list of allowed/preferred extensions for uploading files in LocalSettings.php. It is overridden, however, by $wgFileBlacklist and $wgMimeTypeBlacklist.

If $wgStrictFileExtensions is set to true (default) then this $wgFileExtensions array is the list of allowed extensions, and all others are blocked.

If $wgStrictFileExtensions is set to false, then users will only get a warning when uploading files with extensions not in this list. i.e. $wgFileExtensions is then only a preferred set of extensions. In this case some particularly dangerous file extensions will still be blocked using $wgFileBlacklist and $wgMimeTypeBlacklist.

If $wgCheckFileExtensions is false, this option has no effect since all file extensions will be permitted without performing any checks.

If $wgEnableUploads is set to false, this option has no effect since all uploading is disallowed.

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.

Example[edit | edit source]

$wgFileExtensions is a php array, which is initialised with a default (sensible) set of file extensions. In LocalSettings.php you might use array operations such as...

// Add one filetype to the default array
$wgFileExtensions[] = 'pdf';
 
// Add several file types to the default array
$wgFileExtensions = array_merge( $wgFileExtensions, array( 'pdf', 'ppt', 'jp2', 'webp', 'doc','docx', 'xls', 'xlsx' ) );
 
// Override the default with a bundle of filetypes:
$wgFileExtensions = array( 'png', 'gif', 'jpg', 'jpeg', 'jp2', 'webp', 'ppt', 'pdf', 'psd', 'mp3', 'xls', 'xlsx', 'swf', 'doc','docx', 'odt', 'odc', 'odp', 'odg', 'mpp');

Files without extensions (hack)[edit | edit source]

To allow uploading of files that don't have extensions, you will need to apply the following hack: Edit $IP/includes/SpecialUpload.php and at line 351 (in version 1.11.1), change

  if ($finalExt == '') {
      return $this->uploadError( wfMsgExt( 'filetype-missing', array ( 'parseinline' ) ) );

to

  if ($finalExt == '') {
  /*  return $this->uploadError( wfMsgExt( 'filetype-missing', array ( 'parseinline' ) ) );   */

In other words, comment out the action that is taken if there's no file extension.

in newer MediaWiki versions (>= 1.11.2) you also have to do additional modifications in $IP/includes/SpecialUpload.php

Warning Warning: Remember this is only an untested hack. This will disable the Mime Type check for all files without an extension!

change (around line 1023)

  if ($wgVerifyMimeType) {

to

  if ($wgVerifyMimeType && $extension != '') {

to suppress the warning on the upload dialog add following line to your LocalSettings.php:

  $wgFileExtensions[] = '';

See also[edit | edit source]

Language: English  • français • italiano • 日本語