Manual:Configuring file uploads/de

MediaWiki unterstützt das Hochladen und das Einbinden von Mediendateien. Diese Seite beschreibt die technischen Aspekte dieses Features. Siehe Manual:Image Administration/de und Help:Images/de für allgemeine Anwendungsinformationen.

Beginnend mit MediaWiki Version 1.1 ist das Hochladen aus Sicherheitsgründen standardmäßig abgeschaltet. Das Hochladen kann mit einer Konfigurationseinstellung angeschaltet werden. Es empfiehlt sich jedoch, zunächst mehrere Voraussetzungen zu überprüfen.

Stelle sicher, dass das Hochladen in PHP angeschaltet ist
Folgendes muss in der  gesetzt sein (die unter ,  ,   oder   (openSUSE 11.2),   oder bei Windows  unter   zu finden ist):

Wenn das nicht gesetzt ist, können PHP-Skripte nicht die Hochladen-Funktion nutzen und das Hochladen wird im MediaWiki nicht funktionieren.

Wenn der -Befehl gesetzt ist, muss er das Zielverzeichnis für das Hochladen in der MediaWiki-Installation  und das  -Verzeichnis (das ist das Standardverzeichnis, wenn nicht anders konfiguriert). The addition of the 'upload_tmp_dir' can avoid messages like "Could not find file "/var/tmp/php31aWnF" (where in this example the 'upload_tmp_dir' is '/var/tmp'). Lies mehr über das Hochladen von Dateien mit PHP in den File upload basics (englisch) und spezieller unter move_uploaded_file (englisch).

Note|Der formale Inhalt der Variablen ist ein boolscher Ausdruck. PHP liest jeden String, der nicht den Wert FALSCH hat als WAHR, deshalb führt der oft verwendete Wert ON zum gleichen Ergebnis.

Prüfungen für Windows- und IIS-Benutzer
Setze für %SystemRoot%\TEMP die Rechte als Internetgastaccount (IUSR_Rechnername, oder IUSR für IIS 7+): Lesen, Schreiben und Ausführen;

Prüfe die Verzeichnissicherheit
Das Hochladeverzeichnis muss so konfiguriert sein, dass es einem Endbenutzer (jemand, der sich das Wiki mit einem Browser ansieht) nicht möglich ist, andere Skripte hochzuladen und auszuführen, weil das sonst einen Exploit-Zugang zu Deinem Webverzeichnis ermöglichen könnte und das Wiki oder die Webseite zerstört werden könnten.

Setze das -Verzeichnis (oder das  -Verzeichnis in früheren Versionen) auf die Berechtigung  :
 * User kann lesen, schreiben und ausführen;
 * Group kann lesen und ausführen;
 * World kann lesen und ausführen.

Wenn Du  verwendest, stelle sicher, dass das Verzeichnis dem Benutzer gehört, der das PHP-Skript laufen lässt (das ist der Apache-Benutzer oder, bei suphp, der Skriptbesitzer).

If using CentOS 6 or Mageia the owner:group in the chown command should be "apache:apache" instead of "www-data:www-data".

Wenn Du SELinux verwendest, stelle sicher, dass die ACLs entsprechend eingestellt sind (siehe dort).

Wenn Du suphp verwendest, stelle sicher, dass  in der   auf   (oder weniger) gesetzt ist.

Beschränke die Anzeige von Verzeichnissen im Bilderverzeichnis
Wenn Du nicht allen Benutzern ermöglichen willst, Dein Bilderverzeichnis einzusehen, könntest Du das in Deiner Apachekonfiguration verhindern:

Das Hochladen An- und Ausschalten
In MediaWiki Version 1.5 und später steht das zu setzenden Attribut in der  und   wird so gesetzt:

Das ermöglicht das Hochladen. Um das Hochladen zu unterbinden, muss man das Attribut auf FALSE setzen:

In älteren Versionen der Software steht das zu setzende Attribut auch in der, wird aber andersherum verwendet, mittels. Der Standard sieht so aus:

Den Wert umkehren, um das Hochladen zu ermöglichen:

Using a central repository
InstantCommons is a feature, enabled with a configuration change, which gives you immediate access to the millions of free (freely licensed) files in Wikimedia Commons.

Hochladerechte
Per Standard können alle registrierten Benutzer Dateien hochladen. Um das einzuschränken, musst Du die  ändern:


 * Um normale Benutzer am Hochladen zu hindern:


 * Um eine spezielle Gruppe namens "uploadaccess" anzulegen und den Mitglieder der Gruppe das Hochladen von Dateien zu erlauben:


 * Um automatisch bestätigten ("autoconfirmed") Benutzern ("non-newbie") zu erlauben, Dateien hochzuladen:

Das Recht, bestehende Dateien zu ersetzen wird mit einer anderen Berechtigung gesteuert, genannt :
 * Um normalen Benutzern zu verwehren, bestehende Dateien zu überschreiben:


 * Um automatisch bestätigten ("autoconfirmed") Benutzern ("non-newbie") zu erlauben, bestehende Dateien zu überschreiben:

Wenn ein ForeignFileRepo gesetzt ist, wird das Recht, diese Dateien lokal zu ersetzen mit einer speziellen Berechtigung gesteuert, genannt :
 * Um normalen Benutzern zu verwehren, filerepo-Dateien lokal zu überschreiben:


 * Um automatisch bestätigten ("autoconfirmed") Benutzern ("non-newbie") zu erlauben, filerepo-Dateien lokal zu überschreiben:

Siehe Manual:User rights für Details zu den Benutzerrechten und Manual:Preventing access für mehr Informationen zum Beschränken von Zugängen.

Konfiguration von Dateitypen
Du kannst  in der   hinzufügen, um das Hochladen von anderen Dateitypen zu erlauben. 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.) For Ubuntu:

php.ini can be found at this location. 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 /etc/php5/cli/php.ini as well as one at /etc/php5/apache2/php.ini. If you are using mod_php (most common), it is the php.ini file in /etc/php5/apache2 that is important to change. 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 :
 * 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  in the web.config file:

  

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:



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 $wgAllowJavaUploads.

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.

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

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 $wgDeletedDirectory 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 in a folder on the file system.
 * 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.