Manual:Extensions/Installation and upgrade/pt
Assim que instalado, o MediaWiki está pronto para aceitar as extensões. Para adicionar uma extensão, siga estes passos:
Antes de começar
- Algumas extensões fornecem instruções criadas para a instalação, utilizando os comandos Unix. Você precisará de acesso à shell (SSH) para inserir estes comandos listados nas páginas de ajuda da extensão.
- Esta página assume que as definições do seu site estão num ficheiro chamado LocalSettings.php , mas se utilizar um ficheiro diferente, por exemplo, num farm wiki, as instruções deverão ser igualmente relevantes.
Transferir uma extensão
Obter o pacote de ficheiros
Para cada extensão, leia a sua documentação para saber mais sobre as localizações e métodos de transferência apropriados. Os modos comuns de transferência de extensões, incluem:
- O 'Distribuidor de Extensões' ajuda-o a selecionar e transferir a maioria das extensões populares, embora nem todos os programadores de extensões necessariamente o recomende.
- Uma lista de extensões guardadas no repositório Git está localizada em git:mediawiki/extensions.
- Algumas extensões também estão disponíveis através de:
- Pacotes
- Composer , um gestor de dependências para as bibliotecas PHP. Muitas extensões podem ou devem ser instaladas utilizando o "Composer". Prossiga para Composer/For extensions para mais informação.
- Repositórios de pacotes
- Algumas extensões não utilizam o controlo de versão e não são recomendadas.
Adicionar o pacote à pasta /extensions
As extensões são normalmente distribuídas como pacotes modulares.
Estes geralmente vão na sua própria subdiretoria do $IP /extensions/
.
Pode adicionar a pasta de ficheiros manualmente ou transferi-la automaticamente se utilizar algo como o "Git" ou "Composer".
Instalar uma extensão
- Always check the requirements and instructions that come with each extension. The following summary applies to most extensions, but many extensions require different and/or additional steps to be taken.
- Ensure that required permissions are set.
- At the end of the
LocalSettings.php
file, add:This line forces the PHP interpreter to read the extension file, and thereby make it accessible to MediaWiki.wfLoadExtension( 'ExtensionName' );
For an earlier installation method using require_once
and how to migrate, see the instructions below.
- Configure if required or wanted. Configuration settings should typically be added after including the extension. Again, check the extension's instructions for details.
- You may be required to run a maintenance script, for instance to add the necessary database tables.
- Concluído!
Problemas possíveis
- Some extensions can conflict with maintenance scripts, for example if they directly access $_SERVER (not recommended). In this case they can be wrapped in the conditional so maintenance scripts can still run.
if ( !$wgCommandLineMode ) { wfLoadExtension ( 'ExtensionName' ); }
- The maintenance script importDump.php will fail for any extension which requires customised namespaces which is included inside the conditional above such as Extension:Semantic MediaWiki , Extensão: Formas de Página .
Adicionar múltiplas extensões para wfLoadExtensions()
Especially if you have a large number of extensions, it may be useful to add them as an array to wfLoadExtensions()
(with plural -s) instead of adding them to separate instances of wfLoadExtension()
(singular).
For instance, to install Cite, ParserFunctions and SpamBlacklist, you could write:
wfLoadExtensions( [ 'Cite', 'ParserFunctions', 'SpamBlacklist' ] );
This method comes with one limitation, which is that you cannot point to custom file locations, as explained in this section.
Atualizar uma extensão
Some extensions require to be updated whenever you update MediaWiki, while others work with multiple versions.
To upgrade to a new version of an extension:
- Download the new version of the extension
- Replace all the extension files in the
extensions/<ExtensionName>
directory with the new files.
Do not remove the extension configuration present in LocalSettings.php
- If the extension requires changes to the MediaWiki database, you will need to run the update.php maintenance script.
Most extensions will mention if this script needs to be run or not. (Perform backup of your data before executing the script). If you don't have command line access, you can also use the web updater.
- Documentation for an extension usually tells you what else you need to do.
Desinstalar
- To uninstall the extension, remove the relevant lines from LocalSettings.php (
wfLoadExtension
with the extension's name as well as any possible lines for associated configuration settings).
- Optionally, delete the file package from the
/extensions
folder.
Avançado
Utilizar localizações personalizadas
This must be done before you load any extensions or skins from non-standard directory locations:
- If you keep your extensions in a location different from
$IP/extensions
, you need to override$wgExtensionDirectory
, or use the second parameter ofwfLoadExtension()
, to specify the directory in which to find the extension.- If one or more of your extensions are stored in additional locations, use the second parameter of
wfLoadExtension()
to specify the location of the.json
file for each of those extensions. wfLoadExtensions()
(plural) always uses$wgExtensionDirectory
and cannot be overridden.
- If one or more of your extensions are stored in additional locations, use the second parameter of
$wgExtensionDirectory = '/some/path'; wfLoadExtension( 'FooBar' ); // Looks in $wgExtensionDirectory for /some/path/FooBar/extension.json wfLoadExtension( 'Hello', '/some/other/path/HelloV2/Hello.json' ); // Looks for /some/other/path/HelloV2/Hello.json
- If your skins are not in
$IP/skins
, you need to override the poorly named$wgStyleDirectory
, or use the second parameter ofwfLoadSkin()
, to specify the directory in which to find the skin.- If one or more of your skins are stored in additional locations, use the second parameter of
wfLoadSkin()
to specify the location of the.json
file for each of those skins. wfLoadSkins()
(plural) always uses$wgStyleDirectory
and cannot be overridden.
- If one or more of your skins are stored in additional locations, use the second parameter of
$wgStyleDirectory = '/my/skins'; wfLoadSkins( [ 'BarBaz', 'BazBar' ] ); // Looks in $wgStyleDirectory for both /my/skins/BarBaz/skin.json and /my/skins/BazBar/skin.json wfLoadSkin( 'BamBam', '/yet/another/path/BamBam/skin.json' ); // Looks for /yet/another/path/BamBam/skin.json
Migrar de require_once
Before MediaWiki 1.25, configuration for extensions and skins was done in a PHP file using the extension's or skin's name, for example MyExtension.php
or MySkin.php
.
To install an extension with LocalSettings.php, you would use require_once
to call this PHP file:
require_once "$IP/extensions/Hello/Hello.php";
require_once "$IP/extensions/FooBar/FooBar.php";
$wgFooBarEnable = true;
require_once "$IP/skins/Baz/Baz.php";
require_once "/tmp/extension/some/where/else/BarFoo/BarFoo.php";
If the extensions are recent enough to support the current registration system, you would convert this to:
wfLoadExtensions( [ 'Hello', 'FooBar' ] );
$wgFooBarEnable = true;
wfLoadSkin( 'Baz' );
wfLoadExtension( 'BarFoo', '/tmp/extension/some/where/else/BarFoo/extension.json' );