The concept of a "wiki ID" is spread throughout the MediaWiki code base, but it not formally defined anywhere, and there is quite a bit of confusion about edge cases and its relationship to other things, like database names (see for instance T184529: Define a way to get a database connection based on a logical wiki ID.). Currently, the identity of other wikis in the same wiki farm is represented as a string, more or less identical with their database name. Interwiki prefixes are used to refer to other known sites (but also to the wikis on the same wiki farm).
To resolve this, a WikiID class should be introduced. Or rather a hierarchy of three classes:
- SiteID identifies any site of any kind the wiki can refer to or interact with
- WikiID identifies a MediaWiki site the wiki can refer to or interact with
- LocalWikiID identifies a MediaWiki site the wiki on the local cluster (aka wiki farm) which to which direct database access is possible.
WikiIDs (or rather, all SiteIDs) have a string representation that can be used for persistence in the database and representation in the web API. That string representation should be treated as a URI, and should be fairly stable, though not impossible to change. The string representation has to be unique and consistent at least across the local cluster (aka wiki farm), but should ideally be universally unique. Using the wiki's base URL (domain plus article path) would be the obvious choice.
WikiIDs (or rather, all SiteIDs) are constructed by a SiteIDFactory service (or SiteInfoLookup, compare T113034: RFC: Overhaul Interwiki map, unify with Sites and WikiMap) that provides the following methods:
- getSiteId( string|false ) will instantiate a SiteID from the given string, applying any normalization, aliasing, and lookups. At the very least, a round trip with a SiteID's string representation must be supported, but completely different things like database names may be supported for some sites, especially wikis on the local cluster. The SiteID returned should be of the most specific type possible. If false is passed in, a LocalWikiID representing the current wiki (home wiki if the factory service) is returned.
- isHomeWiki( SiteID|null ): returns true if the given site ID is the home wiki of the factory service. Will always return true if null is passed in.
- getHomeWikiID: returns the LocalWikiID representing the current wiki (home wiki if the factory service).
In general, false instead of a string ID, or null instead of a SiteID object, are considered to represent the current wiki (home wiki). However, to allow transparent cross-wiki functionality, this notion is meaningful only relative to a given SiteIDFactory service; so it's not necessarily identical to the wiki the request was made to.
Some requirements for a wiki ID class representing farm-local wikis (LocalWikiId):
- should have an equals() method, such that if two LocalWikiIds are equal, they refer to the same wiki.
- should have a __toString method, but the string representation must not be considered stable (it could perhaps change from a database name to a base URI)
- Can be based on the database name (plus table prefix, plus schema name, plus host name) for now, but using the wiki's base URL (domain and base path) would probably be better in the long run.
- null should be used to represent the "current" wiki (just like false is currently used instead of a string based ID in this case)
- WikiIDs must only be constructed by a factory service (WikiIdResolver), that has a getWikiId() method.
- getWikiId() will resolve any aliases (such as interwiki prefixes or domain names) and construct a canonical LocalWikiId()
- WikiIdResolver should also have get getDefaultWikiId() method that returns the canonical ID object for the wiki that is otherwise represented by null ("this" wiki, the "current" wiki).
- LocalWikiId may extend a WikiId class that can also be used to represent "foreign" wikis.
- LocalWikiId may extend a SiteId class that can also be used to represent "foreign" non-wiki sites.
- a mapping should exist between LocalWikiId and DatabaseDomain
- a mapping should exist between LocalWikiId and Interwiki
See also: