Manual:Central ID
The central ID identifies users across wikis. On single-wiki installations it is the same as the user ID; on wiki farms which use some kind of single sign-on, it's probably assigned by the authentication extension. Site admins can configure it by setting $wgCentralIdLookupProvider .
Using a central ID provider
[edit]Any code that interacts with data that would benefit from being available cross-wiki (e.g. authentication and authorization details, cross-wiki blocks) should, instead of storing local user IDs, store the central ID and use the CentralIdLookup class to convert between local usernames and central IDs.
Such extensions should also allow their data to be stored centrally. Typically this is done by providing a virtual domain, and doing something like this to get a database connection:
MediaWiki version: | ≥ 1.42 |
$db = \MediaWiki\MediaWikiServices::getInstance()->getConnectionProvider()->getPrimaryDatabase( 'virtual-myextension' );
(in MW 1.40-1.41, use getDBLoadBalancerFactory()
rather than getConnectionProvider
)
For an example of code making use of central IDs, see SpecialBotPasswords.
Basic examples
[edit]Obtaining the default Central ID Lookup provider:
$lookup = \MediaWiki\MediaWikiServices::getInstance()->getCentralIdLookup();
Obtaining the central ID from a local user:
$centralId = $lookup->centralIdFromLocalUser( $user );
Writing a central ID provider
[edit]Single sign-on extensions should implement a subclass of CentralIdLookup
and register it in $wgCentralIdLookupProviders .
For an example of a single sign-on extension providing central IDs, see CentralAuthIdLookup
in Extension:CentralAuth .
For a full list of such extensions, see Category:CentralIdLookup providers .