Links are used to reference pages within MediaWiki, other wikis, or external websites.
在MediaWiki中有5种类型的超文本链接:
请注意,上述的表列并不包含分类链接和文件链接,两者分别用于放置页面到分类内,及显示图片或其他媒体文件。
要创建一个指向同一wiki内的页面的内部链接(称为“wiki链接”),请使用双重方括号的wiki标记,[[就像这样]]
。
当您预览或保存您的更改时,您将看到一个可以指向目标页面的链接。
如果页面已存在,链接会显示为蓝色(就像这段话开头的“创建”一词那样);如果不存在,则会显示为红色(因此[[就像这样]]
链接实际会被显示为就像这样)。
注意,若wiki的颜色方案已从默认值更改为不同,则颜色可能会不同。
伴随这种链接到缺失页面的“红字链接”(无论它是否是真的红色)通常就是要让用户创建该页面。
要将任意文本(不一定是页面标题)标记为链接,可使用竖直线或管道符,像这样:[[Help:Categories|分类链接]]
的结果是 [[Help:Categories|]]。
链接目标的首字母通常不区分大小写(除非wiki有其他的配置),这意味着链接开头可以大小写任意(因此How to contribute和how to contribute是相同的)。然而,随后的每个字母则必须准确匹配目标页面(因此How to contribute和How To Contribute不是相同的)。页面标题中的空格会表示为下划线(因此How to contribute和How_to_contribute也是相同的),但在链接中使用的下划线会在页面文本中被看见(但这可以使用“竖线”来避免)。
如果链接的页面的标题正是你正在编辑的页面,则其结果根本不是超链接,而只是粗体文本(例如:在本页面上标记[[Help:Links/zh]]
,得到的结果是Help:Links/zh)。
如果你正在努力创建链接到当前页面的wiki链接,你可能是要链接到页面内特定的“段落”或者“锚点”;请参见下方的例子。
MediaWiki使用pagelinks 表来了解内部wiki链接的动态。
名称/描述 | 语法 | 结果 |
---|---|---|
内部链接 | [[Main Page]]
[[Help:Contents]]
[[Extension:DynamicPageList (Wikimedia)]]
|
|
管道链接 |
[[Help:Editing pages|editing help]]
链接到目标页面中的某一章节或锚点。 [[Help:Editing pages#Preview|previewing]]
链接至同一页面上某个锚点的竖线链接 [[#See also|different text]]
|
|
Pipe trick | [[Manual:Extensions|]]
[[User:John Doe|]]
[[Extension:DynamicPageList (Wikimedia)|]]
[[Extension:DynamicPageList (disambiguation)|]]
如同在DynamicPageList的示例中所示,管道技巧所完成的转换可导致不同链接目标却有着相同的文本。 |
|
词尾链接 | [[Help]]s
[[Help]]ing
[[Help]]ers
[[Help]]almostanylettersyoulikehere
[[Help]]BUTnotalways
|
Helpalmostanylettersyoulikehere HelpBUTnotalways |
避免词尾链接 | [[Help]]<nowiki />ful advice
[[wikipedia:GNU General Public License|GPL]]<nowiki />v3
|
Helpful advice GPLv3 |
链接到同一页面上的锚点 | [[#See also]]
|
#See also |
为外来的链接设置锚点 | <div id="Unique anchor name 1">optional text</div>
<span id="Unique anchor name 2">optional text</span>
分别渲染区块层级和行内。
这样做可以在同一页面上使用 在章节标题中设置锚点 ==<span id="Alternate Section Title"></span>Section heading==
需要注意的地方: 这里必须是一个span标签,而不是div标签。 (这样的锚点可以在段落更改标题的同时又不破坏外来的链接。) |
选配文本
选配文本 |
链接至另一页面上的锚点 | [[Help:Images#Supported media types for images]]
|
Help:Images#Supported media types for images |
链接至当前页面的讨论页 | [[{{TALKPAGENAME}}|Discussion]]
|
Discussion |
链接到子页面 | [[/example]]
|
/example |
链接至子页面而没有开头斜线 | [[/example/]]
|
example |
链接到当前页面的父页面的子页面。 只能在子页面上使用。 | [[../example2]]
如果您将 |
example2 |
链至分类页面的可见链接 | [[:Category:Help]]
在没有开头冒号时,链接将无法显示,并且页面会被放置在分类中;这是一个常见错误。 另见帮助:分类 。 |
Category:Help |
链至图片或媒体文件的可见链接 | [[:File:Example.jpg]]
[[:File:Example.jpg|file label]]
[[Media:Example.jpg]]
[[Media:Example.jpg|file label]]
在“File:”示例中没有开头括号时,图片就会直接显示。 参见帮助:图片 。
|
|
链接至为每个读者指定的页面(用户页等) | [[Special:MyPage]]
[[Special:MyTalk]]
[[Special:Preferences]]
|
|
链至指定修订版本的内部链接 | [[Special:PermanentLink/2393992]]
修订的版本可以在每个页面的edit history中找到。 (通常可以看到指向某个修订的版本的链接实现为外部链接,这是因为可以很容易通过复制粘贴来构建外部链接。 |
Special:PermanentLink/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 即使未使用方括号,也将自动链接以“ |
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,具体取决于当前正在查看的页面的协议(不同的用户可能会有所不同)。
仅在方括号 |
|
外部链接当前服务器 | https://{{SERVERNAME}}/pagename |
https://www.mediawiki.org/pagename |
外部链接到其他主机并传送本维基页面的名称 | https://google.com/search?q={{PAGENAMEE}} |
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] |
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数据和上方的外部链接。 |
|
指向本页面的编辑页的外部链接,看上去像是内部链接 | <span class="plainlinks">[https://www.mediawiki.org/w/index.php?title=Help:Links&action=edit Edit this page]</span>
当您想要使得一个外部链接看上去像是内部链接,可以使用 plainlinks 类,来防止一般情况下会出现的小箭头。 |
Edit this page |
Some skins add an arrow icon after each external link by default. However, this can be avoided by using class="plainlinks". For instance:
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:
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.
跨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链接#跨语言链接。
A piped link is an internal link or interwiki link where the 'target page name' of the link and its 'label' are both specified.
This is useful in cases where the user wants to values of 'target page name' and 'label' to be different. This also enables linking a contextually relevant word or phrase within the text of a page rather than using the generic value "see also". The wording does not need to match the name of the target page. Depending on the preferences set for the current user and a supported browser, you can still see the link target: when you hover your cursor over the link, the name shows up in a pop-up window and is also shown in the status bar.
For example:
[[coffeehouse setup|Get Piping Hot Coffee Here!]]
will show: Get Piping Hot Coffee Here!
Let's take another example: [[help:Piped link|piped link]] will be displayed as piped link. This can be done when context makes it clear that the page being linked to is in the help namespace. The piped link is a better way of doing this, rather than mistakenly linking to piped link which might be a disambiguation page or not exist.
Fun Fact: The term piped refers to the use of the pipe character "|", which in this context is used to separate the more descriptive description from the actual name of the linked page.
The Pipe character was named after an alternative use of it; see Pipe (computing).
An alternative way is to use redirect pages.
To create Get Piping Hot Coffee Here!, use [[Get Piping Hot Coffee Here!]] and make it redirect to coffeehouse setup (please note: unlike above, what pops up when you point at the link, depending on your browser's support, is the text that is already shown).
It is convenient if the redirect is already there or will also be of use elsewhere. However, there are a few drawbacks.
Using a piped link and a redirect together, it is possible to provide information in the hover box that is not the name of the linked page, for example, the value of a unit in terms of other units. In that case, it is possible to make a page whose page name is the information that you'd like in the link title, and which redirects to the page with a more appropriate name.
For example, the page w:30.48 cm redirects to w:Foot (unit).
If the part after the "|" in a piped link is left empty, it is converted to an abbreviated form of the page name on the left, based on the following rules:
[[Help:Piped_link#Pipe_trick|]]
outputs [[Help:Piped_link#Pipe_trick|]].Similar to using the three or four tildes when signing on Talk pages, and using 'subst', in a preview, the result shows up in the preview itself, but the conversion in the edit box is not shown yet. Click on the "Show changes" option to see the change in the wikitext.
[[Help:Template|]]
is converted to [[Help:Template|Template]], which is shown as Template[[Music: My life|]]
is converted to [[Music: My life| My life]], which is shown as My life - although "Music:" itself is not a namespace (therefore the space after the colon character is not automatically removed), however, the shortcut works anyway[[w:en:Pipe (computing)|]]
is converted to [[w:en:Pipe (computing)|en:Pipe]], which is shown as en:Pipe.[[commons:Boston, Massachusetts|]]
is converted to [[commons:Boston, Massachusetts|Boston]], which is shown as Boston.[[w:{{{1}}}|]]
does not give [[w:{{{1}}}|{{{1}}}]], and calling the template with a value of parameter 1 gives a working link, but in the case of substitution only.[[w:en:{{FULLPAGENAME}}|]]
does not give [[w:en:{{FULLPAGENAME}}|en:{{FULLPAGENAME}}]] and [[m:{{FULLPAGENAME}}|]]
does not give [[m:{{FULLPAGENAME}}|{{FULLPAGENAME}}]][[Wikipedia:Village pump (technical)#Pipe trick|]]
is not converted, so it does not give a working link.This wikitext | Produces |
* [[project:a (b)|]]
* [[w:project:a (b)|]]
* [[:de:project:a (b)|]]
* [[wiktionary:project:a (b)|]]
* [[wiktionary:de:project:a (b)|]]
* [[wikibooks:project:a (b)|]]
* [[wikiquote:project:a (b)|]]
* [[wikisource:project:a (b)|]]
* [[wikisource:project:a (b)#c|]]
* [[w:en:{{FULLPAGENAME}}|]] [[w:en:{{FULLPAGENAME}}|en:{{FULLPAGENAME}}]]
* [[m:{{FULLPAGENAME}}|]] [[m:{{FULLPAGENAME}}|{{FULLPAGENAME}}]]
|
* a * project:a * project:a * project:a * de:project:a * project:a * project:a * project:a * [[wikisource:project:a (b)#c|]] * [[w:en:Help:Links/zh|]] en:Help:Links/zh * [[m:Help:Links/zh|]] Help:Links/zh |
Since the sortkey syntax of the category is similar to a piped link, the pipe trick also works for category tags, even though technically, it is not useful there.
On page "A (c)", [[|b]] is converted to [[b (c)|b]] automatically.
Similarly, on page "A, c", [[|b]] is converted to [[b, c|b]] automatically.
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
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."
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:
<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]]
.<h2>Editing Instructions</h2>
. This text serves as an anchor_name.
border="1" class="wikitable" id="You type"
[[#top]]
.See also Help:Section#Linking sections using an arbitrary id.
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.
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
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.
When utilizing the subpage feature within namespace A on page A:B/c/d, {{BASEPAGENAME}} shows B/c while {{SUBPAGENAME}} shows d.
Within a subpage hierarchy, you can utilize the following relative links:
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
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
The guidelines outlined in Manual:Page naming state that in wiki and interwiki links, conversions are made to non-literal characters automatically. For example,"[[Manual:Page%20naming]]
" will display as "Manual:Page naming". 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.
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
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.
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链接受最大页面标题大小的限制。