Manual:Configuring file uploads/pt

MediaWiki suporta o envio e integração de ficheiros mediateca. Esta página descreve os aspetos técnicos desta funcionalidade, consulte e  para obter informação geral de utilização.

A partir do MediaWiki versão 1.1, os envios estão inicialmente desativados por predefinição, devido a motivos de segurança. Os envios podem ser ativados por meio de uma definição, embora seja recomendável que verifique primeiro certos pré-requisitos.

Pré-requisitos


Certifique-se que os envios estão ativados no PHP
O seguinte precisa de ser definido em :

Se isto não estiver definido, os scripts de PHP não poderão utilizar as funções de envio, e os envios do MediaWiki não serão ativados.

If the open_basedir directive is set, it must include both the destination upload folder in your MediaWiki installation ("{$IP}/images") and the 'upload_tmp_dir' folder (default system folder if not set). 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'). Read more about PHP file uploads at File upload basics and in particular.



Verificar para utilizadores do Windows e IIS
Set  to have permissions for the Internet Guest Account ( _MachineName, or   for IIS 7+): Read, write and execute;



Verificar segurança da diretoria
The upload directory needs to be configured so that it is not possible for an end user to upload and execute other scripts, which could then exploit access to your web directory and damage your wiki or web site.

Defina a pasta  (ou a pasta   em versões anteriores) para ter a permissão "755":


 * Utilizador pode ler, escrever e executar;
 * Grupo pode ler e executar;
 * Mundo pode ler e executar.

If using, make sure to adjust the ACLs accordingly (see there).

Check webserver security
See Manual:Security for changes to make to your webserver configuration to prevent uploaded files from executing code or having browsers execute malicious files.


 * Restrict directory listing on images folder

If you don't want a public user to list your images folder, an option is to set this up in your apache configuration:



verificar ficheiro .htaccess
A diretoria  na pasta de instalação do MediaWiki contém um ficheiro .htaccess com algumas configurações. The goal of this file is to make the upload folder more secure, and if you place your upload directory somewhere else, it's recommended to also copy the .htaccess file to the new location, or apply that configuration on the server directly. However, some of those configurations may cause conflicts or errors, depending on how the server is configured.

Algumas a ter em conta.

If that's the case, you should comment-out the lines, and apply those directives directly on the server configuration files. The directives that are most likely causing the problems are  —which prevents HTML and PHP files from being served as HTML—, and   —which would prevent PHP files from being parsed and executed on the server as such.
 * If the server doesn't allow to set or override directives in .htaccess files, accessing any file under that folder may result in a generic "HTTP 500 error".



Ativar / Desativar os envios
Na versão 1.5 e superior do MediaWiki. o atributo a ser definido reside em "" e é definido como se segue:

Para desativar a função de envio, defina o atributo para false:



Utilizar um repositório central
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.



Permissões de Envio
Por predefinição, todos os utilizadores registados podem enviar ficheiros. Para restringir isto, tem de alterar :


 * Para evitar que os utilizadores normais enviem ficheiros:


 * Para criar um grupo especial chamado de "uploadaccess" (acesso de envio), e permitir que os membros desse grupo enviem ficheiros:


 * Para permitir que os utilizadores "auto confirmados" (não principiantes) enviem ficheiros:

The right to replace existing files is handled by an extra permission, called :


 * 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 :


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



Configurar tipos de ficheiro
You can add in  to allow uploads of other desired file types. For example, you can change the $wgFileExtensions line to look something like

ou

ou

However, certain file extensions are blacklisted 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, 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).

Também pode definir

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.

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



Iniciar sessão
Por predefinição, os envios anónimos não são permitidos. Deve registar-se e iniciar a sessão antes de a hiperligação de "enviar o ficheiro" apareça na caixa de ferramentas.

Criação de Miniaturas
Para informação sobre renderizar/criar miniaturas automaticamente das imagens, consulte . 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.



Definir o número máximo para os envios de ficheiro
Browsers tell the server the size of the file to be uploaded before it actually sends the file.

If the upload is too big, it is rejected by the target (server) and the upload fails providing multiple errors depending at which layer the limit was imposed:


 * If it's a server limit (nginx, Apache) on the maximum amount of transmitted data, it may simply fail with a HTTP 500 error or HTTP 413 – Request entity too large.
 * If the limit it's at the PHP level, if post_max_size is hit, you may get a generic HTTP 500 error (or simply a blank page) otherwise, MediaWiki should give a more meaningful error message.



Por predefinição, o código de configuração em limita o tamanho dos ficheiros a enviar para 2 MB (e o tamanho máximo de um operação posterior de 8 MB). Para permitir o envio de ficheiros grandes, edite estes parâmetros no ficheiro php.ini.


 * , grande de 8 MB por predefinição
 * , grande de 2 MB por predefinição

Isto poderá requerer acesso de root para o servidor. (se estiver num anfitrião partilhado, contacte o seu administrado do servidor)

A localização do ficheiro php.ini varia de acordo com a distribuição que está a utilizar. See for instructions for locating php.ini used by your server.
 * Localizar o ficheiro 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 &lt;Virtual Host&gt;:
 * 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.


 * limites do servidor da Web:

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.

Ubuntu 16.04:

(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 option. This is independent of the hard limit imposed by PHP.


 * limites temporários de envio:

As alterações temporárias aos limites de envio (por exemplo, quando utilizar múltiplas wikis numa farm) podem ser alteradas adicionando as linhas:

ao ficheiro de configuração LocalSettings.php do MediaWiki para cada wiki. Neste exemplo, o limite de PHP está definido em 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

  

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 :

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:



Permitir Envios JAR Java
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 text 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.



Enviar diretamente de um 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.

By default, upload by URL are only possible using the API (or extensions such as ). To make the option usable from Special:Upload, you need to set to  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. 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.



Envio em série
A number of tools are available for uploading multiple files in one go rather than each file separately:

<span id="Upload_directory">

Diretoria de envios
Whenever an image is uploaded, several things are created:

This page is stored and can be edited like any other page. These are stored in the thumb directory of the image directory, in a separate directory for each main file.
 * 1) An article in the file namespace with the name of the file, e.g. File:MyPicture.png.
 * 1) The file itself is stored into the folder on the file system, which is configured in  or into one if its subfolders (see below).
 * 1) If thumbnailing is available, thumbnailed versions of the file will be created when necessary (such as for the usage on the file description page.

If is enabled (by default), MediaWiki creates several subdirectories in the images directory.

If  is set to , 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, all images are uploaded in $wgUploadDirectory itself. (e.g. $IP/images/foo.jpg)

Multiwiki sites

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

Not doing so will mysteriously break image uploads.

Configuring the upload form
The upload form message provided with the default MediWiki installation (which appears when you click "Upload file" link or go to Special:Upload link) may not go very well for you.

For that case you can edit MediaWiki:Uploadtext contents and provide your own text. If your wiki site is multilanguage don't forget to edit localized versions like MediaWiki:Uploadtext/de.

On the MediaWiki:Licenses page you can customize a drop-down list of licenses for uploads of your site. See the documentation of this feature.

Take into account that localized versions like MediaWiki:Licenses/de won't work by default. To enable them you must configure the variable.

Edit MediaWiki:Upload-default-description to add an initial text to the "Summary" field of your upload form (for example your wiki site has a universal template for upload summaries and you want everyone to use that template).

<span id="Known_problems_on_Windows">

Problemas conhecidos no 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 .

Since MediaWiki 1.31 MediaWiki can handle filenames with non-ascii characters if it's using PHP 7.1 or later.

Known problems with database names having non-alphanumeric characters
If  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.

Since MediaWiki 1.26, it allows uploads when contains dots.

<span id="See_also">

Consulte também

 * Secção segurança de envio em «Segurança»
 * Manual:Definições de configuração#Envios para uma lista de todas as variáveis de configuração relacionadas com os envios de ficheiro
 * - similar list as a category (ordered alphabetically)
 * Vê uma página em branco quando tenta enviar um ficheiro
 * Adding support for new filetypes