Add CentralIdLookup::factoryNonLocal()
This is basically a workaround for T163277 and T170996: it’s hard to tell whether the IDs returned by a CentralIdLookup are actually safe to use cross-wiki or not, so add a factory method which only returns a CentralIdLookup that can be expected to provide cross-wiki IDs, and otherwise gives up and returns null. This is a port of the Wikibase CentralIdLookupFactory class, originally added in change Ie7b9c482cf by Matthew Flaschen. Bug: T258390 Change-Id: I903c126be413608bd366875ecc7ac007d4da8e3f
This commit is contained in:
parent
28ff8803a0
commit
b0d7337ef4
1 changed files with 28 additions and 0 deletions
|
|
@ -66,6 +66,34 @@ abstract class CentralIdLookup implements IDBAccessObject {
|
|||
return self::$instances[$providerId];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a CentralIdLookup that is guaranteed to be non-local.
|
||||
* If no such guarantee can be made, returns null.
|
||||
*
|
||||
* If this function returns a non-null CentralIdLookup,
|
||||
* that lookup is expected to provide IDs that are shared with some set of other wikis.
|
||||
* However, you should still be cautious when using those IDs,
|
||||
* as they will not necessarily work with *all* other wikis,
|
||||
* and it can be hard to tell if another wiki is in the same set as this one or not.
|
||||
*
|
||||
* @return CentralIdLookup|null
|
||||
*/
|
||||
public static function factoryNonLocal(): ?self {
|
||||
$centralIdLookup = self::factory();
|
||||
|
||||
if ( $centralIdLookup instanceof LocalIdLookup ) {
|
||||
/*
|
||||
* A LocalIdLookup (which is the default) may actually be non-local,
|
||||
* if shared user tables are used.
|
||||
* However, we cannot know that here, so play it safe and refuse to return it.
|
||||
* See also T163277 and T170996.
|
||||
*/
|
||||
return null;
|
||||
}
|
||||
|
||||
return $centralIdLookup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset internal cache for unit testing
|
||||
* @codeCoverageIgnore
|
||||
|
|
|
|||
Loading…
Reference in a new issue