Page MenuHomePhabricator

Define a WikiID class for uniquely identifying wikis
Closed, DuplicatePublic

Description

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

To resolve this, a WikiID class should be introduced. Or rather ca 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.