Manual:Configuring file uploads/fr

MediaWiki supporte le téléversement et l'intégration de fichiers multimédia Cette page décrit les aspects techniques de cette propriété, voir et Help:Images pour l'usage général des informations.

Existant depuis MediaWiki version 1.1, le téléversement de fichiers est initialement désactivé par défaut, pour des questions de sécurité. Le téléversement de fichiers peut être activé via un paramètre de configuration, bien qu'il soit recommandé de vérifier d'abord certains pré-requis.

Vérifier que les téléversements sont activés en PHP
Les éléments suivants doivent être paramétrés dans le fichier php.ini (pouvant être situé quelque part comme /etc/php/php.ini, /etc/php4/php.ini, /etc/php5/cli/php.ini & /etc/php5/apache2/php.ini (openSUSE 11.2), /usr/local/lib/php.ini ou sur Win32 C:\Windows\php.ini):

Si cela n'est pas paramétré, les scripts PHP ne pourront pas utiliser les fonctions de téléversement, et les téléversements de MediaWiki ne seront pas activés.

Si la directive open_basedir est paramétrée, elle devra inclure à la fois le fichier de destination de téléversement de votre installation MediaWiki ("{$IP}/images") et le 'upload_tmp_dir' (dossier système par défaut si non paramétré). L'ajout du 'upload_tmp_dir' peut éviter les messages comme "Could not find file "/var/tmp/php31aWnF" (où dans cet exemple le upload_tmp_dir' est '/var/tmp') Apprenez-en davantage sur le téléversement de fichiers sur File upload basics et en particulier move_uploaded_file.

Note: La valeur formelle pour la variable est une expression booléenne. PHP traite chaque chaîne non reconnue comme la valeur 'false' comme étant 'true', par conséquent la valeur 'on', souvent utilisée, renvoie le même résultat.

Vérification pour utilisateurs de Windows et IIS
Paramétrez %SystemRoot%\TEMP pour donner au compte invité internet (IUSR_MachineName, or IUSR for IIS 7+): lecture, écriture et exécution;

Vérification de la sécurité du répertoire
Le répertoire de téléversement doit être configuré pour qu'il ne soit pas possible pour un utilisateur final de téléverser et exécuter d'autres types de scripts, qui pourraient alors s'octroyer un accès à votre répertoire web et endommager votre wiki ou votre site web.

Paramétrez le dossier /images (ou le dossier /uploads pour les précédentes versions)pour avoir la permission "755".
 * L'Utilisateur peut lire, écrire et exécuter;
 * Le Groupe peut lire et exécuter;
 * Les Autres peuvent lire et exécuter.

En cas d'utilisation du safe_mode, assurez-vous que le répertoire est la propriété de l'utilisateur qui exécute le script php (qui est l'utilisateur Apache,ou, dans le cas de suphp, le propriétaire du script).

En cas d'utilisation de CentOS 6 ou Mageia, les paramètres "owner:group" de la commande chown doivent être "apache:apache" au lieu de "www-data:www-data".

En cas d'utilisation de SELinux, vérifiez les paramètres ACLs (voir la documentation).

En cas d'utilisation de suphp, vérifiez que le umask a la valeur 0022 (ou moins) dans le fichier /etc/suphp.conf.

Si vous ne souhaitez pas qu'un utilisateur public ait puisse lister votre répertoire d'images, une option est de le paramétrer dans votre configuration apache:
 *  Restriction du listage de répertoire au dossier des images

Vérifier le fichier .htaccess
Le répertoire images du dossier d'installation MediaWiki contient un fichier .htaccess contenant des paramètres de configuration. Le but de ce fichier est de rendre le dossier de téléversement plus sécurisé, et si vous placez votre répertoire de téléversement ailleurs, il est recommandé de copier également le fichier .htaccess vers un autre endroit, ou d'appliquer cette configuration directement sur le serveur. Toutefois, certains de ces paramètres de configuration peuvent être à l'origine de conflits ou d'erreurs, selon la façon dont le serveur est configuré.

Quelques éléments à prendre en compte:

Avant MediaWiki 1.27, si vous avez un gestionnaire 404 personnalisé pour générer des miniatures avec le script, les règles de ré-écriture dans ce fichier .htaccess pourraient annuler les règles pré-existantes, parce qu'il ne dispose pas de l'option.
 * Si le serveur ne permet pas de modifier ou de retirer des paramètres des fichiers .htaccess, demander l'accès à un fichier placé dans ce dossier peut occasionner l'erreur générique "HTTP 500 error". Si tel est le cas, vous devrez décommenter les lignes, et appliquer ces instructions directement sur les fichiers de configuration du serveur. Les instructions qui ont le plus de chances de causer des problèmes sont  - qui empêche les fichiers HTML et PHP d'être renvoyés en HTML -, et   - qui empêche les fichiers PHP d'être parsés et exécutés en tant que tels sur le serveur.

Paramétrer le téléversement sur on/off
Dans MediaWiki version 1.5 ou supérieures, l'attribut qui doit être paramétré dans LocalSettings.php et est paramétré de la manière suivante:

Ceci active les téléversements, comme on peut s'y attendre. Pour les désactiver, paramétrer l'attribut sur 'false':

Dans les versions plus anciennes du logiciel, l'attribut à paramétrer se situe dans LocalSettings.php, mais il est il est placé plus haut, c'est à dire. La valeur par défaut est la suivante:

Inverser la valeur pour activer les téléversements:

Utilisation d'un répertoire central
InstantCommons est une caractéristique, activée par un changement dans la configuration, qui vous donne un accès immédiat aux millions de fichiers libres (dont la licence est libre) de Wikimedia Commons.

Permissions de téléversement
Par défaut, tous les utilisateurs enregistrés peuvent téléverser des fichiers. To restrict this, you have to change $wgGroupPermissions:

$wgGroupPermissions['user']['upload'] = false; $wgGroupPermissions['uploadaccess']['upload'] = true; $wgGroupPermissions['autoconfirmed']['upload'] = true;</tt>
 * To prevent normal users from uploading files:
 * To create a special group called "uploadaccess", and allow members of that group to upload files:
 * To allow "autoconfirmed" (non-newbie) users to upload files:

The right to replace existing files is handled by an extra permission, called reupload</tt>: $wgGroupPermissions['user']['reupload'] = false;</tt> $wgGroupPermissions['autoconfirmed']['reupload'] = true;</tt>
 * To prevent normal users from overriding existing files:
 * To allow "autoconfirmed" (non-newbie) users to replace existing files:

If a ForeignFileRepo is set, the right to replace those files locally is handled by an special permission, called reupload-shared</tt>: $wgGroupPermissions['user']['reupload-shared'] = false;</tt> $wgGroupPermissions['autoconfirmed']['reupload-shared'] = true;</tt>
 * To prevent normal users from overriding filerepo files locally:
 * To allow "autoconfirmed" (non-newbie) users to replace filerepo files locally:

See Manual:User rights for details on user rights, and Manual:Preventing access for more information about restricting access.

Configuring file types
You can add $wgFileExtensions in LocalSettings.php to allow uploads of other desired file types. For example, you can change the $wgFileExtensions line to look something like or or However, certain file extensions are blacklisted ($wgFileBlacklist) and cannot be uploaded even if added to $wgFileExtensions. To upload files with blacklisted extensions, you must modify the blacklist. For instance, to allow users to upload executables: In addition, $wgMimeTypeBlacklist prevents certain file types based on MIME type; .zip files, for example, are prohibited based on MIME type (MediaWiki version 1.14 up to 1.17).

You can also set $wgStrictFileExtensions to allow most types of file to be uploaded. However, blacklisted filetypes and MIME types will still not be permitted.

If you are getting the error "The file is corrupt or has an incorrect extension", make sure mime type detection is working properly.

If you decide to allow any kind of file, make sure your mime detection is working and think about enabling virus scans for uploads.

To enable zip extension (tested in MediaWiki v1.19.23) the following will be necessary in the LocalSettings.php file:

Logon
By default anonymous uploads are not allowed. You must register and logon before the upload file option appears in the toolbox.

Thumbnailing
For information about automatic rendering/thumbnailing of images, see Manual:Image_thumbnailing. For problems with thumbnailing, see Image Thumbnails not working and/or appearing.

If the file is not visual (like an Image or Video) a fileicon is used instead. These are generated by the  function in the File class in the FileRepo group. Icons stored in " " in a " "-format.

Set maximum size for file uploads
By default, the configuration code in php.ini limits the size of files to be uploaded to 2 megabytes (and the maximum size of a post operation to 8 megabytes). To allow uploading of larger files, edit these parameters in php.ini:
 * post_max_size, 8 megabytes large by default
 * upload_max_filesize, 2 megabytes large by default

This may require root access to the server. (If you are on a shared host, contact your server administrator.)

The location of the php.ini file varies on the distribution you are using. (Try "locate php.ini" or "php -i" to find the location of your config file.)
 * Locating the php.ini file

It is important to change the php.ini file in the apache2 folder. For example, there may be a core default php.ini at  as well as one at. If you are using mod_php (most common), the most likely location for the correct php.ini file is in  or. For php-fastcgi, edit /etc/php5/cgi/php.ini.

If you have more than one website hosted on a server and want to change only for Mediawiki, insert into your /etc/apache2/sites-enabled/your_wiki_site.com inside <Virtual Host>:
 * Multiple websites hosted on a server

Both above settings also work in a .htaccess file if your site uses mod_php. If your site uses PHP >= 5.3 and allows it, you can place php.ini directives in .user.ini files instead.


 * web server limits

Your web server may impose further limits on the size of files allowed for upload. For Apache, one of the relevant settings is LimitRequestBody. For Nginx, client_max_body_size is the relevant setting. For Lighttpd, server.max-request-size is what may need modification.

You may need to restart Apache or IIS after altering your PHP or web server configuration. (sudo /etc/init.d/apache2 restart in Linux, for example.)

You may also need to restart php5-fpm after altering your PHP (or ngingx server?) configuration. (sudo /etc/init.d/php5-fpm restart in Linux, for example.)


 * uploading too large of files warning

MediaWiki itself issues a warning if you try to upload files larger than what is specified by $wgUploadSizeWarning option. This is independent of the hard limit imposed by PHP. MediaWiki also has a $wgMaxUploadSize option, but that is currently not enforced for normal uploads (when uploading a local file). The only way of restricting the upload size is through the use of modifying the php configuration.

Temporary changes to upload limits (when using multiple wikis on a farm, for example) can be altered by adding the lines:
 * temporary upload limits

to the MediaWiki LocalSettings.php configuration file for each wiki. In this example the PHP limit is set at 50 Mb. Note that these settings will not override the maximum settings set above (since the core php.ini and apache2 php.ini files set the absolute maximum). This method sets maximums that are less than the absolute maximum.


 * IIS7 upload limit

By default, IIS7 on Windows 2008 allows only 30MB to be uploaded via a web application. Larger files will return a 404 error after the upload. If you have this problem, you can solve it by increasing the maximum file size by adding the following code to <system.webServer> in the web.config file:

<requestFiltering> <requestLimits maxAllowedContentLength="50000000" /> </requestFiltering>

With the above maxAllowedContentLength, users can upload files that are 50,000,000 bytes (50 MB) in size. This setting will work immediately without restarting IIS services. The web.config file is located in the root directory of your web site.

To allow uploading files up to 2G:

add the following lines to LocalSettings.php:

Also, modify the following lines in PHP.INI:

In the IIS web.config file, override the value of maxRequestLength. For example, the following entry in web.config allows files that are less than or equal to 2 gigabytes (GB) to be uploaded:

<httpRuntime maxRequestLength="2097151" executionTimeout="18000"/>

With IIS 7, you also need to configure it to allow large uploads. This is found by clicking “Request Filtering > Edit Feature Settings” in the IIS section in the middle of the window. Set the ”Maximum allowed content length (Bytes)” field to 2147482624. If you don’t see "Request Filtering" in the IIS section, it needs enabled via Internet Information Services > World Wide Web Services > Security in the "Turn Windows features on or off" area in Control Panel.

If the above tip does not enable large uploads, then open a command prompt and execute this command as well:

%windir%\system32\inetsrv\appcmd set config -section:requestFiltering -requestLimits.maxAllowedContentLength: 2147482624

Allowing Java JAR Uploads
By default, MediaWiki will scan all uploads that appear to be ZIP archives and reject any that contain Java .class files. This is a security measure to prevent users uploading a malicious Java applet. For non-public sites only, use the following to disable this check:

This setting can be used as a work around for allowing mimetypes to be accepted indiscriminately. For example, if you attempt to upload a .doc file created by Word 2007, no matter the ext list you provide and mimetype checking you invoke or prohibit, you will receive the message:


 * The file is a corrupt or otherwise unreadable ZIP file. It cannot be properly checked for security.

.doc files saved by Word 2007 (and possibly later versions) contain a small embedded ZIP archive storing metadata that is not representable in the binary .doc format as used by earlier versions of Word. This embedded ZIP data confuses the Java archive scanner, causing the .doc file to be rejected. Files in the newer .docx file format are valid ZIP archives in their entirety, and can be uploaded successfully without setting.

Uploading directly from a URL ("Sideloading")
If you want to allow a user to directly upload files from a URL, instead of from a file on their local computer, set $wgAllowCopyUploads = true</tt>.

By default, upload by URL are only possible using the API (or extensions such as UploadWizard). To make the option usable from Special:Upload, you need to set $wgCopyUploadsFromSpecialUpload to true as well. On the upload form, you will then see an additional field for the URL, below the usual filename field. The URL field is greyed out per default, but can be activated by activating the radiobutton (checkbox) to the left of the field.

In order to use this feature, users must have the user right upload_by_url</tt>. This right was granted to sysops by default until MediaWiki 1.20 but it now needs to be granted explicitly. To allow this to normal users, set Keep in mind that allowing uploads directly from an arbitrary location on the web makes it easier to upload random, unwanted material, and it might be misunderstood as an invitation to upload anything that people might come across on the web.

PHP's cURL support must be enabled to support this feature. Configure your PHP when installing using the --with-curl option. If your server is accessing internet through a proxy then $wgHTTPProxy</tt> needs to be set accordingly. Either you supply it directly or, if your server supplies the environment variable "http_proxy" see your phpinfo, then you could use the following code in your LocalSettings.php:

Undeleting images
Undeleting images is possible as an option since MediaWiki 1.8, and enabled by default since MediaWiki 1.11.

Prior to MediaWiki 1.11, you can enable undeletion of images by setting $wgSaveDeletedFiles = true. Since version 1.11, the behavior is controlled by $wgFileStore, and deleted files are per default stored in $wgUploadDirectory/deleted. Since version 1.17, $wgFileStore has been deprecated and should be used instead.

Mass uploading
A number of tools are available for uploading multiple files in one go rather than each file separately:

Upload directory
Whenever an image is uploaded, several things are created:


 * 1) 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.
 * 2) The file itself is stored into the folder on the file system, which is configured in  or into one if its subfolders (see below).
 * 3) 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.

If $wgHashedUploadDirectory</tt> is set to true</tt>, uploaded files will be distributed into sub-directories of $wgUploadDirectory based on the first two characters of the md5 hash of the filename. (e.g. $IP/images/a/ab/foo.jpg) Creation of such subdirectories is handled automatically. This is used to avoid having too many files in one folder because some filesystems don't perform well with large numbers of files in one folder.

If you only maintain a small wiki with few uploaded images, you could turn this off by setting $wgHashedUploadDirectory = false</tt>, all images are uploaded in $wgUploadDirectory itself. (e.g. $IP/images/foo.jpg)

Multiwiki sites
Not doing so will mysteriously break image uploads.
 * Make sure you've changed the site location in LocalSettings.php from, e.g. /var/lib/mediawiki to wherever your installation is, and created a writeable images directory (most of the rest can be symlinked).

Known problems on Windows
Running MediaWiki on Windows server has some restrictions in allowed filenames, due to a PHP bug. PHP can't handle filenames with non-ascii characters on it correctly, and MediaWiki will refuse to upload files containing such characters to prevent broken uploads, with the message .

Known problems with database names having non-alphanumeric characters
If $wgDBname contains non-alphanumeric characters, uploads may fail with errors like Could not create directory "mwstore://local-backend/local-public/&lt;path&gt;". . This is caused by an internal check for valid container name for file backend, but it's constructed using $wgDBname.

Since MediaWiki 1.26, it allows uploads when $wgDBname contains dots.