From MediaWiki.org
Jump to navigation Jump to search
This page is a translated version of the page Manual:Interwiki and the translation is 55% complete.

Outdated translations are marked like this.
Other languages:
Deutsch • ‎English • ‎español • ‎français • ‎italiano • ‎polski • ‎português • ‎română • ‎suomi • ‎čeština • ‎русский • ‎ไทย • ‎中文 • ‎日本語 • ‎한국어

跨wiki链接(英语:Interwiki links)是指向其他项目的页面的链接,使用前缀内部链接样式。

跨wiki链接可以链接到(例如)维基百科、维基教科书、维基新闻等的页面或你需要的不同语言的wiki项目。(见手册:Wiki家族 )。

形如[[Wikipedia:Main Page]]的链接将这样出现:Wikipedia:Main Page,并将您重定向至维基百科的首页。


Table and query API

Interwiki链接托管在MediaWiki数据库的interwiki 表中。

该列表可从siteinfo 元数据查询API的interwikimap属性获得,换句话说 api.php?action=query&meta=siteinfo&siprop=interwikimap

警告 警告: interwikimapAPI属性在wikis的使用上给了一个错误的答案,这个属性是interwiki cache (like Wikimedia Wikis) prior to MediaWiki 1.19 (Bug 19838)




前缀 目标网址 用例
commons https://commons.wikimedia.org/wiki/ [[commons:MediaWiki]]
mediazilla http://bugzilla.wikimedia.org/ [[mediazilla:1209]]
meta https://meta.wikimedia.org/wiki/ [[meta:Main Page]]


See m:Help:Interwiki linking for complete information on linking from/to Wikimedia projects.

在某些安装中,这些都没预安装。 这种情况下请尝试[[metawikipedia:Main Page]]


  • 跨Wiki链接在数据库的interwiki表中设定。
  • 要修改这些,您需要编辑数据库,就像下面一样。
  • 您可能比较愿意安装Interwiki扩展,这能够简化上述操作。


由于Wikipedia 默认情况下在1.10版本之前未设置,您可能希望添加它(以及您想要的其他项目)。



('prefix', 'URL format string', 1, 0)




  • MySQL与PostgreSQL
MediaWiki版本s: 1.10 – 1.16
INSERT INTO interwiki (iw_prefix, iw_url, iw_local, iw_trans) VALUES ('w', 'https://en.wikipedia.org/wiki/$1', 1, 0);




  • 导出数据库表interwiki
  • 在表的最后一行后添加(使用英文维基百科为例):
('w', 'https://en.wikipedia.org/wiki/$1', 1, 0);
In the above code, the semicolon ';' as seen, MUST be at the end of the table. At the end of any other line within that table Only has ','.
  • 导入数据库表interwiki



  • 前往您的网站,
  • 创建一个带有以下内容的页面:
    [[w:Wikipedia:Village pump|]]
  • This should display a link to the 'Village pump' page on en.Wikipedia.org (the url https://en.wikipedia.org/wiki/Wikipedia:Village_pump)


In detail, the fields of the interwiki database table are as follows:

  • iw_prefix: choose a prefix, which is used for interwiki linking, e.g. "wikipedia" for linking to Wikipedia.
  • iw_url: enter the project's URL, e.g. https://en.wikipedia.org/wiki/$1 for Wikipedia. Don't forget the $1 as it is replaced with the article's name you are linking to ([[Wikipedia:Main Page]] links to https://en.wikipedia.org/wiki/Main_Page).
    If iw_url is a binary BLOB field (SVN version, but also occurs in version 1.11.0, bug?) this won't work directly. You have to enter it as binary. There are two possible solutions: 1. You save the url in a plain text file, then import it through phpmyadmin. 2. You can directly enter an SQL query.
  • iw_local: if 1, your wiki will redirect even external links of the form iw_prefix:title, not only those from its own pages; you need this if you want to use the redirect functionality from outside your wiki or other wikis use your transwiki functions for nested transwiki links (like w:en:fr:Wikipédia:Accueil). See m:Help:Interwiki linking#Non-local interwikis. Requires a protocol to be specified in iw_url.
  • iw_trans: "transwiki transclusion" - set to 1 if you want to use pages from the other wiki as templates. You will also need to set $wgEnableScaryTranscluding = true in your LocalSettings.php. Requires a protocol to be specified in iw_url.
  • iw_api: URL to the MediaWiki API, e.g. https://en.wikipedia.org/w/api.php (optional).
  • iw_wikiid: Database name of the wiki (If locally accessible). May be used (later?) for interwiki transclusions. (optional)

Tools.svg 维基管理员技巧: Several help pages link to MediaWiki.org's Manual namespace. To make these links work on your local wiki, add an interwiki link with iw_prefix=manual and iw_url=http://www.mediawiki.org/wiki/Manual:$1

Tools.svg 维基管理员技巧: $wgTranscludeCacheExpiry in your LocalSettings.php should be set if changes in the transcluded wiki are done. 或者,您可以刷新本地wiki上的表transcache



If you have installed a Wiki family , you can link from an article in English to an article in German (if you have a German project, too). 您可以设置MediaWiki,以便在工具栏下方的侧边栏中显示这些链接。

在您的文件系统中,有一个名为“languages”的MediaWiki安装的子文件夹。 Go there and have a look at "Names.php " as it contains a list of known languages and their prefixes. E.g. you want to add your German project, search "Names.php" for "Deutsch" and note the prefix "de".

If you know the "right" prefix, edit your database by adding a new line to table interwiki:

  • iw_prefix: language-prefix (e.g. "de" for German), which is listed in "Names.php"
  • iw_url: URL to your wiki-project (e.g. http://de.example.org/index.php/$1)
  • iw_local: same as above "Adding More"
  • iw_trans: same as above "Adding More"

现在,您可以将文章链接到其他语言的相同。 Adding [[de:Hauptseite]] on your English Main_Page will create a link "Deutsch" below the toolbox, which leads to the Main_Page of the German wiki (Hauptseite).

Note, that this link is shown in Sidebar's section, only, and not inside of the article. If you want to create a link inside of the text, you have to add a colon previous to the prefix: [[:de:Hauptseite]] or set $wgInterwikiMagic to false.

Exporting the interwiki table from a wiki

以下JavaScript代码可用于生成SQL INSERT语句,以便在wiki中运行时填充interwiki表,例如,通过浏览器的开发人员工具注入代码或将其放在Special:MyPage / <skinname> .js和预览:

function ExtractInterwikiMapTable() {
	$.getJSON(mw.config.get('wgScriptPath') + '/api.php?action=query&meta=siteinfo&siprop=interwikimap&format=json', function(data) {
		var iw_prefix, iw_url, iw_local, iw_api, re_escape = /(')/g, result = '';
		for (var i = 0, iwm = data.query.interwikimap; i < iwm.length; i++) {
			iw_prefix = "'" + iwm[i].prefix.replace(re_escape, '\\$1') + "'";
			iw_url = "'" + iwm[i].url.replace(re_escape, '\\$1') + "'";
			iw_local = (typeof iwm[i].local == 'string') ? '1' : '0';
			iw_api = "'" + (iwm[i].iw_api || '').replace(re_escape, '\\$1') + "'";
			result += 'INSERT INTO interwiki (iw_prefix, iw_url, iw_local, iw_trans, iw_api) VALUES ('+iw_prefix+', '+iw_url+', '+iw_local+', 0, '+iw_api+');\n'
		$('<textarea style="width:800px;height:400px;"/>').val(result).appendTo(document.body);




  1. 使用Extension:Interwiki 时,确保使用2.1及其以后版本,它修复了缓存延迟的问题。