帮助:链接

NMFWiki,网易我的世界论坛的百科全书!转载请声明引自NMFWiki。
跳转到导航 跳转到搜索
This page is a translated version of the page Help:Links and the translation is 99% complete.
PD 注意:當您編輯本頁面時,即同意以CC0協議授權您的貢獻。您可以在公有領域帮助页面找到更多信息。 PD

在MediaWiki中有5种类型的超文本链接:

  1. 内部链接:链接到同一個wiki內的其他页面(通常称作“wiki链接”)
  2. 外部链接:链接到其他网站的页面
  3. 内部页面的外部链接:链接到同一個wiki内部的页面
  4. 跨wiki链接:链接到已预先使用特殊前缀字符注册的其他网站
  5. 跨语言链接:链接到已注册为当前wiki的不同语言版本的其他wiki

请注意,上述的表列并不包含分类链接文件链接,两者分别用于放置页面到分类內,及显示图片或其他媒体文件。

内部链接

创建一個指向同一wiki內的页面的内部链接(稱為「wiki链接」),请使用双重方括号的wiki标记,[[就像这样]]。 当您预览或保存您的更改时,您将看到一个可以指向目标页面的链接。 如果页面已存在,链接会显示为蓝色(就像这段话开头的“创建”一词那样);如果不存在,則会显示为红色(因此[[就像这样]]链接实际會被显示为就像这样)。 注意,若wiki的颜色方案已从默认值更改為不同,則颜色可能会不同。 伴隨这种链接到缺失页面的“红字链接”(无论它是否是真的红色)通常就是要让用户创建該页面。

要将任意文本(不一定是页面标题)标记为链接,可使用竖直线或管道符,像這樣:[[Help:Categories|分类链接]]的结果是 [[Help:Categories|]]。

链接目标的首字母通常不区分大小写(除非wiki有其他的配置),这意味着链接开头可以大小写任意(因此How to contributehow to contribute是相同的)。然而,随后的每个字母則必须准确匹配目标页面(因此How to contributeHow To Contribute不是相同的)。页面标题中的空格会表示为下划线(因此How to contributeHow_to_contribute也是相同的),但在链接中使用的下划线会在页面文本中被看见(但这可以使用“竖线”來避免)。

如果链接的页面的标题正是你正在编辑的页面,則其结果根本不是超链接,而只是粗体文本(例如:在本页面上標記[[Help:Links/zh]],得到的结果是Help:Links/zh)。

如果你正在努力创建链接到当前页面的wiki链接,你可能是要链接到页面内特定的「段落」或者「锚点」;請参见下方的例子。

MediaWiki使用pagelinks 表来了解内部wiki链接的動態。

名称/描述 语法 结果
内部链接
[[Main Page]]

[[Help:Contents]]

[[Extension:DynamicPageList (Wikimedia)]]

Main Page

Help:Contents

Extension:DynamicPageList (Wikimedia)

管道链接
[[Help:Editing pages|editing help]]

链接到目标页面中的某一章节或锚点。

[[Help:Editing pages#Preview|previewing]]

链接至同一页面上某个锚点的竖线链接

[[#See also|different text]]

另見meta:Help:Piped link

editing help

previewing

different text

Pipe trick
[[Manual:Extensions|]]

[[User:John Doe|]]

[[Extension:DynamicPageList (Wikimedia)|]]

[[Extension:DynamicPageList (third-party)|]]

如同在DynamicPageList的示例中所示,管道技巧所完成的转换可导致不同链接目标卻有著相同的文本。

Extensions

John Doe

DynamicPageList

DynamicPageList

词尾链接
[[Help]]s

[[Help]]ing

[[Help]]ers

[[Help]]almostanylettersyoulikehere

[[Help]]BUTnotalways

依照所谓的按每种语言本地化後的“linktrail规则”(譯註:/^([a-z]+)(.*)\$/sD)。

Helps

Helping

Helpers

Helpalmostanylettersyoulikehere

HelpBUTnotalways

避免词尾链接
[[Help]]<nowiki />ful advice

[[wikipedia:GNU General Public License|GPL]]<nowiki />v3

Helpful advice

GPLv3

链接到同一页面上的锚点
[[#See also]]

锚点會在页面的章节标题顶部([[#top]])自动提供。

#See also
为外來的链接设置锚点
<div id="Unique anchor name 1">optional text</div>

<span id="Unique anchor name 2">optional text</span>

分别渲染区块层级和行内。 这样做可以在同一页面上使用[[#Unique anchor name 1]],也可以在不同页面上使用[[Help:Links/zh#Unique anchor name 1]]。 在看某個不可见锚点的功能時,請省略“选配文本”的部份。

在章节标题中设置锚点

==<span id="Alternate Section Title"></span>Section heading==

需要注意的地方: 这里必须是一个span标签,而不是div标签。 (这样的锚点可以在段落更改标题的同时又不破坏外來的链接。)

选配文本

选配文本

Section heading
链接至另一页面上的锚点
[[Help:Images#Supported media types for images]]
Help:Images#Supported media types for images
链接至当前页面的讨论页
[[{{TALKPAGENAME}}|Discussion]]

参见Help:魔术字#页面名

Discussion
链接到子页面
[[/example]]

[[Help:Links/example|/example]]的快捷方式。 参见Help:子页面

/example
链接至子页面而没有开头斜线
[[/example/]]

[[Help:Links/example|example]]的快捷方式。

example
链接到当前页面的父页面的子页面。 只能在子页面上使用。
[[../example2]]

如果您将[[Help:Links/example2|example2]]链接到[[Help:Links/example|example]]那将成为一个重定向。

example2
链至分类页面的可见链接
[[:Category:Help]]

在没有开头冒号时,链接将无法显示,并且页面会被放置在分类中;这是一个常见错误。 另见Help:分类

Category:Help
链至图片或媒体文件的可见链接

File:Example.jpg

file label

Media:Example.jpg

file label

链接至为每个读者指定的页面(用户页等)
[[Special:MyPage]]

[[Special:MyTalk]]

[[Special:Preferences]]

Special:MyPage

Special:MyTalk

Special:Preferences

链至指定修订版本的内部链接
[[Special:PermanentLink/2393992]]

修订的版本可以在每个页面的edit history中找到。 (通常可以看到指向某个修订的版本的链接实现为外部链接,这是因为可以很容易通过复制粘贴来构建外部链接。

Special:PermanentLink/2393992
链接到“差异”的内部链接
[[Special:Diff/2393992]]

[[Special:Diff/2390639/2393992]]

默认情况下(上面的例子中)是显示显示与上一个版本之间的差异, 请看上一个条目中的注释。

Special:Diff/2393992

Special:Diff/2390639/2393992

重定向
#REDIRECT [[Main Page]]

应该是页面上的第一行,也是唯一的一行。 参见Help:重定向

 Main Page

外部链接

要想创建到一个其他网站的页面的外部链接,将URL后空一格加上链接文本,然后全部放入单层方括号中(看下面的例子)。当保存或预览页面时,您将看到一个与外部链接,颜色不同,且可能有一个箭头图标用来表示指向本站以外的其他网站。

描述 您输入的 输出效果
使用指定文字顯示外部連結
[https://mediawiki.org MediaWiki]
MediaWiki
数字表示的外部链接
[https://mediawiki.org]

如果您省略链接文本,则会发生这种情况。 同一页面上此类型的多个链接按顺序编号。

[1]
裸露外部链接
https://mediawiki.org

即使未使用方括号,也将自动链接以“http://”和“https://”开头的URL。

https://mediawiki.org
避免自动链接的URL
<nowiki>https://mediawiki.org</nowiki>
https://mediawiki.org
相對协议URL的外部链接
[//en.wikipedia.org Wikipedia]

[//en.wikipedia.org //en.wikipedia.org]

链接将是HTTP或HTTPS,具体取决于当前正在查看的页面的协议(不同的用户可能会有所不同)。 仅在方括号[ ]中支持此功能。 单独使用“//en.wikipedia.org不会产生链接。

Wikipedia

//en.wikipedia.org

外部链接当前服务器
https://{{SERVERNAME}}/pagename
https://www.mediawiki.org/pagename
外部链接到其他主机并传送本维基页面的名称
https://google.com/search?q={{PAGENAMEE}}

参见URL编码页面名称, Manual:PAGENAMEE encoding

https://google.com/search?q=Links
电子邮件链接
[mailto:info@example.org email me]
email me
发给特定人的邮件链接并且包含主题和邮件内容
[mailto:info@example.org?Subject=URL%20Encoded%20Subject&body=Body%20Text info]
info
自定义 URI
[skype:echo123 call me]

任何你希望添加的URI首先通过$wgUrlProtocols 制定。 (此示例在MediaWiki.org上不會被启用)

[skype:echo123 call me]

Using email links

Email links use mailto: before the address. They're written like this: [mailto:anyone@example.org address name] (resulting in address name). If there's no name, the address is automatically numbered, like this: [mailto:anyone@example.org] becomes [2]. Addresses without square brackets won't be linked, e.g., anyone@example.com. You can also add a CC using [mailto:anyone@example.org?cc=anyone2@example.org address name] (resulting in address name). To add a subject, use [mailto:me@me.com?subject=Me] "

指向内部页面的外部链接

要添加指向同一wiki并使用URL查询参数的链接,你可能需要使用外部链接语法。

描述 您输入的 输出效果
指向当前页面的编辑页面的外部链接
[https://www.mediawiki.org/w/index.php?title=Help:Links&action=edit Edit this page]

[{{fullurl:{{FULLPAGENAME}}|action=edit}} Edit this page]

请参见Help:魔术字#URL数据和上方的外部链接

Edit this page

Edit this page

指向本页面的编辑页的外部链接,看上去像是内部链接
<span class="plainlinks">[https://www.mediawiki.org/w/index.php?title=Help:Links&action=edit Edit this page]</span>

当您想要使得一个外部链接看上去像是内部链接,可以使用 plainlinks 类,来防止一般情况下会出现的小箭头。

Edit this page

The arrow icon

Some skins add an arrow icon after each external link by default. However, this can be avoided by using class="plainlinks". For instance:

  • [http://a a] gives a
  • <span class="plainlinks">[http://a a]</span> gives a

Using Linksearch

Special:Linksearch is a built-in tool that helps find pages linked to a specific URL. By using the externallinks table, it generates a comprehensive list of page names where the link originates, along with the complete target link for each source page. You can search in all namespaces or just one. It supports wildcard (*) use, so you can search by top-level domain (e.g. [3]), second-level domain (e.g. [4]), etc. or refine your search by specifying parts of the URL e.g. [5].

Notes:

  • Avoid including "http://".
  • The program might not return any results if there is a colon in the URL.
  • MediaWiki page names in URLs should have underscores instead of spaces. The Linksearch function also requires underscores in URLs.
  • Linksearch is sensitive to capitalization, multiple underscores, and the use of "index.php". It may not find alternative URLs even if they lead to the same target. Therefore, when creating an external link, it's best to use the canonical form of the URL. If the address bar displays a modified URL after following a link, update the URL in the link accordingly for optimal use of Linksearch.
  • The list is sorted by URL, using standard page name order. Note that an underscore, unlike a blank space, is alphabetically positioned between "Z" and "a".

Using backlinks

Normally, internal links within a project are easy to spot and useful for finding related pages. But when there's a mix of internal and external links, it can be tricky to track backlinks, it necessitates the use of both "Help:What links here" and "Linksearch". However, for links to specific sections or anchors, it's possible to include both an internal link and, with CSS styling using "display=none" an external link to provide backlink.

External links are better than interwiki links.

With Linksearch, you can even find backlinks to specific sections or anchors. So, combining both internal and external links while hiding the external ones "<span style="display:none">http://...</span>", gives us the best of both worlds.

限制

  1. 「外部链接」不支持「字尾链接」。
  2. 「外部链接」不会计入Special:WhatLinksHere(链入页面)。

跨wiki链接

跨wiki链接是指向其他网站的与内部链接相似的链接(尽管名称有“wiki”二字,但不一定指向wiki)。 比如,您可以输入[[wikipedia:Sunflower]]链接到https://en.wikipedia.org/wiki/Sunflower,或者在此维基上输入较短的[[w:Sunflower]]。 两者都会产生一个wikipedia:Sunflower的链接。 之所以可行,是因为默认情况下,MediaWiki将wikipedia:配置为“跨维基前缀”,当在[[]]中使用时,它会链接到https://en.wikipedia.org/wiki/ (如果您的wiki的管理员更改了设置,则可能无法使用。)不像内部链接,跨wiki链接不检查页面是否存在,所以跨wiki链接常显示为蓝色,无论远程wiki的页面是否存在。

就像内部链接一样,您也可以建立管道链接,替换链接的名称, 比如:[[wikipedia:Sunflower|big yellow flower]]生成big yellow flower[[wikipedia:Sunflower|]] 生成 Sunflower

基本上,跨wiki链接是常用的较长的外部链接的缩写。非常相似的链接可以 [http://en.wikipedia.org/wiki/Sunflower big yellow flower]创建。

更多详情位于手册:Interwiki m:Help:Interwiki linking

您的wiki可能有一个Special:Interwiki页面,列出了它支持的跨wiki前缀;这是默认的跨wiki列表。 您可以在您的站点编辑interwiki 表格。

跨语言链接

如果您的wiki有其他语言的版本,您将在sidebar中发现其他语言链接,就在工具箱下方的「其他语言」章節。

在wiki中,标记跨语言链接看上去与内链非常相似,但是其行为类似于分类链接,因为会以特殊方式渲染。

分类链接(通常)在页面底部的特殊的列表中出现,而跨语言链接则出现在页面的侧边栏中的特殊列表中(或者其他地方,取决于wiki的配置和使用的皮肤)。

跨语言链接的目的是链接相同主题不同语言的页面。 要创建跨语言链接,请在页面的任意地方(通常是底部,类似于分类链接)输入[[语言前缀:页面名称]],语言前缀是指为你的wiki指定的另一语言版本的前缀(通常是ISO 639-1语言代码)。

跨語言鏈接是單向的,不會从其他語言的頁面指回来。 為此,也需要在其中放置等效的反向鏈接。 语言链接不能像维基百科語言版本的“語言”章节中的“編輯鏈接”那樣生效, 但是它可以在所有命名空间中使用,包括“User:”以指向其他語言的其他配置文件。

如果您只想将跨语言链接显示在页面内容的某个地方,而非显示在侧边栏上,可在语言前缀之前添加一个半角冒号:

[[:zh:向日葵]]zh:向日葵

当链接不仅跨wiki而且跨语言,那就是wikipedia:zh:向日葵

更多信息请参见m:Help:跨wiki链接#跨语言链接

Anchors

Linking to an anchor

Links in the format [[#anchor_name]] will direct to the first matching anchor on the page, typically corresponding to the first identical section heading.

You can add an [[#anchor_name]] to a link, directing it to the first matching section heading (or anchor) on the named page:

[[Help:Editing#Advanced editing]]

https://www.mediawiki.org/wiki/Help:Editing#Advanced_editing

Using an automatic anchor

Section headings serve as anchors, using the heading text as the anchor name. If there are multiple sections with identical headings, each subsequent occurrence is appended with "_2", "_3", etc.

The anchor #toc links to the page's table of contents, except when there's a section titled "toc."

A manual anchor

Manually-set anchors are beneficial for linking to "unlinkable" elements such as tables (titles or cells) or sections of plain text. For instance, in the External links to internal pages section above, although the column text "Description" resembles a (minor) heading, it is not.

There are several methods to set an anchor at any position:

  • The "anchor" template, if it exists on your wiki, specified as {{Anchor }}, offers a standardized method to create anchor points. Place the template where you want, using the syntax {{Anchor|Name_of_Anchor}}. For instance, {{Anchor|Description}} is placed in the "Description" column of the table below the "External links to internal pages" section. Clicking on #Description links to that anchor point created on the table. The anchor is only visible via the source code.
  • Use the generic anchor tag <span id="anchor_name">some text</span> with optional text for visible anchors. For hidden anchors, omit the text. To point to the anchor use [[#anchor_name]].
  • Avoid using manual HTML headings like <h2>Editing Instructions</h2>. This text serves as an anchor_name.
  • In certain instances, adding an ID attribute similar to HTML within a Wiki-element is necessary. Take, for instance, the table mentioned earlier, titled External links to internal pages:
border="1" class="wikitable" id="You type"
  • A top of a page can be accessed using the reserved term [[#top]].

See also Help:Section#Linking sections using an arbitrary id.

Using Linksearch anchors

As mentioned above, if external link style is used, e.g. [6], we can use Special:Linksearch: [7].

When using Linksearch, it's helpful to add leading zeros to numerical anchor names to prevent unintended matches.

For example, instead of searching for "1", use "01" to avoid including "10". This practice is seen in w:Portal:Current events/DateHeader2. Similarly, if there are anchors like "a" and "ab", using "_a" can distinguish them in search results.

Anchorencode

The #anchorencode parser function encodes input to use as an anchor. For example, to external link to #Using linksearch anchors above, you would use https://www.mediawiki.org/wiki/Help:Links#{{anchorencode:Using Linksearch anchors}}, which resolves to https://www.mediawiki.org/wiki/Help:Links#Using_Linksearch_anchors

Subpage feature

MediaWiki has a subpage feature that may or may not be active depending on the project and namespace. If it's activated, the following rules apply; otherwise, "A/b" is simply a standalone page with that name.

A page's tree structure is formed using forward slashes in page names: A/b is considered a subpage of A, making A the parent of A/b; additionally, A/b/c is a subpage of A/b; meanwhile, A/a, A/b, and A/c are categorized as sibling pages.

The subpage body automatically displays links to all parent pages without needing specific wikitext. These links appear even if the parent page doesn't exist. However, if any ancestor page in the sequence is missing, the chain of links will stop before that point. Additionally, the capitalization of letters after the forward slash in the page name matters, meaning "/subpage" and "/Subpage" refer to different pages.

The functions, What links here and [Help:Related changes|]] do not consider these automatically generated links."

When the subpage feature is enabled within a namespace, any forward slash in a page's name automatically creates a subpage structure, regardless of whether it was intended or not.

You can find a list of subpages using Special:PrefixIndex.

Using variables

When utilizing the subpage feature within namespace A on page A:B/c/d, {{BASEPAGENAME}} shows B/c while {{SUBPAGENAME}} shows d.

Using relative links

Within a subpage hierarchy, you can utilize the following relative links:

  • [[../]] links to the parent page of the current subpage. For example, on page A/b, it takes you to page A, and on page A/b/c, it directs you to page A/b.
  • [[../../]] links to the grandparent page of the current subpage. For example, on page A/b/c, it points to page A.
  • [[../s]] links to a sibling page of the current subpage. For example, on page A/b, it leads to page A/s.
  • [[../../s]] links to an "uncle" page of the current subpage. For example, on page A/b/c, it points to page A/s.
  • [[/s]] links direct to a subpage. On page A, it functions similarly to [[A/s]]. However, linking from a namespace with an enabled subpage feature to a main namespace page starting with "/" requires a workaround: adding a colon before the page name.

Relative links remain functional even when all pages within a hierarchy are renamed to reflect a change in the root's name, even if the root becomes a child of a new parent. Users with the appropriate permissions, such as administrators and those with the move-subpages right, have the option to move both the main page and its subpages during a renaming process.

Learn more about subpages at w:Wikipedia:Subpages. See examples at Help:Link/example and Help:Link/example/example2

Subpage activation

This feature is only enabled in namespaces specified in the $wgNamespacesWithSubpages configuration setting, either its default namespaces, or any additional namespaces set in LocalSettings.php

Character conversion

The guidelines outlined in m:Help:Page name state that in wiki and interwiki links, conversions are made to non-literal characters automatically. For example,"[[Help:Page%20name]]" will display as "m:Help:Page name". Conversely, external links operate oppositely; literal characters are transformed into non-literal characters. For example, browsers typically convert ".../wiki/!" to ".../wiki/%21".

Applying a code like %70 to a redirect deactivates it, even though the link remains accessible from the redirect page. To ensure a successful redirect, the redirect page displays the canonical form of the target, unlike the preview page which shows the link in its regular format.

Miscellaneous

Some additional effects of links

  • Related changes
  • Backlinks, Linksearch
  • When you include a space after the pipe symbol ([[main Page| ]]), the outcome can vary depending on the browser. In some cases, it might only display a space (" "), without creating a clickable link. However, it's still recognized as a link by the "what links here" feature.

"Hover box" on links

In certain web browsers, when you place the cursor over a link, a tooltip may appear, displaying the content of the link's HTML title attribute. MediaWiki assigns different values to this attribute depending on the type of link: for internal wikilinks, it displays the page name and (page does not exist), if the page does not exist; for interwiki links, it displays the page name with a prefix; and for external links, it displays the URL.

The browser might also display similar information in its status bar, possibly showing which section it belongs to.

Using a piped link, even if it isn't clicked, can help clarify acronyms (like displaying "neutral point of view" as NPOV) or adding annotations. Hover boxes can also be created without links, you can customize the hover box content using markup like [[Link title|<span title="hoverbox">Display text</span>]].

You cannot include a title attribute directly within the href element for external links. Nevertheless, you can achieve a similar outcome by using a span element instead, like this:

[http://www.example.com <span title="hover text on external link">www.example.com web site</span>] :
www.example.com web site

Retrieving links from a page

The MediaWiki API allows users to retrieve all links from a page. For example, you can utilize the API query called API:Links to achieve this.

Linking to a page from an image

You can utilize images to direct users to other pages. For further details, refer to the guidance on utilizing an image to link to a specific page in the help section.

限制

內部Wiki鏈接受最大頁面標題大小的限制。

參見