Help:Link

Hyperlinks allow users to easily move between pages. For basic information about wiki-markup in general, see Help:Editing. For various URLs of Wikimedia project pages, see Help:URL.

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.

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.

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). 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.

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 [[: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.

The maximum link length (before optional bar character) is 255 bytes, after expansion of .. and / and UTF-8 encoding.

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, and links to short disambiguation pages. 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.

An interwiki link links 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 (except Wikipedias) and many other wikis [[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.

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 Help:Link), whereas a self interwiki link is normal (m: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. w:de:a.

External links use absolute URLs to link directly to any webpage. These links have the associated CSS class "external". An external link can be of the form [http://www.example.org link name], with the link name separated from the URL by a space, and giving link name. A link without link name is automatically numbered: [http://www.example.org] gives [3]. A URL without square brackets gives a link displaying the URL: http://www.example.org gives http://www.example.org. Without "http:": [//www.example.org link name] gives link name, [//www.example.org] gives [4]; however, //www.example.org gives //www.example.org (no link).

To show a URL (including "http://") without link, use e.g. <nowiki>http://www.example.org</nowiki> 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.

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 [5]. Addresses without square brackets will not be rendered as link, e.g. anyone@example.com. It's possible to make CC with [mailto:anyone@example.org?cc=anyone2@example.org address name] (resulting in address name).

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, et cetera. They can also be used to create a navigational image.

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

To skip a number in the automatically numbered external links (for whatever reason), use e.g. <span style="display:none">[http://a]</span>: [6][7][8].

Note that a false condition of a ParserFunction, or a template like template:void ( talkedithistorylinks ) does not work, because counting the links is done after expansion of templates and parser functions.

Special:Linksearch (an extension installed on Wikimedia wikis, [9]) 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. [10]), or a second-level domain (e.g. [11]), 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. [12].

Remarks:

Do not put "http://".

The colon in the URL may cause the program return no results.

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.

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-set anchor, one could put an internal link and also, with CSS style "display=none", an external link, to provide backlinks.

External link style is also 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. 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>

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".

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 & Demos table above, though the "Wikilink Tricks & Demos" title-text appears like a (minor) heading, it is not, and the otherwise perfectly normal wikilink [[#Wikilink Tricks & Demos]] will not work.

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".

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 [15]), with leading zeros (see also [16]). 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 headings, 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 headings that cannot be used as anchors.

In an external link, an anchor can be created conveniently with the parser function anchorencode, for example, "{{anchorencode:Anchors in external links (anchorencode)}}" → "Anchors_in_external_links_.28anchorencode.29" [17], which can be used to form the link //meta.wikimedia.org/wiki/Link#Anchors_in_external_links_.28anchorencode.29

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; while 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.

[[../]] 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]]. 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.

Linking to an anchor of an ancestor does not work; attempting that gives a link to a page with the name consisting of the name of the ancestor followed by "/".

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. Administrators and other users with the move-subpages right have an option in page moves to also move subpages.

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[18]. 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[19].

In accordance with the rules explained in Help:Page name, conversions are automatically made to 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.

On some browsers, holding the cursor over a 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 (the message with id 'red-link-title' (talk) if the page does not exist), the page name with prefix if it's an interwiki link, and the URL if it's an external link.

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. NPOV) or any other remark. It is possible to produce a hover box without a link, see template:H:title ( talkedithistorylinks ). It is also possible to change the contents of the hover box, using markup similar to [[Link title|<span title="hoverbox">Display text</span>]], e.g.

With the Query API 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. //meta.wikimedia.org/w/query.php?what=links&titles=Help:Link .[1]