Manual:Wiki family/zh

此页将引导你通过安装和配置一个小的wiki-family(维基農場).

方案 1: 在一个服务器上通过虚拟主机安装多个wiki
这种方法利用了符号链接在一个Unix-based系統. 这种技术也可以用在Windows系统里面，透過安装程序 (连接, 连接的外壳扩展) 提供符号链接或使用集成在新版本的Windows命令mklink”.

如何使用"虚拟目录" 操作多个Wiki在一台服务器上，, 使用相同的源代码 (即页面文件使用单组MediaWiki文件), 使用同一个数据库, 在基于共享主机的Unix-based系統中:

请参见解决方案， 包含一步一步的详细说明： http://www.steverumberg.com/wiki/WikiHelp_-_Method_One

请注意， 使用类似于维基百科语言子域（ps：意思就是说使用不同的域名前缀） (例如.example.com, fr.example.com 等) 会让你产生上述链接的方法2的能力的同时，通过Web服务器的虚拟主机的能力提供一个使用简单的两维基分化.

方案 2：快速设置
你要安装 多个维基在单个服务器上, 使用 相同的源代码 (即，单组MediaWiki文件), 和使用相同的数据库？

前置作業

 * 1) 上傳MediaWiki的檔案到支援PHP5的網頁伺服器的Web用的資料夾裡(需解壓縮)
 * 2) 使用網頁遊覽器到該上傳MediaWiki的網址跑安裝程序, 完成後先下載設定檔LocalSettings.php

A型：使用主機名稱區分

 * 1) 在網頁伺服器上, 設定虛擬主機, 指向同一份MediaWiki的檔案
 * 2) 將原本安裝程序所產生的LocalSettings.php, 依實際網站名稱, 改名; 並修改內容, 加上幾個變數
 * 3) * $wgServer (主機名稱的Url)
 * 4) * $wgLogo (Logo的位置)
 * 5) * $wgUploadDirectory (上傳圖檔的實際路徑)
 * 6) * $wgUploadPath (上傳圖檔後, 所使用的圖檔 Url 前置)
 * 7) 在原本放的MediaWiki的檔案的資料夾裡放另一份LocalSettings.php, 例如像是

B型：使用資料夾名稱區分
1.在網頁伺服器上, 網站的根目錄修改 .htaccess, 設定轉址, 例如MediaWiki放在 wiki 資料夾裡 IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*

RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^wiki1/(.+)$ wiki/$1 [PT,L,QSA] RewriteRule ^wiki1/$ wiki/index.php [PT,L,QSA] RewriteRule ^wiki1$ wiki/index.php [PT,L,QSA]

RewriteRule ^wiki2/(.+)$ wiki/$1 [PT,L,QSA] RewriteRule ^wiki2/$ wiki/index.php [PT,L,QSA] RewriteRule ^wiki2$ wiki/index.php [PT,L,QSA]

 order allow,deny allow from all 

php_flag magic_quotes_gpc Off 2.將原本安裝程序所產生的LocalSettings.php, 依實際網站名稱, 改名; 並修改內容, 加上幾個變數
 * $wgLogo (Logo的位置)
 * $wgUploadDirectory (上傳圖檔的實際路徑)
 * $wgUploadPath (上傳圖檔後, 所使用的圖檔 Url 前置)

3.在原本放的MediaWiki的檔案的資料夾裡放另一份LocalSettings.php, 例如像是

其他(待清理的內容)

 * 1) Install prerequisites.
 * 2) Upload MediaWiki files to web folder on the webserver.
 * 3) From browser, browse to the uploaded folder (for example, if your web server is running as   and MediaWiki files were uploaded to   folder, then the URL would be  ) which will lead to a page which gives a link to Please set up the wiki first. Click the link, fill-in the setup form, and install the first wiki (e.g., MyWiki). For details, see Manual:Config script.
 * 4) After successful installation, move LocalSettings.php into the root directory of your wiki and rename it in such a way to make it easy to track (e.g., LocalSettings_myFirstWiki.php)
 * 5) Repeat step three and four above for each wiki you wish to create, creating a new LocalSettings.php file for each wiki (e.g., LocalSettings_anotherWiki.php, etc.)
 * 6) If two or more separately installed wikis are to be merged to operate out of files of the main wiki, then after renaming and moving each of your LocalSettings.php files to the main wiki folder, change the variable $wgScriptPath in the each of the LocalSettings.php files to point to the main wiki's folder.
 * 7) Create a LocalSettings.php file for your global settings, then select one from the two possibilities below:


 * If you have different domains/subdomains that link to one directory on your server, use this:


 * To link your subdomains to one directory on your server, you may have to edit the configuration file for your server (cannot be done with a  file, try changing   there in Apache web server setup) or, if your site has its own IP address, modify the DNS configuration for your site.


 * If your wikis are in different directories (e.g.,   etc) linked to the main wiki directory on your server (say  ), use this:


 * If the function strpos finds the string you search for at the beginning of $callingurl, then the function returns 0 (i.e. it found the string starting at position zero) therefore, you need to change  to.


 * If you use Short URL with the second case (directory based wikis), you need to check the two directories:, to symlink the sources , and adapt.


 * You should use "strpos == 1" or similar instead of plain strpos to avoid redirecting to wrong wiki when the url contains the name after the beginning.

You can use a different unique MySQL database for each wiki (see $wgDBname). OR you can use a different table prefix for each wiki (for Postgres, you can achieve a similar effect by using different schemas) (see $wgDBprefix).

It may also be useful to simply redirect any unrecognized wiki URL to the "main" url, instead of "This wiki (in blah) is not available. Check configuration."

從命令行更新維基農場
This method requires the $_SERVER["SERVER_NAME"] to be present to run maintenance/update.php - which of course it isn't, from the commandline. This can be overcome by creating a simple php script, "update_subdomain.php" (all of this is done in the mediawiki base install directory): You can now run the code with:

It seems to not be possible to run the update script multiple times from the same php script (ie. in a loop), as the runs after the first don't recognise the changed $_SERVER['SERVER_NAME']. (Perhaps try setting the dependent variables directly, as in ?) This can be overcome by creating a bash script to run the php script multiple times (called "update_wikifarm.sh"):

Change the subdomain prefixes to suit your wikifarm, then Make the script executable, and run it:

方案 3：Drupal的风格的网站
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.


 * Create a base directory to contain all your MediaWiki files e.g.,.
 * Install MediaWiki and additional tools as usual to a version-declaring subdirectory(e.g., ).
 * Link the version-declaring directory to a code directory. e.g.,
 * Create a sites directory to contain our images and settings:
 * Setup the wiki as normal from the /code directory.
 * 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.
 * If you intend to use media files, create an images directory in your site directory. e.g., . Make it writable as necessary.
 * Place the Drupal-style LocalSettings.php file in your main directory:
 * Modify the LocalSettings.php of each subsite to point to the right places:
 * First comment out the code relating to, (lines 16-20 in 1.15.3) as this is set to the code directory by.
 * 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.
 * Make further modifications as required.

 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 #  
 * Prepare your Apache 2 installation. Example site: wiki.mysite.com
 * Create a link to the code directory, if required e.g.
 * Create an appropriate VHost configuration:


 * 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 (K)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

方案 4：多個維基分享共有的資源
You want to have some wikis in different languages, sharing the same media-files in another, single wiki.

For example:


 * en.yourwiki.org - English language
 * fr.yourwiki.org - French language
 * de.yourwiki.org - German language
 * pool.yourwiki.org - media-files for all of these wikis (like Commons).
 * As there is already an Interwikilink named commons for Wikimedia Commons, we name our media-files-wiki "pool".
 * Think before being creative; if you call your media-files-wiki something like "media" (e.g. media.example.com), it might collide with internal namespaces and nomenclature for embedded media files ( [[media:file.ext]] ).

安裝
On your file system, create a folder for each wiki. Run the install script for each wiki.

This solution duplicates source code. 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: For example, enter  and then enter''

To do the same in Windows, use

維基配置
It is imperative, that you modify LocalSettings.php of your different wiki installations right from the start (even before creating the symbolic links), or you will have   piling up in your server's memory. Include the line below into each LocalSettings.php. $wgJobRunRate = 0;

Interwiki
Now you have to set Interwikilinks between all wikis, by editing their MySQL-Databases (if you prefer, install and use Extension:Interwiki)
 * Table Interwiki
 *  iw_prefix - enter the language-code of the wikis, "de" for German, "en" for English, "fr" for French and "pool" for the mediapoolwiki
 *  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" !).

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

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.

使用分享的檔案
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

description there. (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

Extension Settings

 * 第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

Wiki Family Settings
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.

Note: If you use a Images/Media commons or pool, we recommend that you do not put these settings in the WikiFamilySettings.php file. That information only applies to every wiki in your wiki family other than your repository. We recommend putting it in a separate file.

Shared database tables
See Manual:Shared database for instructions on setting up shared database tables.

Scenario 5: Multiple wikis through RewriteRules with parent wiki
This approach has elements in common with Scenario 2 above. Be advised that the folks at mediawiki do not recommend using a parent wiki with wikis inside it, the use of a parent wiki is not required. In this scenario, wikis are being deployed for a variety of teams and a url hierarchy was desired to make it obvious where the main/home wiki was located. As such the team wiki urls would need to be one level up from the home wiki. To make this manageable you would need use the same wiki source code and preferably use one database. The approach below has been updated and was tested on Ubuntu 10.04 with 1.18 (This process should work with 1.16+)

Install
Follow steps 1-7 in Scenario 2 to setup the individual wikis, some steps will be explained again for clarity.

Parent Wiki
Unlike the other wikis, the parent wikis LocalSettings.php will for the most part remain untouched as all variables will default to the correct locations and the url for it will be http://domain.com/wiki. Once it has been created rename it to LocalSettings_def.php

Configure
Assuming you are setting up the wikis to use sub-directories (/wiki/wiki1, /wiki/wiki2), define the master LocalSettings.php file in this manner:

Note that in this example if the url designates a non-existant wiki or isn't pointing to one (e.g http://mysite.com/wiki/nowiki or http://mysite.com/wiki/) it will default to LocalSettings_def.php which is the master wiki located at /wiki. Modify the LocalSettings_wiki#.php file for each wiki to give each an unique url:


 * Wiki 1 Local Settings File:


 * Wiki 2 Local Settings File:

Due to how RewriteRules behave, it's best to point to the parent wiki skins directory:

And then to avoid problems with the cache (pages being served up from another wiki with the same title such as Main_Page) you should modify $wgCacheDirectory to point each to a unique directory. When you create the directory verify that the permissions are set to 755 and that the user apache runs under owns it.

It's highly recommended that you created a GlobalSettings.php file to store settings shared across wikis to simplify setup. Primary reason for doing so is if certain variables are not declared the defaults will use $wgScriptPath as the base which can cause problems. Here is an example:


 * GlobalSettings.php

Then simply add this file as an include in each wikis LocalSettings.php file.

Setup Rewrites
In the httpd file you need RewriteRules to map the wikis properly. If you do not have root access to the web server, you can also put this in .htaccess excluding the Directory tags. Assuming the wiki source is installed in /var/www/wiki/, you will want something similar to this:

Take a look at Apache_Rewrite_rules if the above does not work for you.

Shared Users and permissions
Since this use case is for an internal group, sharing users and groups across the wikis is desired to simplify management. To do so we'll use a Shared Database to pull this off. Add the following to GlobalSettings.php:

If you intend to let each team manage access of their wiki, you will need to reset permissions for the roles on other wikis as since the roles are shared across the wiki family a user from wiki1 with role wiki1_sysop that has sysop permissions will retain those permissions in wiki2. Take a look here for a workaround. Once you have done so, you should also read up on Preventing access

Ultimate minimalist solution
The "ultimate minimalist solution" consists of symlinks, $ 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., php update.php. (The above code should detect which wiki's update.php you are referring to.) Upgrading is simple if you download from SVN. (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 Manual:Image Administration, where *.example.org/images/ just point to the same single directory. Or one could use e.g., *.example.org/$wgDBname/images/.

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

刪除舊wiki
To remove a wiki from a production
 * 1) remove its configuration from
 * 2) 網頁伺服器
 * 3) LocalSettings.php
 * 4) DROP DATABASE

Wikimedia Method
Another option is using the method that the Wikimedia Foundation uses. The rough steps are listed below. This method isn't for the faint of heart, but it has fairly good results, as can be seen by the success the Wikimedia Foundation has had by using this :-)  Configure a template copy of MediaWiki through the online configuration wizard. Edit the Main Page if you want a default main page for every wiki you create on your farm. After that, export your database with mysqldump, phpMyAdmin, etc. Save this on your server in the maintenance/ directory as something like . Now, write up a few quick scripts to create a new wiki. In a gist, you'll need to add it to a list of wikis, which can be flat-file based or MySQL/SQLite based, and then import the template database dump back into the database under the name of a new wiki. Use a standard suffix after the new database name (i.e. if the wiki is meta.yourdomain.net, then you might choose metawiki as the database name). In your configuration file, add something like this, fixing the database prefix and your domain as necessary: </li> Configure your DNS with a wildcard A record, and apache with a server alias (like ) and you should be in business.</li> </ol>

The script maintenance/update.php can be included from a another php script, update_farm.php for example, and this outer script will set the various SERVER values that are needed by your LocalSettings.php to set the correct $wgDBname: and the command line for updating meta.yourdomain.net is, from your unique mediawiki directory: php update_farm.php meta.yourdomain.net Your unique LocalSettings.php (which usually consists in a few lines including a CommonSettings.php not directly accessible from the server) decodes the variable meta and will set the $wgDBname accordingly.

The DOCUMENT ROOT directory (similar to the value set in your httpd.conf) can also be used in your CommonSettings.php in order to have more flexibility, like using a test server.

You'll also need to fix the upload directories unless you want every wiki to use the same files. As said above, this is probably one of the hardest methods to do, and it requires more technical experience, but it can give really good, clean results.

Wiki Farm 套件
There are several MediaWiki extensions that attempt to simplify hosting of several wikis by using just one code base:
 * Extension:Farmer
 * Extension:WikiFarm
 * Extension:Simple Farm

另请参看

 * Configuration database
 * Extension:CentralAuth
 * Manual:InitialiseSettings.php & Manual:CommonSettings.php
 * MediaWiki Farmers user group and Wikifarm