From Lunarpedia
Jump to: navigation, search


Hyperlinks allow users to move between pages. For some basic information about using hyperlinks, see {{ #ifeq:

| | Help:Editing#Links | Help:Editing#Links }}. There are three general types of hyperlinks recognized by MediaWiki, each with associated CSS formatting to distinguish them.


A wikilink is an internal link to another page within a wiki. Although it is sometimes possible to code these links using HTML, a wiki will often provide its users with a unique markup language that makes creating wikilinks simpler and a lot less time consuming. Such languages are called wikitext languages or wiki markups. The syntax for the wikitext language used by Lunarpedia and all other Wikimedia projects is defined by the software MediaWiki.


MediaWiki defines a wikilink as a closed set of inward facing square bracket pairs '[[ ]]'. The link target is the sequence of characters immediately following the first bracket pair until pipe '|' or the opposing bracket pair ']]' is encountered (read from left to right).

Basic Wikilink Syntax

Template:Wikilink syntax tbl

Template:Wikilink syntax tbl

Template:Wikilink syntax tbl

Template:Wikilink syntax tbl

Template:Wikilink syntax tbl

Template:Wikilink syntax tbl

Template:Wikilink syntax tbl

Template:Wikilink syntax tbl

Template:Wikilink syntax tbl

Template:Wikilink syntax tbl

Wikilink Tricks & Demos

Template:Wikilink syntax tbl

Template:Wikilink syntax tbl

Template:Wikilink syntax tbl

Template:Wikilink syntax tbl

Template:Wikilink syntax tbl

Template:Wikilink syntax tbl

Template:Wikilink syntax tbl

Template:Wikilink syntax tbl

* Links with parameters (the link name) are said to be "piped" because of the pipe symbol used. See {{ #ifeq:

| | piped links | piped links }}

** Regardless of whether the prefix is an interwiki link prefix, a namespace prefix, or just some text with a colon.

MediaWiki automatically checks if the target of a wikilink exists ("existence detection"). If the page doesn't exist, the link leads to the editing screen, and it is assigned the class "new". Such wikilinks are nicknamed "red links" because they are colored red in the default stylesheet on a default installation of MediaWiki. Red links are useful in determining the current status of the page (created or not created), create links to a future page, facilitates and incites page creation.

Note that the image, category, and interlanguage syntax are the same as the wikilink syntax. Attempting to link normally will place the image on the page, add the page to the category and create an interlanguage link at the edge of the page. This can be prevented by prefixing a colon, which escapes the specific syntax. For example, [[:Category:Help]], [[:fr:Help:Link]], and [[:Image:Mediawiki.png]].

The existence of an internal link from a page to an existing or non-existing page is recorded in the pagelinks table.

Stub feature

A wikilink to an existing page will be in class 'stub' if the page is in the main namespace, it is not a redirect, and the number of bytes of the wikitext is less than the "threshold for stub display" set in the {{ #ifeq:

| | user's preferences | user's preferences }}.

This allows users to immediately identify links to very short pages that probably need to be expanded. Alternately, a user may set a very high threshold to achieve any of the following:

  • Identify links to very large pages. However, the criterion is the size of the wikitext; possible inclusion of templates and images can make the rendered page large, even if the amount of wikitext is small.
  • Determine at a glance whether a link leads to the main namespace or not. However, this does not take into account redirects to the main namespace (even if the redirect itself is in the main namespace).
  • Identify links to redirects, for clean-up work such as bypassing redirects.

However, section linking to a "stub" does not work. Although this is normally a minor issue, this may cause problems with users who set a very high threshold.

Interwiki links

An {{ #ifeq:

| | interwiki link | interwiki link }} links a page to a page on another website. Unlike the name suggests, the target site need not be a wiki, but it has to be on the interwiki map specified for the source wiki. These links have the associated CSS class "extiw". These are in the same form as wikilinks above, but take a prefix which specifies the target site. For example, on Wikimedia projects and many other wikis [[wikipedia:Main Page]] links to Wikipedia's main page. The prefix can be hidden using the same piped syntax as wikilinks.

Interwiki links to the same project

Although interwiki links can be used to point to a wiki from itself, this is not generally recommended. MediaWiki does not detect whether or not the target page of an interwiki list exists, so there is no special formatting and the link is always to the view page. Further, MediaWiki does not check if the page is linking to itself. A {{ #ifeq:

| | self wikilink | self wikilink }} is bolded (like Help:Link), whereas a self interwiki link is normal (m:Help:Link).


  • A copy of the wikitext on a sister project may still point to the same page. Sometimes two prefixes are needed for that purpose, e.g. w:de:a.

External links

External links use absolute URLs to link directly to any webpage. These links have the associated CSS class "external". External links are in the form [ link name] (resulting in link name), with the link name separated from the URL by a space. Links without link names will be numbered: [] becomes [1]. Links with no square brackets will be displayed in their entirety: .

Unlike in the case of internal links, characters immediately after the closing bracket are not added to the link label: [ a]s gives as.

See {{ #ifeq:

| | URLs in external links | URLs in external links }} for more detailed information.

Special:Linksearch (an extension installed on Wikimedia wikis, [2]) finds all pages linking to a given URL. Using the externallinks table it provides for a given external link pattern a list of source page names on the wiki concerned (linked) with for each the full link target (also as a link). One can either search all namespaces or a selected one. A leading wildcard * can be used to search links to a whole top-level domain (e.g. [3]), or a second-level domain (e.g. [4]), etc. In the case that a full domain name is specified, one can additionally specify the rest of the URL, or the first part of that (a wildcard at the end is implied), e.g. [5]; do not put "http://".


  • A MediaWiki page name in a URL has underscores instead of spaces. Also the URL specified in Linksearch requires writing underscores.
  • Even if multiple URLs lead to the same target, with regard to capitalisation, multiple underscores, and using "index.php" or not, Linksearch is case-sensitive and also does not find alternatively written URLs. Therefore, when creating an external link, for optimal use of Linksearch, use a canonical form for the URL. In particular, if after following a link the address bar shows a modified URL, change the URL in the link to that.
  • The list is {{ #ifeq:

| | alphabetic | alphabetic }} in the URL. Note that an underscore, unlike a blank space, is alphabetically positioned between "Z" and "a".

With regard to this backlinks feature, external link style is superior to interwiki link style. The URL specified for Linksearch can even contain an anchor (see below), or the first part of an anchor. Therefore Linksearch can find backlinks of sections and explicit anchors. In this regard external links are even superior to internal links.

External links to the same project

External links are often used to use special URL parameters in links. This allows links directly to the edit history of a page, to a page in edit view, a diff of two versions, et cetera. They can also be used to create a {{ #ifeq:

| | navigational image | navigational image }}.

Commonly, a link to a normal page on the same project is in internal link style. An advantage is the existence detection. Also, if some links are in internal and some in external link style, we need both "What links here" and Linksearch for finding all backlinks. However, especially for a link to a section or explicitly put anchor, one could put an internal link and also, with CSS style "display=none", an external link, to provide backlinks. See also below.

For portability, use "fullurl" where the URL should depend on the project.

Arrow icon

Monobook skin produces an arrow icon after every external link. This can be suppressed with class="plainlinks":

With some special code on MediaWiki:Common.css such as on m:MediaWiki:Common.css, external links to PDF files have their own icon File:Icons-mini-file acrobat.gif. On this site with your current settings http://a.pdf gives http://a.pdf .


Links in the form [[#anchor_name]] will link to any anchor named "anchor_name" on the page. This may be either a heading named "anchor_name", or an arbitrary position. [[#top]] is a reserved name that links to the top of a page. It is possible to create an arbitrary anchor name using the HTML code <span id="anchor_name"></span>.

An anchor can also be appended to the page name in any type of link: {{ #ifeq:

| | Help:Editing#Links | Help:Editing#Links }},

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

We can combine the advantages of internal and external link style by putting both, but hiding the external links: <span style="display:none">http://...</span>

Since Linksearch allows specifying the first part of an anchor, it is useful, if anchor names are numerical or have a numerical end, to use leading zeros. Otherwise, when searching for links to e.g. "1", we also get links to "10", etc. This is e.g. applied in w:Portal:Current events/DateHeader2. More generally, if there are anchors "a" and "ab", it may or may not be desired that a search for links to "a" also gives links to "ab"; if not, use an anchor "_a".

Also, if anchor names have multiple components, it is useful to put the most significant component first, e.g. if anchors indicate months or dates, we could have the format YYYY-MM, or YYYY-MM-DD, or in a year page MM-DD (see also [8]), with leading zeros (see also [9]). This applies also for page names, but since these are highly visible, as opposed to anchors, other considerations play a role too. In the case of sections, if for link targets another naming scheme is desired than for display of section headers, explicitly put anchors instead of using section names. This is applied in w:Portal:Current events/DateHeader2, where the use in links of the names of explicitly put anchors is enforced by using pseudo sections, with displayed headers that cannot be used as anchors.

In the case of multiple sections with the same name, the HTML produced has a HTML ID that is the section name, with, from the second occurence, "_2", "_3", etc. appended. This does not apply when other anchors are used.

See also {{ #ifeq:

| | Help:Section#Section_linking | Help:Section#Section_linking }}.

Redirects with section links

A {{ #ifeq:

| | redirect | redirect }} to a page section also works.

Subpage feature

MediaWiki has a subpage feature, although activation depends on project and namespace. If activated, the following applies (if not, "A/b" is just a page with that name).

A tree structure of pages is established by using forward slashes in pagenames: A/b is a child of A, hence A is a parent of A/b; also A/b/c is a child of A/b; A/a, A/b, and A/c are siblings.

At the top of the subpage body links to all ancestor pages are shown automatically, without any corresponding wikitext. The links show up even if the parent page does not exist, but the sequence of ancestors stops before any non-existing ancestor page (e.g., if the grandparent page does not exist, the parent page is not shown either). Like most letters of a page name, the first letter after the slash is case-sensitive; "/subpage" and "/Subpage" are different pages.

{{ #ifeq:

| | What links here | What links here }} and {{ #ifeq:

| | Related changes | Related changes }} ignore these automatic links.


On page A:B/c/d, where A is a namespace with the subpage feature enabled, {{BASEPAGENAME}} gives B/c and {{SUBPAGENAME}} gives d

Relative links

Relative links still work if all pages of a tree are renamed according a name change of the root, including making it a child of a new root.

Inside a subpage hierarchy the following relative links can be used:

  • [[../]] links to the parent of the current subpage, e.g., on A/b it links to A, on A/b/c it links to A/b.
  • [[../s]] links to a sibling of the current subpage, e.g., on A/b, it links to A/s.
  • [[/s]] links to a subpage, e.g. on A it is the same as [[A/s]]. Because of this, linking from a namespace where the subpage feature is enabled to a page in the main namespace with a name starting with "/", requires a workaround: put a colon before the pagename.

See also w:Wikipedia:Subpages, and the example pages m:Link/a/b and m:Help:Link/a/b. For the latter the subpage feature does not work because of the namespace.

User space

Subpages of a user page ([[User:Username/Subpage]]) are considered to be in that user's "user space". Rules are often relaxed in a user's own subpages, whereas they are typically tightened for a user editing another user's subpages.

Unintended subpage structure

Any slash in a pagename causes a subpage structure, e.g. Subpage demo Season 2006/2007 is a subpage of "Subpage demo Season 2006". As long as the latter does not exist, this has no effect on the former. However, a page with a slash in its name cannot be the root page of a subpage structure. For example, Subpage demo Season 2006/2007 /soccer does not show its parent, because its unintended grandparent does not exist. A dummy grandparent page can fix this.

Subpage activation

Wikipedia has this feature activated in all talk namespaces and the user and project namespace. The Meta-Wiki also has it in the main namespace. The default is set in DefaultSettings.php[10]. As of revision 1.21, the following namespaces have it activated by default: Special, Main talk, User and User_talk, Meta_talk, and Image_talk. Settings per project are changed in LocalSettings.php[11].


Linking to a page with images

It is possible to use images as links to other pages. For more information, see {{ #ifeq:

| | use an image as a link to a page | use an image as a link to a page }}.

"Hover box" on links

On some browsers, holding the cursor over link will show a hover box containing the text of the link's HTML title attribute. MediaWiki sets this to the target page name (without the possible section indication) if it's a wikilink, the page name with prefix if it's an interwiki link, and the URL if it's an external link.

This can be switched off in the {{ #ifeq:

| | user preferences | user preferences }}. The browser may also show similar info, but with the possible section indication, in the address bar.

For these effects a piped link is useful even if it not followed; for example, for displaying the meaning of an acronym (e.g. NPOV) or any other remark. It is possible to produce a hover box without a link, see Template:Tim. It is also possible to change the contents of the hover box, using markup similar to [[Link title|<span title="hoverbox">Display text</span>]].

Disallowed characters

In internal and interwiki link style, a plus sign in a page name is not allowed, the HTML and hence the rendered page just shows the wikitext, e.g. a+b. In external link style a plus sign in the URL is retained. It is often equivalent with a space. See also below.

In accordance with the rules explained in {{ #ifeq:

| | Help:Page name | Help:Page name }}, conversions are automatically made to {{ #ifeq:

| | non-literal characters | non-literal characters }} in wiki and interwiki links. For example, "[[Help:Page%20name]]" becomes "Help:Page name". However, the opposite is true for external links; literal characters are converted into non-literal characters. For example, most browsers will convert ".../wiki/!" to ".../wiki/%21".

A code like %70 in a redirect disables it, although the link works from the redirect page. For a redirect that works, the redirect page shows the canonical form of the target, unlike its preview page, which renders the link in the usual way.

Special pipe syntax

Using an empty pipe syntax on wiki and interwiki links will hide interwiki prefixes and parentheses. For example, [[w:Mercury (planet)|]] becomes Mercury. This pipe syntax should only be used where the unqualified reference is not ambiguous, such as in an article about the solar system. See {{ #ifeq:

| | Help:Piped link | Help:Piped link }}.

Additional effects of links

  • {{ #ifeq:

| | Related changes | Related changes }}

  • {{ #ifeq:

| | Backlink | Backlink }}s, {{ #ifeq:

| | Linksearch | Linksearch }}

  • {{ #ifeq:

| | Date format | Date format }}

  • Using a space after the pipe syntax ([[Main page| ]]) produces (perhaps depending on the browser) a space only, not a link (" "), but it is treated as a link for the "what links here" feature.

Links from a page

With query the links from page pagename, sorted by namespace, and for each namespace alphabetically, are given by {{SERVER}}{{SCRIPTPATH}}/query.php?what=links&titles=pagename , e.g. // .

Linking to a category page

Add a colon in front of the Category tag when you set up a link to a category page to prevent the software from thinking you merely want to add the page you are working from to the category:

[[:Category:Category name]]

See also

  • {{ #ifeq:

| | Help:Calculation | Help:Calculation }}

  • {{ #ifeq:

| | Help:Editing#Links, URLs | Help:Editing#Links, URLs }}

  • {{ #ifeq:

| | Help:Interwiki linking | Help:Interwiki linking }}

  • {{ #ifeq:

| | Help:Piped link | Help:Piped link }}

  • {{ #ifeq:

| | Help:Self link | Help:Self link }}

  • {{ #ifeq:

| | Help:Template#Restrictions | Help:Template#Restrictions }} (and the next section)

  • {{ #ifeq:

| | Help:URL | Help:URL }}

  • {{ #ifeq:

| | Help:What links here | Help:What links here }}

  • {{ #ifeq:

| | Help:Guide for system administrators for setting up interwiki linking | Help:Guide for system administrators for setting up interwiki linking }}