Manual:Wiki family/zh

下面是如何设置MediaWiki来托管多个wiki的说明. 同一台服务器上的多个wiki被称为wiki家族或wiki农场. 知名wiki农场列表在提供.

基本原則
wiki家族最常见的配置是运行同一个版本的MediaWiki. 在此场景中需要执行以下步骤
 * 1) 安装一个普通的MediaWiki站点，安装完得到一个初始数据库. 这可以是完全空的(例如，任何表中没有行)，也可以有任何初始页面、用户、interwiki链接等. 这个是你想要在wiki家族添加多个网站的前提.
 * 2) 设置您的网络服务器以将来自多个地方的流量路由到一个 MediaWiki 安装.  这可以用于多个域、子域或子目录，并且可以通过符号链接、别名、URL 重写或其他机制来完成.
 * 3) 在 LocalSettings.php 中配置该家族，有四个步骤
 * 4) 首先，使用  或 （或类似的）和   常量（和环境变量）来识别不同的 wiki（例如，作为名为   的变量）.  前者用于 Web 请求，后者用于维护脚本（您将传递   参数）.  如果无法识别 wiki，请不要忘记配置这里.
 * 5) 然后，设置基于 wiki 标识的配置变量.  这些包括：
 * 6) 接下来，为每个 wiki 设置不同的配置变量.  这些包括： 这些也可以包含在单独的文件中，例如.
 * 7) 最后，设这LocalSettings.php 其余部分配置的所有常见参数，例如扩展、皮肤等.
 * 8) 可以配置共享资源，例如用户、会话、媒体（即上传）、跨wiki链接等.
 * 9) 在家族中安装一个新的 wiki 就是创建数据库并导入数据库模板，然后运行  .  升级和其他维护任务类似.

本页的其余部分详细说明了上述各个部分. 或许您还想配置共享数据库.

判断来源
这个允许你使用一份代码来安装多个站点基于单台服务器（虚拟主机、VPS、独立服务器），


 * 1) 上传MediaWiki文件到网站根目录
 * 2) 和往常一样安装wiki 更多资料看
 * 3) 安装好之后，拷贝到网站根目录并重命名为一个好记的名字(比如 LocalSettings_myFirstWiki.php)
 * 4) 重复第二、三个步骤，这个目的是为了创建多份（看你要开几个站点久重新安装几次）新的LocalSettings.php文件
 * 5) 如果要合并两个或多个单独安装的wiki到主wiki的文件之外进行操作，则重命名每个LocalSettings.php，并将其移动到主wiki文件夹后，更改每个LocalSettings.php中的变量 指向主wiki的文件夹.
 * 6) 创建全局设置文件LocalSettings.php，从下面的两种情况选择其一.


 * 如果你使用不同的域名链接到服务器的程序所在目录，像这样编写：


 * 如果你使用同一个域名的不同子目录访问你的多个wiki站点，（例如 ， ）你可以这样编写：

建议为每个 wiki 使用不同的数据库（通过为每个 wiki 设置不同的 ）. 但是，如果您只有一个数据库，则可以使用不同的前缀 来分隔不同的安装.

对于任何无法识别的wiki URL，一般显示“此wiki不可用，请检查相关配置”. 如果将它重定向到“主”URL，可能会比较友好点.

使用EXPORT
This method requires the to be present to run maintenance/update.php - which of course it isn't, from the commandline. 这可以通过设置环境变量来解决：

如果使用子目录，那么你可以：

使用 conf 参数
如果您为维基农场中的每个 wiki 使用单独的  ，例如 Giant switch statement中所建议的, 那么你可以使用  参数告诉   使用哪个设置文件. 例如：

Drupal-style sites
As above, this setup allows you to install more than one wiki using different databases on a single server, using the same source code. This setup has the advantage of being completely transparent to users and reasonably secure in terms of the images directory.

 ServerAdmin me@myserver.com DocumentRoot /home/web/wiki.mysite.com ServerName wiki.mysite.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.mysite.com/images # If you want to password protect your site #  #   AuthType Basic #   AuthName "My protected Wiki" #   AuthUserFile /etc/apache2/htpasswd/users-mywiki #  require valid-user #  
 * 1) Create a base directory to contain all your MediaWiki files e.g..
 * 2) Install MediaWiki and additional tools as usual to a version-declaring subdirectory (e.g.,  ).
 * 3) Link the version-declaring directory to a code directory. e.g.,
 * 4) Create a sites directory to contain our images and settings:
 * 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://mysite.com/mywiki, one would create the directory mysite.com.mywiki. e.g.,  . 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.,  .  Make it writable as necessary.
 * 8) Place the Drupal-style LocalSettings.php file in your main directory:
 * 9) Modify the LocalSettings.php of each subsite to point to the right places:
 * 10) First comment out the code relating to , (lines 16-20 in 1.15.3) as this is set to the code directory by.
 * 11) Next insert the following two lines to ensure that image files are accessible, e.g.:  and . These need to be put somewhere after the call to   (line 25 in 1.15.3), as the variables will otherwise be reset.
 * 12) Make further modifications as required.
 * 13) Prepare your Apache 2 installation. Example site: wiki.mysite.com
 * 14) Create a link to the code directory, if required e.g.
 * 15) Create an appropriate VHost configuration:
 * 11. If you are setting the sites up locally, update your  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 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:
 * Ubuntuguide.org MediaWiki tips

多个维基共享公共资源
你希望在一个单独的维基包含一些不同语言的其它维基，它们共享相同的媒体文件.

例如：


 * en.yourwiki.org -
 * fr.yourwiki.org -
 * de.yourwiki.org -
 * pool.yourwiki.org - 所有这些wiki的media-files（如Commons）.
 * 由于Wikimedia Commons已经有一个名为 的Interwikilink，我们将 media-files-wiki 命名为"pool". 
 * 想清楚！ 如果你将你的 media-files-wiki 称为"media''" （例如 media.example.com），它可能会与嵌入式媒体文件[[media:file.ext]]的内部命名空间冲突.

在文件系统上，为每个wiki创建一个文件夹. 为每个wiki运行安装脚本.

此解决方案复制源代码. To reduce this duplication and improve cache performance, you may wish to replace the  (≤ MW 1.20.x), ,  ,  ,  ,  ,   (≤ MW 1.17.x),  ,  ,  ,   and   (≥ MW 1.22.x ) directories for non-pool installations with symbolic links to the pool's directories:

THIS WILL NOT WORK. For example, enter  and then enter

To do the same in Windows, use

跨Wiki
现在你必须通过编辑它们的MySQL-数据库，来设置所有wiki之间的跨wiki链接. （或者安装使用）
 * 跨wiki表
 *  iw_prefix - 输入 wiki 的语言代码，"de"代表德语，"en"代表英语，"fr"代表法语，"pool"代表 mediapoolwiki（wiki媒体池）
 *  iw_url - this is the place for the complete URL to the wikis, e.g. " http://de.yourwiki.org/index.php/$1 " for the German wiki (don't forget the "$1" !).

Enter as many records into table Interwiki than you have different wiki (so one record for German, one for English, one for media for example).

Now you can link an article to the same in another languages. Adding Hauptseite on your English Main_Page will create the link "Deutsch" (under the Navigation bar) which leads to the Main_Page of the German wiki (Hauptseite). For further information visit

Note to page Special:Interwiki: (you will see a long table) Add in the German wiki the prefix 'en' and the url http://en.yourwiki.org/index.php/$1 and set the checkbox 'Als lokales Wiki definiert'. Do it in the English wiki vice versa with checkbox 'Forward'. And in both wikis enter a second prefix 'pool' and http://pool.yourwiki.org/index.php/$1 and check the checkbox 'Forward'.

上传
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:

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

If you want to allow uploads only for your pool wiki, you may use something like this:

使用共享文件
To use poolwiki's files in the languagewikis, open "LocalSettings.php" for each languagewiki and add:

Now you can integrate pool's files with (e.g. ) in the languagewikis.

图像描述
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

在那里描述.

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

共用设置
If you have multiple wikis, you'll probably want to share similar settings across them all. Here is how to do that. We recommend that you separate your Extension settings into a different file than your other settings, as detailed below. They can be all put into one large file, but it's not as flexible depending upon your specific needs.

Here is an example directory structure if you do all of the following:

en/ es/ pl/ ja/ pool/ ExtensionSettings.php WikiFamilySettings.php SharedMediaSettings.php

拓展设置

 * 步骤 1
 * Create a file called ExtensionSettings.php with the following contents, and place it in a location similar to the example above.


 * 步骤 2
 * Edit the LocalSettings.php file of each wiki that you want to use the shared settings, and add the following.
 * 步骤 3
 * Now just add all the references to your various extensions

维基家族设置
These are settings that you want to apply to the entire wiki family. For example, maybe you want to be able to easily put all the wikis into read-only mode at the same time. You can also store the username/password for the database(s), if they are all the same. Additionally, you could control user permissions across your entire wiki from this one file.

共用数据表
See Manual:Shared database for instructions on setting up shared database tables.

Symlink method
The symlinks method was formerly a method that eliminated the need to have redundant copies of MediaWiki on your filesystem while providing flexibility and customization for each wiki. WARNING: As of recent MediaWiki versions, this doesn't work anymore. If you try this, your MediaWiki will break. Instead, it's highly recommended to follow its spiritual successor, the method used by the Wikimedia Foundation (and the method that's used to power Wikipedia, this wiki, and many more!).

$ ls -og lrwxrwxrwx 1 16 2008-11-03 06:29 aaa.example.org -> mediawiki lrwxrwxrwx 1 16 2008-11-03 06:29 bbb.example.org -> mediawiki lrwxrwxrwx 1 16 2008-11-03 06:29 ccc.example.org -> mediawiki

Let's see a real example of. In real life we must deal with the slight differences in the names and databases of the sites we manage.

Note we still individually do database related tasks, e.g.,  (The above code should detect which wiki's update.php you are referring to.) Upgrading is simple if you download from Git. (Hopefully there is no more code that assumes there is only one wiki on the disk...)

图片
Unless you do not allow uploads or allow them only for your pool wiki, you will need to create separate image directories and alias them in your vhost configuration: , and in aaa.example.org's vhost: . Same for bbb and ccc.

However you may instead just prefer, where *.example.org/images/ just point to the same single directory. Or one could use e.g., *.example.org/$wgDBname/images/.

添加新的维基
To add a wiki to a production
 * 1) add its configuration to your web server
 * 1) temporarily comment out the  check of config/index.php and then run it
 * 1) merge the config/LocalSettings.php produced into LocalSettings.php
 * 1) add some pages

删除旧维基
To remove a wiki from a production


 * 1) remove its configuration from
 * 1) web server
 * 1) LocalSettings.php
 * 1) DROP DATABASE

wikimedia使用的方法
另一个选择是使用Wikimedia Foundation使用的方法. This uses only one single MediaWiki directory to provide the backbone for all sites, with the specific wiki being served dynamically determined at page load depending on the value of being sent from the webserver (in WMF's case, Apache) to PHP. 大致步骤如下所示. 这种方法有点小难度，但是效果就像Wikimedia Foundation一样牛逼.  通过在线配置向导或者使用install.php维护脚本来配置MediaWiki的模板副本. 如果您希望农场上创建的每个wiki都有一个默认主页，请编辑Main Page.  然后，通过mysqldump, phpMyAdmin等导出数据库. 如果您希望仅结构化的导出数据库（例如， ），那么您必须使用创建第一个用户. 将其保存在服务器的maintenance/目录中，类似于  现在，编写一些快速脚本来创建一个新的wiki. 总之，您需要复制数据库以获得Wiki列表（该列表可以是基于flat-file、MySQL、SQLite的）. 首先导出模板wiki，然后以每个新wiki的名称将模板数据库转储回数据库. 在新数据库名称后使用标准后缀（即，如果wiki是cat.example farm.org，则可以选择catwiki作为数据库名称）.  根据需要在配置文件中添加如下内容修复数据库前缀和域：  将DNS配置为通配符a记录，将apache配置为服务器别名（比如 ），这样你就可以开始工作了.  

maintenance/update.php脚本和其他所有maintenace脚本一样，都使用一个 参数，该参数被导出为 常量. 您的LocalSettings.php文件需要将其设置为正确的$wgDBname. （这是因为在命令行上没有HTTP请求，因此没有设置"SERVER_NAME". ） For instance:

您唯一的LocalSettings.php（通常由几行组成，包括一个CommonSettings.php，不能从服务器直接访问）使用$wgDBname变量初始化wiki特定的设置. 详见如何使用.

你还需要修复上传目录，除非你想让每个wiki使用相同的文件. If you require the upload directories to be different, consider a more sophisticated setup by modifying $wgLocalFileRepo and/or $wgForeignFileRepos. You may also want to consider a remote server solution. The Wikimedia Foundation uses OpenStack Swift. Furthermore, extensions exist to enable your wiki to use AWS S3 and Azure Storage for remote file storage as well. 如上所述，这可能是最难的方法之一，它需要更多的技术经验，但它可以提供真正好的、干净的结果. For more details on how the Wikimedia Foundation configures their wikis, visit the Wikitech wiki's explanation of the Wikimedia Foundation's MediaWiki architecture.

维基农场拓展
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:


 * - beta

For localisation issues of the and customising the Skins regarding the files ,  ,  ,  ,  ,   respectively:



其它说明

 * 配置数据库
 * MediaWiki Farmers user group and Wikifarm
 * — the mechanism by which user accounts can have an extra 'central' identifier.