Sunday, July 26, 2015

Section anchors and other anchors in MediaWiki code

It's possible to link to specific article sections or other in-article items in Wikipedia and other projects that use MediaWiki software.
Hereonafter I'm going to use 'MediaWiki', because this is the software that Wikipedia and similar projects rely on, and functionality is not limited to just Wikipedia. Other projects that use MediaWiki code are at Wikia, such as Memory Alpha, a comprehensive Star Trek canon encyclopedia.
The simplest way to find the jump link is by clicking on a section name in the article table of contents — the browser then jumps to the section — and then copying the URL from the browser address bar, where the address is appended with anchor text when an anchor is jumped to.

An anchor in HTML and newer web page standards is an in-page point one can jump to if a link exists, or if the anchor is used in a web address (URL).

Each section title is also made into an anchor, and sections are the most prominent jumping points in MediaWiki-based projects, because the anchor is always there whenever there's a section.

In a web address, the anchor is known as part of the URL that starts with a hash # sign:

https://en.wikipedia.org/wiki/Electric_car_use_by_country#Global_outlook

This link takes to the Wikipedia article "Electric car use by country", but jumps the browser view into the "Global outlook" section, which may have more relevant information than the whole article.

One can thus link to an in-article position either by targeting a section via pre-existing section anchors, or by creating a separate anchor using the {{Anchor}} template (exists in Wikipedia and its sister projects), or by creating and adding in article code a specific easily-readable ID to almost any tag or object present in an article, such as a table, a <DIV> or <SPAN>:
{| class="wikitable" id="Top_10_countries"
|-
|Table in wikicode
|-
|}


<!-- or somewhere else: -->

<div id="Other_countries">Some content inside a block</div>
That way, the anchor is created to a table, and after saving, one can jump to it by using this link instead:

https://en.wikipedia.org/wiki/Electric_car_use_by_country#Top_10_countries

Article sections in MediaWiki-based projects may contain all UTF-8-encoded characters, and the characters are then transformed into UTF-8-encoded text parts acceptable in web addresses:

The highlighted anchor part of the below URL was converted from the Russian word 'Возможности' (Features) from the Russian-language article about Mozilla Firefox, wherein the Russian-language capital 'В' (V) was converted into .D0.92. in an anchor. This, of course, makes links in non-Latin scripts very long:

https://ru.wikipedia.org/wiki/Mozilla_Firefox#.D0.92.D0.BE.D0.B7.D0.BC.D0.BE.D0.B6.D0.BD.D0.BE.D1.81.D1.82.D0.B8

No comments: