手册:Wiki农场

This page is a translated version of the page Manual:Wiki family and the translation is 74% complete.

下面是如何设置MediaWiki来托管多个wiki的说明。

座落在同一台服务器上的多个wiki被称为wiki家族wiki农场。在WikiApiary 裏有一個知名wiki农场列表

How wiki farms are handled in maintenance scripts

MediaWiki维护脚本(例如update.php)接受一个--wiki参数,该参数将作为常数MW_DBMW_PREFIXMW_WIKI_NAME传递给你的LocalSettings.php 文件。 --wiki参数的全部值是MW_WIKI_NAME的值。

如果--wiki参数中有一个破折号,那么破折号之前的部分被分配给MW_DB,破折号之后的部分被分配给MW_PREFIX

本表展示了这如何工作:

--wiki的参数是如何被解析的。
--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. 通常情况下,域名和/或URL路径被用来选择一个wiki。

方法

维基农场

以下步骤是在相同版本的MediaWiki中运行多个wiki

  1. 正常安装第一个wiki。 更多资料,請看手册:安装指南
  2. 启用您的Web服务器用来和所有wiki共享您的MediaWiki安装。对于多个(子)域,可以侦听多个服务器名称使用。对于多个子目录,你可以使用重写规则、别名或符号链接。
  3. LocalSettings.php顶部添加如下代码,解析当前wiki。 Note that if the argument to --wiki contains a hyphen, the argument will be split on the hyphen and the resulting two values assigned to MW_DB and MW_PREFIX, respectively. 对于按域名分类的wiki:
    $wikis = [
        'example.org' => 'examplewiki',
        'one.example.org' => 'onewiki',
    ];
    if ( defined( 'MW_DB' ) ) {
        // 自动引用传给维护脚本的--wiki选项
        $wikiID = MW_DB;
    } else {
        // 使用MW_DB环境变量或映射域名
        $wikiID = $_SERVER['MW_DB'] ?? $wikis[ $_SERVER['SERVER_NAME'] ?? '' ] ?? null;
        if ( !$wikiID ) {
            die( 'Unknown wiki.' );
        }
    }
    
    $wgLocalDatabases = $wgConf->wikis = array_values( $wikis );
    $wgDBname = $wikiID;
    $wgDBuser = 'mediawiki';
    
  4. 設定所有wiki必要的不同的设置。例如:
    $wgCacheDirectory = "/tmp/mediawiki_cache/$wgDBname";
    $wgUploadDirectory = "$IP/images/$wgDBname";
    $wgUploadPath = "/w/images/$wgDBname";
    
  5. 設定前一個维基的改写。这应该包括至少$wgServer$wgArticlePath
    $wgConf->settings = [
        'wgServer' => [
            'examplewiki' => 'https://example.org',
            'onewiki' => 'https://one.example.org',
        ],
        'wgArticlePath' => [
            'default' => '/wiki',
        ],
        'wgSitename' => [
            'default' => 'Example',
            'onewiki' => 'One',
        ],
        'wgLogo' => [
            'default' => '/images/examplewiki/Example_logo.png',
        ],
        'wgLanguageCode' => [
            'default' => 'en',
            'onewiki' => 'pt',
        ],
    ];
    extract( $wgConf->getAll( $wgDBname  ) );
    
    这可以从单独的文件完成,例如:
    # LocalSettings.php
    $wgConf->settings = require __DIR__ . '/LocalSettings_overrides.php';
    
    # LocalSettings_overrides.php
    <?php
    return [
        'wgServer' => ..,
        ..,
    ];
    

要创建新的 wiki,请先创建其数据库并添加其设置,然后运行 php maintenance/update.php --wiki=mywiki

单独的设置文件

这种方法是用于操作完全独立的wiki們,但仍共享相同的Web服务器和MediaWiki源代码。

  1. 像往常一样,通过Web或CLI安装程序安装第一个wiki,这会设置您的数据库并生成一个LocalSettings.php 文件。
  2. 安装后,重命名生成的LocalSettings.php文件以包含wiki ID(例如数据库名称),如LocalSettings_mywiki.php
  3. 对要创建的每个wiki重复上述步骤1和2。
  4. 创建一个新的LocalSettings.php文件,该文件将加载正确的文件。 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' ) ) {
    // 自动从--wiki选项设置为维护脚本
    $wikiID = MW_DB;
} else {
    // 使用MW_DB环境变量或映射域名
    $wikiID = $_SERVER['MW_DB'] ?? $wikis[ $_SERVER['SERVER_NAME'] ?? '' ] ?? null;
}

if ( $wikiID ) {
    require_once "LocalSettings_$wikiID.php";
} else {
    die( 'Unknown wiki.' );
}

// 添加需要应用于此行以下所有wiki的所有设置
// -------

如果你的wiki在同一个域上,但路径不同(例如example.org/wiki1example.org/wiki2等),你可以这样操作:

<?php
$wikis = [
    '/example' => 'examplewiki',
    '/w_example' => 'examplewiki',
    '/one' => 'onewiki',
    '/w_one' => 'onewiki',
];
if ( defined( 'MW_DB' ) ) {
    // 自动从--wiki选项设置为维护脚本
    $wikiID = MW_DB;
} else {
    $path = explode( '/', $_SERVER['REQUEST_URI'] ?? '', 3 )[1] ?? '';
    $wikiID = $_SERVER['MW_DB'] ?? $wikis[ $path ] ?? null;
}

if ( $wikiID ) {
    require_once "LocalSettings_$wikiID.php";
} else {
    die( 'Unknown wiki.' );
}
如果您使用短 URL,您需要同时添加$wgArticlePath$wgScriptPath

Drupal样式的网站

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. 示例: 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. 示例: 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. 示例: 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 VHost 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. 注意从命令行运行维护脚本时,配套 Drupal 代码中的 $_SERVER['HTTP_HOST'] 未定义,因此此解决方案不能够在不做修改的情况下使用维护脚本。

Ubuntu 的 Drupal 样式设置方法

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:

多个维基共享公共资源

你希望在一个单独的维基包含一些不同语言的其它维基,它们共享相同的媒体文件。

例如:

  • en.example.org - 英语
  • fr.example.org - 法语
  • de.example.org - 德语
  • pool.example.org - 所有wiki的共享媒体文件。
上面的示例使用名称“pool”。避免使用名称“commons”,因为这可能与interwiki链接冲突,也称为commons表示维基共享资源。 还要避免使用名称“media”(例如media.example.org),因为这可能会导致您的跨维基与用于访问本地媒体文件的内部命名空间Media:(例如[[media:File.png]])之间的冲突。

共享数据表

请考虑对用户帐户使用共享数据库。 有关设置共享数据库表的说明,请参阅 手册:共享数据库

跨Wiki

您可以使用Extension:Interwiki 在所有wiki之间创建interwiki链接。 如果wiki是语言编辑版本,建议在确切的语言代码之后命名跨维基前缀。例如,“de”代表您农场中的德语wiki。 这样,您可以使用语言链接连接有关同一主题的页面。

在英文“主页”上添加[[de:Hauptseite]]将在语言侧边栏中创建一个链接“Deutsch”。 更多信息请参见Help:Interwiki linking

如果你有一个用于文件的中央wiki,也要为此创建一个前缀。 例如,pool 到 https://pool.example.org/wiki/$1,并启用“转发”复选框以将其识别为同一系列中的本地 wiki。

上传

首先确认 pool-wiki 文件夹的“images”权限是可写的。

将language-wikis的"Upload file"链接更改为指向 poolwiki 的上传站点很重要。 打开每种语言维基的“LocalSettings.php”,然后添加:

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

在1.17中,您还必须设置$wgUploadMissingFileUrl才能重定向到红色链接上的pool-wiki。

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

如果想要只允许pool wiki上传,使用以下内容:

if ( $wgDBname === 'pool' ) {
	$wgEnableUploads = true;
} else {
	$wgEnableUploads = false;
}

共享文件

要在语言维基中使用poolwiki的文件,请为每个语言wiki打开“LocalSettings.php”并添加:

$wgUseSharedUploads = true;
$wgSharedUploadPath = 'https://pool.example.org/images';
$wgSharedUploadDirectory = '/(LOCALPATH)/POOL-FOLDER/images/';
$wgHashedSharedUploadDirectory = true;

现在,您可以将池的文件与语言维基中的文件(例如[[File:MyLogo.png]])集成。

图像描述

在每个languagewiki中打开(以管理员身份)消息 MediaWiki:Sharedupload-desc-here

将文本更改为:

该文件存储在数据池中(data-pool)。
有关信息和说明,请访问[[:pool:File:{{PAGENAME}}|描述]]。

(请注意行首的“:”,它阻止“pool”包含在页面左侧的跨维基列表中。)

如果你想输出存储在PoolWiki中的媒体描述,请添加到语言维基的“LocalSettings.php”中:

$wgFetchCommonsDescriptions = true;
$wgSharedUploadDBname = 'pool';  # DB-Name of PoolWiki
$wgSharedUploadDBprefix = 'wiki_'; # Table name prefix for PoolWiki
$wgRepositoryBaseUrl = "https://pool.example.org/index.php/Image:";

wiki農場擴充功能

有几个 MediaWiki 扩展试图通过仅使用一个代码库来简化多个 wiki 的托管,但目前只有一个值得参考:

其它说明

参考