Hyperlinks allow users to easily move between pages. For basic information about wiki-markup in general, see Editing.
With MediaWiki it is not possible to code hyperlinks using HTML. Instead there are three general types of hyperlinks, each with associated CSS formatting to distinguish them: wikilinks, interwiki links, and external links. Besides linking, each provides important additional features specific to wikis, such as automatic broken-link detection for wikilinks, and automatic numbering of external links when used as references.
Wikilinks
A wikilink is an internal link to another page or page-section within the same wiki. MediaWiki automatically checks if the target of a wikilink exists ("existence detection"). If the page doesn't exist, the link leads instead 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 future pages, and facilitate and encourage creation of new pages. Also, through "What links here" applied to the non-existing page they provide indirect links to other pages with the same red link.
A link to a non-existing page in the MediaWiki namespace for an existing system message counts as a link to an existing page.
Syntax
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 a pipe "|" or the opposing bracket pair "]]" is encountered (read from left to right). The link target can be another page on the wiki, a section on the same page as the link, or a section on another page on the wiki.
- Inter-page links: Links of the form
[[page name]]link to the page that exactly matches that "page_name". - Intra-page links: Links of the form
[[#link name]]link to the first section on that same page, that has a heading (or anchor – see below) which exactly matches that "link_name". - Inter-page "intra" links: Links of the form
[[page name#link name]]link to the matching section of the matching page, see section linking.
The wikilinks syntax also includes various formatting options to control how a link and its visible text appear.
| Code | Result | Target | Description |
|---|---|---|---|
| [[a]] | a | a | The simplest wikilink |
| [[a b]] | a b | a b | Multiple words |
| [[a b|c d]] | c d | a b | Link targets 'a b' but displays 'c d' * |
| [[a b]]c | a bc | a b | The link label is the link target, with its last word extended to a longer word |
| <nowiki>[[a]]</nowiki> | [[a]] | N/A | Text is displayed as typed without the properties of a link |
| entered: [[a (b)|]], converted to: [[a (b)|a]] |
a | a (b) | A pipe '|' immediately before the closing bracket pair ']]' creates a piped link which hides the part in parentheses when it is displayed *,*** |
| entered: [[a, b|]], converted to: [[a, b|a]] |
a | a, b | A pipe '|' immediately before the closing bracket pair ']]' creates a piped link which hides the comma and what follows when it is displayed *,*** |
| entered: [[w:a|]], converted to: [[w:a|a]] |
a | w:a | A pipe '|' immediately before the closing bracket pair ']]' creates a piped link which hides the first prefix of the link when it is displayed *,**,*** |
| entered: [[w:a (b)|]], converted to: [[w:a (b)|a]] |
a | w:a (b) | A pipe '|' immediately before the closing bracket pair ']]' creates a piped link which hides the first prefix of the link and the part in parentheses when it is displayed *,*** |
| entered: [[mediawiki:1movedto2|]] | mediawiki:1movedto2 | Mediawiki:1movedto2 | |
| entered: [[mediawiki:1movedto2|]] | mediawiki:1movedto3 | Mediawiki:1movedto2 |
| Result | Code | Target | Description |
|---|---|---|---|
| [[a|b|c]] | b|c | a | The wiki markup treats the second pipe '|' as regular text * |
| [[a|b]]c | bc | a | "c" is appended to the end of the link text, targets "a" (Good for adding a plural "s") * |
| a[[b]] | ab | b | "a" immediately precedes the link text but is not included |
| [[a]]<nowiki>b</nowiki> | ab | a | 'b' immediately follows the link text but is not included |
| [[a]]''b'' | ab | a | Using double apostrophes '' around 'b' to make it italicized excludes it from the link text |
| [[a]]'''b''' | ab | a | Using triple apostrophes ''' around "b" to make it bold excludes it from the link text |
| [[a|b]]c<nowiki>d</nowiki> | bcd | a | Translates like [[a|bc]]<nowiki>d</nowiki> * |
| [[a]][[b]] | ab | a , b | Two links next to each other, looks like ab when not hovered over with a cursor |
* Links with parameters (the link name) are said to be "piped" because of the pipe symbol used. See piped links.
** Regardless of whether the prefix is an interwiki link prefix, a namespace prefix, or just some text with a colon.
*** Does not work with #-wikilinks (intra-page links): renders any [[#xxxx|]] as pure text.
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:MA Help]], [[:fr:Help:Link]], and [[:File:Mediawiki.png]].
In the case of a link to a local, non-existing, dynamically generated image description page of an image on Commons, this page is counted as existing for links on pages, e.g. File:Cow-on pole, with horns.jpeg, but not for links in edit summaries and logs.
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 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 interwiki link links to a page on another website. Unlike what the name suggests, the target site need not be a wiki, but it has to be on Memory Alpha's interwiki map. 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, [[wikipedia:Main Page]] links to the main page of the English Wikipedia. The prefix can be hidden using the same piped syntax as wikilinks.
An interwiki can also link to a section or other anchor; see section linking.
Interwiki links back to 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 self wikilink is bolded (like MA Help:Link), whereas a self interwiki link is normal (memoryalpha:MA Help:Link).
Pros:
- 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. wikipedia:de:a.
Cons:
- Link has non-standard appearance
- No existence-detection for target page
External links
External links use absolute URLs to link directly to any web page. These links have the associated CSS class "external". External links are in the form [http://www.example.org link name] (resulting in link name), with the link name separated from the URL by a space. Links without link names will be automatically numbered: [http://www.example.org] becomes [1]. Links with no square brackets will be displayed in their entirety: http://www.example.org. To show a URL without a link use something like h<nowiki/>ttp://www.example.org giving http://www.example.org.
Unlike in the case of internal links, characters immediately after the closing bracket are not added to the link label: [http://www.example.org a]s gives as.
See URLs in external links for more detailed information.
E-mail links
Links to an e-mail address work the same way that external links do, except they require the prefix mailto:. E-mail links are in the form of [mailto:anyone@example.org address name] (resulting in address name), with the link name separated from the address by a space. Addresses without names will automatically be numbered: [mailto:anyone@example.org] becomes [2]. Again, links with no square brackets will be displayed in their entirety: mailto:anyone@example.com.
Same project, special page
External links support various special optional URL parameters in their linking-code. These allow links directly to the edit history of a page, to a page in edit view, a diff of two versions, etc. They can also be used to create a navigational image.
For portability, use the "fullurl" parser function, where the URL should depend on the project.
External links search
Special:LinkSearch is a special page used to find all pages containing an external link matching a given URL pattern. For each link identified, the page in which it was found is listed, along with the link's URL, in alphabetical order by the target URL.
A leading wildcard * can be used to search links to a whole top-level domain (for example, Special:LinkSearch/https://*.com), or a second-level domain (for example, Special:LinkSearch/https://*.startrek.com), et cetera. If a full domain name is specified, one can additionally specify the rest of the URL, or the first part it (a wildcard at the end is implied), for example Special:LinkSearch/https://www.startrek.com/news/discover.
If no URI scheme is specified, HTTP is assumed, for example, Special:LinkSearch/*.chakoteya.net.
For more information, see Help:Linksearch at MediaWiki.org and Help:Linksearch at Wikipedia.
Anchors
Linking to anchors
Links of the form [[#anchor name]] will link to the first anchor on the page matching that "anchor_name", usually the first identical section heading.
An #anchor_name can also be appended to the page name in any type of link, thus linking to the first identical section heading (or anchor) of the named page:
[[MA Help:Editing#Links]], [[m:Help:Editing#Links]], http://meta.wikimedia.org/wiki/Help:Editing#Links
Automatic anchors
Section headings automatically act as anchors, with the heading text as the "anchor_name". In the case of multiple sections with identical headings, the anchor name of each has "_2", "_3", etc. appended, starting from the second occurrence.
The anchor #toc links to the table of content of the page, unless there is a section titled "toc".
Manual anchors
Manually-set anchors are useful for linking to "unlinkable" things like a table (title or cell), a section of plain text, etc. For example, in the Wikilink Tricks and Demos table above, though the "Wikilink Tricks and Demos" title text appears like a minor heading, it is not, and the otherwise perfectly normal wikilink [[#Wikilink Tricks and Demos]] will not work.
There are a number of ways to set an anchor at an arbitrary position:
- On Memory Alpha, there is a template called "anchor" ({{anchor}}) which provides a simple, standardized method for setting an anchor at any position on a page.
- Generic anchors may be created, such as
<span id="anchor_name">some text</span>. For a hidden anchor, omit the text. - In some cases, inserting an HTML-like ID attribute into an (existing) wiki element will create an anchor. For example, from the Wikilink Tricks and Demos table above:
|+ id="Wiki-link Tricks"|'''Wikilink Tricks and Demos'''
- The reserved name
[[#top]]always links to the top of a page.
See also Section linking.
External links search anchors
We can use external links search to find links to internal Memory Alpha pages if they use external link style, e.g. [3], which can be detected with Special:LinkSearch/https://memory-alpha.fandom.com/wiki/MA_Help. This allows us to track section links, which cannot be done with what links here, when internal link style is used.
Index-style anchors
If anchor names have multiple components, it is useful to put the most significant component first; for example, if anchors indicate months or dates, we could use the format YYYY-MM, or YYYY-MM-DD, or in a year page MM-DD (see also Calendar date at Wikipedia), with leading zeros (see also Date formatting and linking at Meta). This also applies to 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 the display of section headings, explicitly place anchors instead of using section names. This is used in Template:Current events header at Wikipedia, where the use in links of the names of explicitly placed anchors is enforced by using pseudo-sections, with displayed headings that cannot be used as anchors.
Anchors in external links (anchorencode)
In an external link, an anchor can be created conveniently with the parser function "anchorencode"; for example, "{{anchorencode:Anchors in external links (anchorencode)}}" gives "Anchors_in_external_links_(anchorencode)" which can be used to form the link https://memory-alpha.fandom.com/wiki/Link#Anchors_in_external_links_(anchorencode)
Subpage feature
MediaWiki has a subpage feature which is active on Memory Alpha outside of the main name space.
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, while A/a 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.
What links here and Related changes ignore these automatic links.
Note that any slash in a page name causes a subpage structure, even if unintended.
Variables
On page A:B/c/d, where A is a namespace, {{BASEPAGENAME}} yields B/c and {{SUBPAGENAME}} yields d.
Relative links
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.
- [[../../]] links to the grandparent of the current subpage, e.g., on A/b/c it links to A.
- [[../s]] links to a sibling of the current subpage, e.g., on A/b, it links to A/s.
- [[../../s]] links to an "uncle" of the current subpage, e.g., on A/b/c, it links to A/s.
- [[/s]] links to a subpage, e.g. on A it is the same as [[A/s]].
See also Wikipedia:Subpages, and the example pages Help:Links/example and Help:Links/example/example2 at MediaWiki.org.
User space
Subpages of a user page ([[User:Username/Subpage]]) are considered to be in that user's "user space".
Character conversion
In accordance with the rules explained in Page name, conversions are automatically made to non-literal characters in wiki and interwiki links. For example, "[[MA Help:Page%20name]]" becomes "MA 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.
Miscellaneous
Additional effects of links
- Related changes
- What links here
- Using a space after the pipe syntax ([[Portal:Main| ]]) produces (depending on the browser) a space only, not a link (" "), but it is treated as a link for the "What links here" feature.
"Hover box" on links
On some browsers, holding the cursor over link will show a hover box (tooltip) 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 ("Page title (page does not exist)" if the link target ("Page title", in this case) does not exist), 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 user preferences. The browser may also show similar info, but with the possible section indication, in the status bar.
For these effects a piped link is useful even if it not followed to the target, for example, for displaying the meaning of an acronym (e.g. NASA) or any other remark. It is possible to produce a hover box without a link; see Template:Links-small. It is also possible to change the contents of the hover box, using {{linktip}}. For example, {{linktip|foot|30.48 cm|ft}} would produce ft.
Links from a page
The links from page "pagename", sorted by namespace, and for each namespace alphabetically, can be accessed via the Action API.
Linking to a page from an image
It is possible to use images as links to other pages. For more information, see using an image as a link to a page.
See also
- URL
- Self link
- Manual:pagelinks table at MediaWiki.org
- Wikipedia:Canonicalization
- Special:MostLinkedPages – shows the most-linked-to pages and the number of links
- Special:LonelyPages – shows pages not linked to by any other page (orphaned pages)
Help | |
|---|---|
| Logging in and preferences | |
| Reading | |
| Editing | |
| Style and formatting | |
| Tracking changes | |
| Page management | |
| Special input and output | |
| Advanced functions | |
| Administration | |