手册:Interwiki

本頁使用了標題或全文手工轉換
From mediawiki.org
This page is a translated version of the page Manual:Interwiki and the translation is 68% complete.
Outdated translations are marked like this.

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

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

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

Interwiki链接到其他專案

資料表與 API 查詢

跨 wiki 链接依靠在 MediaWiki 資料库的 interwiki 表中。 您可以使用 API 查询,以 meta 項目為 siteinfo ,屬性為“interwikimap”,检索出跨 wiki 列表,换句话说,通过发出如下API请求 api.php?action=query&meta=siteinfo&siprop=interwikimap

預設

預設情况下,有幾個维基媒体專案(以及其他项目)已經準備好了进行跨wiki链接,因此您可以在不编辑資料库的情况下使用它们。

以下是一些預設情况下可用的跨 wiki 前缀的示例(维基百科在 1.10 版本以後也可以用):

前缀 目标网址 用例
commons https://commons.wikimedia.org/wiki/ [[commons:MediaWiki]]
mediazilla http://bugzilla.wikimedia.org/ [[mediazilla:1209]]
metawikimedia (在1.23版本之前: metawikipedia) https://meta.wikimedia.org/wiki/ [[metawikimedia:Main Page]]

interwiki預設的前缀的完整列表可在maintenance/interwiki.list中找到

請參看m:Help:Interwiki linking以了解從維基媒體專案連結或是連結到維基媒體專案的完整信息。

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

在跨 wiki 链接中添加新网站

  • 跨 Wiki 链接在資料库的interwiki表中设定。
  • 要修改这些,您需要依下面的方式编辑資料库。

建议使用“Interwiki”的扩展,这样可以简化过程。

由于維基百科在1.10版本之前預設為未设置,您可能希望添加它(以及您想要的其他專案)。

下述的示例展示了如何设置w:为到英文维基百科的链接。

請在表中插入一行:

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

interwiki表中。

单筆

高级用户可以使用如下命令:

  • MySQL 与 PostgreSQL
MediaWiki版本:
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);

较新版本的 MediaWiki 需要一些额外的欄位,如:iw_wikiid

INSERT INTO interwiki (iw_prefix, iw_url, iw_api, iw_local, iw_trans, iw_wikiid) 
VALUES ('w', 'https://en.wikipedia.org/wiki/$1', 'https://en.wikipedia.org/w/api.php', 0, 1, '');

匯出、添加、再匯入

另外,您可以使用下面多个步骤,匯出 interwiki 表,添加一行,然後再次匯入:

  • 匯出資料库表 interwiki
  • 在表的最後一行之後添加(使用英文维基百科为例):
('w', 'https://en.wikipedia.org/wiki/$1', 1, 0);
在上面的代碼中,必須在命令行的末尾加上半形分號「;」。 在命令中其他行的末尾只有半形逗號「,」。
  • 匯入資料库表 interwiki

進行测试

要测试配置:

  • 前往您的网站,
  • 创建一个带有以下内容的页面:
    [[w:Wikipedia:Village pump|]]

這應該會顯示一個連結,此連結將鏈接到 en.Wikipedia.org 上的 'Village pump' 頁面(網址 https://en.wikipedia.org/wiki/Wikipedia:Village_pump)

欄位說明

Further information: Manual:Interwiki table


维基管理员技巧: MediaWiki.org 的「手冊」名字空間中有幾個說明頁面。 要讓這些說明頁面鏈接在您的本地 wiki 上生效,請添加一個帶有 iw_prefix=manualiw_url=http://www.mediawiki.org/wiki/Manual:iw_prefix=manual 的跨 wiki 鏈接


维基管理员技巧: 如果要讓新的跨 wiki 設定生效,你應該在 LocalSettings.php 中設定好 $wgTranscludeCacheExpiry 。 或者,您也可以刷新本地 wiki 上的 transcache 表。

跨 wiki 链接到其他语言

其他语言的跨 wiki 链接

如果您安裝了 Manual:Wiki family ,您能夠將英文頁鏈接到德文頁(如果您也有德語的專案項目)。 您可以设置 MediaWiki ,讓侧边栏的工具選單下方,显示出这些链接。

在您的 MediaWiki 安装檔案系统中,有一个名为「languages」的子資料夹。 參看其中的Names.php ,其中包含了已知語言及其前綴的列表。 例如,如果您想添加您的德語項目,請在 Names.php 中找出 Deutsch 並記下前綴為 de 。

如果知道了正確前綴,請通過向資料表 interwiki 添加新行來編輯您的數據庫:

iw_prefix *iw_prefix:語言前綴(例如德語的 de ),列表在 Names.php
iw_url *iw_url:您的 wiki 專案的 URL(例如 http://de.example.org/index.php/<code><nowiki>http://de.example.org/index.php/$1</nowiki>)
iw_local *iw_local:同上「添加更多」
iw_trans *iw_trans:同上「添加更多」

现在,您可以将頁链接到其他语言但相同頁名的頁了。 加上 [[de:Hauptseite]] 在您的英語 Main_Page 上,將在工具箱下方創建一個鏈接「Deutsch」,該鏈接指向德語 wiki (Hauptseite) 的 Main_Page。

請注意,此鏈接「只」顯示在側邊欄的部分,而不是在文章內部。 如果要在頁內創建鏈接,則必須在前綴前添加半形冒號「:」 [[:de:Hauptseite]] 或將 $wgInterwikiMagic 設置為 false 。

從 wiki 匯出 interwiki 資料表

以下 JavaScript 代码执行 API 查询,以检索现有 Wiki 的跨维基地图,然后显示 SQL INSERT 语句以在新 wiki 上補充跨维基資料表。例如,您可以通过通过浏览器的开发人员工具注入代码,或将其放置在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);
	});
}

$(ExtractInterwikiMapTable);

Interwiki links versus external links

''[[imdbtitle:0389790|Bee Movie]]''Bee Movie
[http://www.imdb.com/title/tt0389790 Bee Movie]Bee Movie

Linksearch works for the latter only.

Wikitext using interwiki links isn't always easily transferable between different wikis because they don't consistently use the same interwiki prefixes, or they might not have them at all. Additionally, interwiki links can sometimes mislead users since they don't know when they're being sent to another site.

You can choose between "extiw" and "external text" CSS classes for links, depending on whether you want them to look the same or different. Using just the interwiki link is easier to type, but copying the URL from the webpage is handy. Templates like w:Template:imdb title can be set up to use either an interwiki link with a parameter like "tt0389790" or "0389790", or an external link with a parameter like one of those or the full URL, making it easier to include IMDb references.

Interwiki links to the local wiki

Interwiki links can be configured to point to the same wiki they are being rendered from. For example, mw:Manual:Interwiki/zh points to this page. These links are treated identically to internal links and do show up on Special:WhatLinksHere, appear bold if they are a selflink like the above, appear red if the page doesn't exist, etc.

参见