Jump to content

Manual:Família de wikis

From mediawiki.org
This page is a translated version of the page Manual:Wiki family and the translation is 23% complete.

Una família de wikis és un conjunt de dos o més wikis que s'executen al mateix servidor i comparteixen un conjunt comú de recursos de la instal·lació principal, mentre que cada wiki roman independent. Aquesta configuració és una alternativa a executar instal·lacions completament separades de MediaWiki. Pot ser l'opció preferida si l'administrador del lloc vol reduir la quantitat de treball que implica la gestió de múltiples wikis o reduir l'ús d'inodes. Per aquest motiu, alguns serveis d'allotjament de wikis opten pel model de família de wikis.

La implementació més coneguda d'una família de wikis és la granja de wikis, tot i que són possibles altres enfocaments. Hi ha disponible una llista de granges de wikis conegudes a WikiApiary .

A continuació es mostren les instruccions sobre com configurar MediaWiki per allotjar més d'un wiki.

Mètodes

Granja de wikis

Els passos següents són per executar diversos wikis a la mateixa versió de MediaWiki:

  1. Instal·leu el primer wiki com de costum. Per a detalls, vegeu Manual:Installation guide .
  2. Assegureu-vos que els vostres futurs wikis puguin arribar al mateix servidor web i instal·lar MediaWiki. Quan utilitzeu (sub)dominis, feu que el vostre servidor web accepti connexions per a tots els amfitrions virtuals (per exemple, a Apache o nginx). If you use Quickstart and localhost, this requires no changes. Quan utilitzeu subdirectoris, podeu utilitzar regles de reescriptura, àlies o enllaços simbòlics.
  3. Afegiu codi a la part superior de LocalSettings.php per detectar el wiki actual. Tingueu en compte que MediaWiki analitza automàticament l'argument --wiki per admetre un guionet opcional, on la primera meitat s'assigna a MW_DB i una segona meitat opcional a MW_PREFIX. Exemple de quan utilitzeu noms de domini:
    // Wiki family
    // https://www.mediawiki.org/wiki/Manual:Wiki_family
    $wikis = [
        'central.localhost:4000' => 'centralwiki',
        'foo.localhost:4000' => 'foowiki',
        'bar.localhost:4000' => 'barwiki',
    ];
    $wgConf->suffixes = [ 'wiki' ];
    $wgLocalDatabases = $wgConf->wikis = array_values( $wikis );
    if ( defined( 'MW_DB' ) ) {
        // Estableix automàticament des de l'opció --wiki als scripts de manteniment
        $wgDBname = MW_DB;
    } else {
        // Utilitzeu la variable d'entorn MW_DB o mapeu el nom de domini
        $wgDBname = $_SERVER['MW_DB'] ?? $wikis[ $_SERVER['HTTP_HOST'] ?? '' ] ?? null;
        if ( !$wgDBname ) {
            die( 'Unknown wiki.' );
        }
    }
    
  4. Configureu paràmetres que han de ser únics per a cada wiki. Per exemple:
    $wgCacheDirectory = "/tmp/mediawiki_cache/$wgDBname";
    $wgUploadDirectory = "$IP/images/$wgDBname";
    $wgUploadPath = "/w/images/$wgDBname";
    
  5. Configureu les redefinicions per wiki. Això hauria d'incloure com a mínim $wgServer i $wgArticlePath.
    $wgConf->settings = [
        'wgServer' => [
            'centralwiki' => 'http://central.localhost:4000',
            'foowiki' => 'http://foo.localhost:4000',
            'barwiki' => 'http://bar.localhost:4000',
        ],
        'wgArticlePath' => [
            'default' => '/index.php/$1',
        ],
        'wgSitename' => [
            'default' => $wgDBname,
            // 'foowiki' => 'Foo',
        ],
        'wgLogo' => [
            // 'foowiki' => '/images/foowiki/Logo.png',
        ],
        'wgLanguageCode' => [
            // 'foowiki' => 'pt',
        ],
    ];
    extract( $wgConf->getAll( $wgDBname ) );
    
    Això es podria fer des d'un fitxer separat, per exemple:
    # LocalSettings.php
    $wgConf->settings = require __DIR__ . '/LocalSettings_overrides.php';
    
    # LocalSettings_overrides.php
    <?php
    return [
        'wgServer' => ..,
        ..,
    ];
    

Per afegir un wiki nou a la família:

  • Creeu una base de dades buida per al wiki i, a continuació, configureu el wiki a LocalSettings.php (almenys el mapa $wikis i una clau a wgServer a $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. Eviteu utilitzar install.php des de la línia d'ordres per instal·lar la base de dades, ja que això es nega a iniciar-se o sobreescriu el vostre fitxer LocalSettings.php.
  • Executeu php maintenance/run.php update --wiki=mywiki

Separate settings files

This approach is for operating entirely independent wikis, but still sharing the same web server and MediaWiki source code.

  1. Install the first wiki as normal, via the web or CLI installer, which sets up your database and generates a LocalSettings.php file.
  2. After installation, rename the generated LocalSettings.php file to include the wiki ID (e.g. database name), like LocalSettings_mywiki.php.
  3. Repeat step one and two above for each wiki you wish to create.
  4. Create a new LocalSettings.php file 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['HTTP_HOST'] ?? '' ] ?? 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.' );
    }
    
If you use Short URL, you need to add both your $wgArticlePath and the $wgScriptPath.

Drupal-style sites

This setup has the advantage of being completely transparent to users and reasonably secure in terms of the images directory.

  1. Create a base directory to contain all your MediaWiki files e.g. mkdir /home/web/mediawiki.
  2. Install MediaWiki and additional tools as usual to a version-declaring subdirectory (e.g., /home/web/mediawiki/mediawiki-1.10.0).
  3. Link the version-declaring directory to a code directory. e.g., ln -s /home/web/mediawiki/mediawiki-1.10.0 /home/web/mediawiki/code
  4. Create a sites directory to contain our images and settings: mkdir /home/web/mediawiki/sites
  5. Setup the wiki as normal from the /code directory.
  6. After successful installation, move LocalSettings.php into 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. e.g., mkdir /home/web/mediawiki/sites/example.com.mywiki. See the Drupal's settings.php file for more information on this.
  7. If you intend to use media files, create an images directory in your site directory. e.g., mkdir /home/web/mediawiki/sites/example.com.wiki/images. Make it writable as necessary.
  8. Place the Drupal-style LocalSettings.php file in your main directory: cp DrupalLocalSettings.php /home/web/mediawiki/code/LocalSettings.php
  9. Modify the LocalSettings.php of each subsite to point to the right places:
    1. First comment out the code relating to $IP, (lines 16-20 in 1.15.3) as this is set to the code directory by index.php.
    2. 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 to DefaultSettings.php (line 25 in 1.15.3), as the variables will otherwise be reset.
    3. Make further modifications as required.
  10. Prepare your Apache 2 installation. Example site: wiki.example.com
    1. Create a link to the code directory, if required e.g. ln -s /home/web/mediawiki/code /home/web/wiki.example.com
    2. 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>
      
11. If you are setting the sites up locally, update your hosts file 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.

Modified Drupal-style method for 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.

If there is a dash in the --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:

How the --wiki argument is parsed.
--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.

Tips for sharing between wikis

You can use $wgForeignFileRepos to share uploaded media files across wikis. This is similar to Wikimedia Commons for Wikipedia.

For example:

  • en.example.org – anglès
  • fr.example.org – francès
  • de.example.org – alemany
  • pool.example.org – Shared media files for all wikis.
The above example uses the name "pool". Avoid using the name "commons" because this may conflict with the interwiki link also named 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]].

Shared database tables

Consider using a shared database for user accounts. See Manual:Base de dades compartida for instructions on setting up shared database tables.

Interwiki

You can create interwiki links between all wikis, by using Extension: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. For further information visit 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.

Upload

Make sure that folder "images" of the pool-wiki is writable.

It is useful to change the "Upload file"-Link of the language-wikis to point to poolwiki's upload-site. Open the "LocalSettings.php" of each language-wiki and add:

$wgUploadNavigationUrl = "https://pool.example.org/index.php/Special:Upload";

In 1.17, you'll also have to set $wgUploadMissingFileUrl to be redirected to the pool-wiki on red links.

$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;
}

Use shared files

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.

Image description

In each languagewiki, open (as an admin) the message MediaWiki:Sharedupload-desc-here.

Change the text to something like:

This file is stored in our data-pool.
For information and description, please visit the [[:pool:File:{{PAGENAME}}|description there]].

(And note the ':' at the beginning of the link target, 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:";

Wiki Farm extensions

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:

See also