Interwiki sorting order
Sorting of Wikidata based interwiki links on Wikimedia wikis is provided by InterwikiSorting extension. Below text for the most part covers pre-Wikidata situation.
Many Wikimedia projects prefer their own interwiki sort orders. The interwiki sort order at the rendered page is the same as the one used in the source code.
The following text describes how you can obtain the sorting order for a project. The description is technical to have a deterministic sort order for each project, but examples may help you to understand the syntax.
The sorting order for a wiki is defined locally on MediaWiki:Interwiki config-sorting order. If there is no such page, sort order will be as described in #auto-languagecode.
There are three ways to define sorting orders: local (MediaWiki:Interwiki config-sorting order), on meta MediaWiki:Interwiki config-sorting order-* (Code: meta-*) and calculated by script (auto-*).
The language code in this context is identical to code used for the subdomain and the main interwiki prefix. All language codes are listed on Special:Sitematrix (Api: action=sitematrix). Please note that the code of the local content language may differ (e.g. for alswiki you have to use als and not gsw).
Language codes are always lower case and only contains character that are also part of ASCII.
Local sorting order
The local system message MediaWiki:Interwiki config-sorting order contains a list of language codes. Each line contains a single language code and interwikis should be ordered in this sequence.
A Script can request this e.g. using api (action=query&meta=allmessages&ammessages=Interwiki%20config-sorting%20order). If this message is missing, interwiki are ordered by language code (see #auto-languagecode).
If the local configuration should not contain a full order it can refer to a calculated- or meta-sort order. In this case add the special code (see below) instead of a language code. These special codes get replaced by the refered list. If this so expanded list contains some language codes twice only the first occurence is important - all other are ignored.
calculated sorting order
There are two sort orders that can be calculated by all script itself based on formal description.
This interwiki sort order is based on the language codes. The language code in this context is identical to code used for the subdomain and the main interwiki prefix. All language codes are listed on Special:SiteMatrix (Api: action=sitematrix).
Language codes are always lower case and sorted lexicographically.
More technical: The comparison is based on the Unicode value of each character in the strings. The character sequence of a code is compared lexicographically to the character sequence of another code. Two strings are different when they either have different characters at some index that is a valid index for both strings, or their lengths are different, or both.
If they have different characters at one or more index positions, let k be the smallest such index; then the string whose character at position k has the smaller value, lexicographically precedes the other string. If there is no index position at which they differ, then the shorter code lexicographically precedes the longer code.
This is the same as auto-languagecode except that y is sorted like i. Only if two language codes are equal after this conversion y is sorted after i as a secondary ordering.
Sort orders defined on meta
Some project like to have a special sort order that is used on various projects. These sort orders can be defined on metawiki, so that a updates must only be done on one page.
Local project can refer to a meta sort order by using meta- codes on the local MediaWiki:Interwiki config-sorting order. The code meta-XXX refers to a sorting order defined at meta:MediaWiki:Interwiki config-sorting order-XXX. The pages follow the same format rules as the local config pages except that they cannot refer to other sort orders.
Currently two meta interwiki sort orders are defined:
- bug 2867 - allow sites, and, eventually individual users, to define their own interwiki sorting order.