Manual: Família de Wikis
Uma família wiki é uma coleção de duas ou mais wikis que são executadas no mesmo servidor e partilham um conjunto comum de recursos da instalação fonte, enquanto cada wiki permanece independente. Esta configuração é uma alternativa à execução de instalações completamente separadas do MediaWiki. It may be the preferred choice if the site admin wants to reduce the amount of work involved in managing multiple wikis, or cut down on inode usage. For this reason, some wiki hosting services opt for the wiki family model.
The best known implementation of a wiki family is the wiki farm, although other approaches are possible. A list of known wiki farms is available on WikiApiary.
Em baixo, tem instruções sobre como configurar o MediaWiki para alojar mais do que uma wiki.
Métodos
Farm de Wikis
The following steps are for running multiple wikis on same version of MediaWiki:
- Instale a primeira wiki normalmente. Para detalhes, consulte Manual:Guia de Instalação.
- Ensure your future wikis can reach the same web server and MediaWiki install. When using (sub)domains, have your web server accept connections for all virtual hosts (e.g. in Apache or nginx). If you use Quickstart and localhost, this requires no changes. When using subdirectories, you could use rewrite rules, aliases, or symlinks.
- Add code to the top of
LocalSettings.phpto detect the current wiki. Note that MediaWiki automatically parses the--wikiargument to support an optional hyphen, where the first half is assigned toMW_DBand an optional second half toMW_PREFIX. Example for when you use domain names:// Wiki family // https://www.mediawiki.org/wiki/Manual:Wiki_family $wikis = [ 'central.localhost:4000' => 'centralwiki', 'foo.localhost:4000' => 'foowiki', 'bar.localhost:4000' => 'barwiki', ]; $wgLocalDatabases = $wgConf->wikis = array_values( $wikis ); if ( defined( 'MW_DB' ) ) { // Automatically set from --wiki option to maintenance scripts $wgDBname = MW_DB; } else { // Use MW_DB environment variable or map the domain name $wgDBname = $_SERVER['MW_DB'] ?? $wikis[ $_SERVER['HTTP_HOST'] ?? '' ] ?? null; if ( !$wgDBname ) { die( 'Unknown wiki.' ); } }
- Configure settings that must be unique for each wiki. For example:
$wgCacheDirectory = "/tmp/mediawiki_cache/$wgDBname"; $wgUploadDirectory = "$IP/images/$wgDBname"; $wgUploadPath = "/w/images/$wgDBname";
- Configure per-wiki overrides. This should include at least
$wgServerand$wgArticlePath.This could be done from a separate file, e.g.:$wgConf->settings = [ 'wgServer' => [ 'centralwiki' => 'http://central.localhost:4000', 'foowiki' => 'http://foo.localhost:4000', 'barwiki' => 'http://bar.localhost:4000', ], 'wgArticlePath' => [ 'default' => '/index.php/$1', // 'default' => '/wiki/$1', ], 'wgSitename' => [ 'default' => $wgDBname, // 'foowiki' => 'Foo', ], 'wgLogo' => [ // 'foowiki' => '/images/foowiki/Logo.png', ], 'wgLanguageCode' => [ // 'foowiki' => 'pt', ], ]; extract( $wgConf->getAll( $wgDBname ) );
# LocalSettings.php $wgConf->settings = require __DIR__ . '/LocalSettings_overrides.php'; # LocalSettings_overrides.php <?php return [ 'wgServer' => .., .., ];
To add a new wiki to the family:
- Create an empty database for the wiki, and then configure the wiki in LocalSettings.php (at least the
$wikismap and a key underwgServerin$wgConf). Then use the web installer to install the database. Settings you specify here will not be saved and you can discard the LocalSettings.php file it generates. Avoid usinginstall.phpfrom the command line to install the database, because that either refuses to start or overwrites your LocalSettings.php file. - Executar
php maintenance/run.php update --wiki=mywiki
Separate settings files
Isto irá deixá-lo instalar mais do que uma wiki num único servidor, utilizando o mesmo código fonte.
- Install the first wiki as normal, via the web or CLI installer, which sets up your database and generates a LocalSettings.php file.
- After installation, rename the generated
LocalSettings.phpfile to include the wiki ID (e.g. database name), likeLocalSettings_mywiki.php.
- Repeat step one and two above for each wiki you wish to create.
- Create a new
LocalSettings.phpfile that will load the correct one.
As with the above wiki farm example, a --wiki argument containing a hyphen will be split on the hyphen into two values assigned to MW_DB and MW_PREFIX, respectively.
<?php
$wikis = [
'example.org' => 'examplewiki',
'one.example.org' => 'onewiki',
];
if ( defined( 'MW_DB' ) ) {
// Automatically set from --wiki option to maintenance scripts
$wikiID = MW_DB;
} else {
// Use MW_DB environment variable or map the domain name
$wikiID = $_SERVER['MW_DB'] ?? $wikis[ $_SERVER['SERVER_NAME'] ?? '' ] ?? null;
}
if ( $wikiID ) {
require_once "LocalSettings_$wikiID.php";
} else {
die( 'Unknown wiki.' );
}
// Add any settings that should apply to all wikis below this line
// -------
If your wikis are on the same domain but under different paths (e.g. example.org/wiki1, example.org/wiki2 etc.), you can use something like this:
<?php
$wikis = [
'example' => 'examplewiki',
'w_example' => 'examplewiki',
'one' => 'onewiki',
'w_one' => 'onewiki',
];
if ( defined( 'MW_DB' ) ) {
// Automatically set from --wiki option to maintenance scripts.
$wikiID = MW_DB;
} else {
$wikiID = $_SERVER['MW_DB'] ?? $wikis[ explode( '/', $_SERVER['REQUEST_URI'], 3 )[1] ] ?? null;
}
if ( $wikiID ) {
require_once "LocalSettings_$wikiID.php";
} else {
die( 'Unknown wiki.' );
}
$wgArticlePath and the $wgScriptPath.
Drupal-sites de estilo
This setup has the advantage of being completely transparent to users and reasonably secure in terms of the images directory.
- Create a base directory to contain all your MediaWiki files e.g.
mkdir /home/web/mediawiki. - Install MediaWiki and additional tools as usual to a version-declaring subdirectory (e.g.,
/home/web/mediawiki/mediawiki-1.10.0). - Link the version-declaring directory to a code directory. "exemplo",
ln -s /home/web/mediawiki/mediawiki-1.10.0 /home/web/mediawiki/code - Create a sites directory to contain our images and settings:
mkdir /home/web/mediawiki/sites - Setup the wiki as normal from the /code directory.
- After successful installation, move
LocalSettings.phpinto a sites directory that will be a match when the site is checked. For example, to capture http://example.com/mywiki, one would create the directory example.com.mywiki. "exemplo",mkdir /home/web/mediawiki/sites/example.com.mywikiSee the Drupal'ssettings.phpfile for more information on this. - If you intend to use media files, create an images directory in your site directory. "exemplo",
mkdir /home/web/mediawiki/sites/example.com.wiki/imagesMake it writable as necessary. - Place the Drupal-style
LocalSettings.phpfile in your main directory:cp DrupalLocalSettings.php /home/web/mediawiki/code/LocalSettings.php - Modify the
LocalSettings.phpof each subsite to point to the right places:- First comment out the code relating to
$IP, (lines 16-20 in 1.15.3) as this is set to the code directory byindex.php. - Next insert the following two lines to ensure that image files are accessible, e.g.:
$wgUploadDirectory = "/home/web/mediawiki/sites/wiki.example.com/images";and$wgUploadPath = "/images";. These need to be put somewhere after the call toDefaultSettings.php(line 25 in 1.15.3), as the variables will otherwise be reset. - Make further modifications as required.
- First comment out the code relating to
- Prepare your Apache 2 installation. Example site: wiki.example.com
- Create a link to the code directory, if required e.g.
ln -s /home/web/mediawiki/code /home/web/wiki.example.com - Create an appropriate virtual host configuration:
<VirtualHost *:80> ServerAdmin me@example.com DocumentRoot /home/web/wiki.example.com ServerName wiki.example.com CustomLog /var/log/apache2/wiki.mysite.log common # Alias for the site to be accessible Alias /mediawiki/code /home/web/mediawiki/code # Alias for wiki so images work Alias /images /home/web/mediawiki/sites/wiki.example.com/images # If you want to password protect your site # <Directory /home/web/wiki.example.com> # AuthType Basic # AuthName "My protected wiki" # AuthUserFile /etc/apache2/htpasswd/users-mywiki # require valid-user # </Directory> </VirtualHost>
- Create a link to the code directory, if required e.g.
- 11. If you are setting the sites up locally, update your
hostsfile with the site names. The site should now work.
In my case, I made another copy of the code from which to install and update my LocalSettings.php and databases.
Note that $_SERVER['HTTP_HOST'] in the companion Drupal code is undefined when running maintenance scripts from the command line, so this solution does not permit the use of maintenance scripts without some modification.
Drupal Modificado-método de estilo para o Ubuntu
A simplified method for multiple wikis and multiple (or nested) subwikis on Ubuntu/Kubuntu that is loosely based on the above method can be found at:
How wiki farms are handled in maintenance scripts
MediaWiki maintenance scripts (e.g. update.php) accept a --wiki argument that is passed to your LocalSettings.php file as the constants MW_DB, MW_PREFIX, and MW_WIKI_NAME.
The entire value of the --wiki argument is the value of MW_WIKI_NAME.
--wiki argument, then the part before the dash is assigned to MW_DB and the part after the dash is assigned to MW_PREFIX.This table demonstrates how this works:
--wiki |
MW_WIKI_NAME |
MW_DB |
MW_PREFIX
|
|---|---|---|---|
| enwiki | enwiki | enwiki | empty |
| enwiki-one | enwiki-one | enwiki | one |
| enwiki-one-two | enwiki-one-two | enwiki | one-two |
Since there is no --wiki argument for web requests, they must be handled differently.
Typically, the domain name and/or URL path is used to select a wiki.
Múltiplas wikis a partilhar recursos comuns
Se deseja ter algumas wikis em idiomas diferentes, partilhando os mesmos ficheiros mediateca em outra wiki única.
Por exemplo:
- en.example.org – inglês
- fr.example.org – francês
- de.example.org – alemão
- pool.example.org – Ficheiros de multimédia partilhados para todas as wikis.
commons for Wikimedia Commons.
Also avoid using the name "media" (e.g. media.example.org) as that may cause a conflict between your interwiki and the internal namespace Media: for accessing local media files, e.g. [[media:File.png]].
Tabelas da base de dados partilhada
Consider using a shared database for user accounts. Consulte Manual: Base de Dados Partilhada para instruções sobre a configuração das tabelas da base dados partilhada.
Interwiki
Pode criar as hiperligações de interwiki entre todas as wikis, utilizando Extensão: Interwiki. If the wikis are language editions, it is recommended to name the interwiki prefix after the exact language code. For example, "de" for the German wiki in your family. This way, you can connect pages about the same subject using language links.
Adding [[de:Hauptseite]] on your English "Main Page" will create a link "Deutsch" in the languages sidebar. Para mais informação, visite Help:Interwiki linking
If you have a central wiki for files, create a prefix for this as well.
E.g. pool to https://pool.example.org/wiki/$1 and enable the "Forward" checkbox to recognise it as a local wiki in the same family.
Enviar
Certifique-se que a pasta "images" da wiki pool é gravável.
Isto é útil para alterar "Enviar ficheiro"-Hiperligação das wikis de idioma para apontar para o site de envio poolwiki. Abra "LocalSettings.php" de cada wiki de idioma e adicione:
$wgUploadNavigationUrl = "https://pool.example.org/index.php/Special:Upload";
Na versão 1.17, também irá ter de definir $wgUploadMissingFileUrl para ser redirecionado para a wiki pool nas hiperligações a vermelho.
$wgUploadMissingFileUrl= "https://pool.example.org/index.php/Special:Upload";
If you want to allow uploads only for your pool wiki, you may use something like this:
if ( $wgDBname === 'pool' ) {
$wgEnableUploads = true;
} else {
$wgEnableUploads = false;
}
Utilizar ficheiros partilhados
To use poolwiki's files in the languagewikis, open "LocalSettings.php" for each languagewiki and add:
$wgUseSharedUploads = true;
$wgSharedUploadPath = 'https://pool.example.org/images';
$wgSharedUploadDirectory = '/(LOCALPATH)/POOL-FOLDER/images/';
$wgHashedSharedUploadDirectory = true;
Now you can integrate pool's files with (e.g. [[File:MyLogo.png]]) in the languagewikis.
Descrição da imagem
Em cada languagewiki, abra (como uma aministrador) a mensagem MediaWiki:Sharedupload-desc-here.
Altere o texto para qualquer coisa, como:
Este ficheiro é guardado na nossa ''pool'' de dados.
Para informação e descrição, por favor, visite a [[:pool:File:{{PAGENAME}}|descrição lá]].
(And note the ':' at the beginning of the line, which stops 'pool' from being included in the interwiki list at the left of the page.)
If you want to output the media-description, stored in the PoolWiki, too, add to the "LocalSettings.php" of the languagewikis:
$wgFetchCommonsDescriptions = true;
$wgSharedUploadDBname = 'pool'; # DB-Name of PoolWiki
$wgSharedUploadDBprefix = 'wiki_'; # Table name prefix for PoolWiki
$wgRepositoryBaseUrl = "https://pool.example.org/index.php/Image:";
Extensões da Wiki Farm
There are several MediaWiki extensions that attempt to simplify hosting of several wikis by using just one code base, however only one is currently noteworthy:
- Extension:MediaWikiFarm - beta.
- Extension:SkinCustomiser: For localisation issues of the sidebar and customising the Skins regarding the files
MediaWiki:Cologneblue.css,MediaWiki:Modern.css,MediaWiki:Monobook.css,MediaWiki:Vector.css,MediaWiki:Mobile.css,MediaWiki:Common.cssrespectively.
Consultar também
- Extensão: CentralAuth
- Manual:InitialiseSettings.php
- Manual:CommonSettings.php
- Manual:$wgConf and Manual:SiteConfiguration.php
- Manual: Id. da Central — o mecanismo pelo que as contas de utilizador podem ter um identificador 'central' extra.
- MediaWiki-Docker/Configuration recipes/Wiki farm - config recipe for a Docker container of MediaWiki