MediaWiki  master
MediaWiki\Interwiki\ClassicInterwikiLookup Class Reference

InterwikiLookup implementing the "classic" interwiki storage (hardcoded up to MW 1.26). More...

Inheritance diagram for MediaWiki\Interwiki\ClassicInterwikiLookup:
Collaboration diagram for MediaWiki\Interwiki\ClassicInterwikiLookup:

Public Member Functions

 __construct (Language $contLang, WANObjectCache $objectCache, HookContainer $hookContainer, ILoadBalancer $loadBalancer, $objectCacheExpiry, $interwikiData, $interwikiScopes, $fallbackSite)
 
 fetch ( $prefix)
 Fetch an Interwiki object. More...
 
 getAllPrefixes ( $local=null)
 Returns all interwiki prefixes. More...
 
 invalidateCache ( $prefix)
 Purge the in-process and object cache for an interwiki prefix. More...
 
 isValidInterwiki ( $prefix)
 Check whether an interwiki prefix exists. More...
 
 resetLocalCache ()
 Resets locally cached Interwiki objects. More...
 

Static Public Member Functions

static buildCdbHash (array $allPrefixes, int $scope=1, ?string $thisSite=null)
 Given the array returned by getAllPrefixes(), build a PHP hash which can be given to self::__construct() as $interwikiData, i.e. More...
 

Private Member Functions

 fetchPregenerated ( $prefix)
 Fetch interwiki prefix data from local cache in constant database. More...
 
 getAllPrefixesDB ( $local)
 Fetch all interwiki prefixes from DB. More...
 
 getAllPrefixesPregenerated ( $local)
 Fetch all interwiki prefixes from pregenerated data. More...
 
 getPregeneratedEntry ( $prefix)
 Get entry from pregenerated data. More...
 
 load ( $prefix)
 Load the interwiki, trying first memcached then the DB. More...
 
 loadFromArray ( $mc)
 Fill in member variables from an array (e.g. More...
 

Static Private Member Functions

static selectFields ()
 Return the list of interwiki fields that should be selected to create a new Interwiki object. More...
 

Private Attributes

Language $contLang
 
array null $data
 Complete pregenerated data if available. More...
 
string $fallbackSite
 
HookRunner $hookRunner
 
int $interwikiScopes
 
ILoadBalancer $loadBalancer
 
MapCacheLRU $localCache
 
WANObjectCache $objectCache
 
int $objectCacheExpiry
 
string null $thisSite = null
 

Detailed Description

InterwikiLookup implementing the "classic" interwiki storage (hardcoded up to MW 1.26).

This implements two levels of caching (in-process array and a WANObjectCache) and two storage backends (SQL and plain PHP arrays).

All information is loaded on creation when called by $this->fetch( $prefix ). All work is done on replica DB, because this should never change (except during schema updates etc, which aren't wiki-related)

Since
1.28

Definition at line 48 of file ClassicInterwikiLookup.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Interwiki\ClassicInterwikiLookup::__construct ( Language  $contLang,
WANObjectCache  $objectCache,
HookContainer  $hookContainer,
ILoadBalancer  $loadBalancer,
  $objectCacheExpiry,
  $interwikiData,
  $interwikiScopes,
  $fallbackSite 
)
Parameters
Language$contLangLanguage object used to convert prefixes to lower case
WANObjectCache$objectCacheCache for interwiki info retrieved from the database
HookContainer$hookContainer
ILoadBalancer$loadBalancer
int$objectCacheExpiryExpiry time for $objectCache, in seconds
bool | array$interwikiDataThe pre-generated interwiki data, or false to use the database.
int$interwikiScopesSpecify number of domains to check for messages:
  • 1: Just local wiki level
  • 2: wiki and global levels
  • 3: site level as well as wiki and global levels
string$fallbackSiteThe code to assume for the local site,

Definition at line 110 of file ClassicInterwikiLookup.php.

References MediaWiki\Interwiki\ClassicInterwikiLookup\$contLang, MediaWiki\Interwiki\ClassicInterwikiLookup\$fallbackSite, MediaWiki\Interwiki\ClassicInterwikiLookup\$interwikiScopes, MediaWiki\Interwiki\ClassicInterwikiLookup\$loadBalancer, MediaWiki\Interwiki\ClassicInterwikiLookup\$objectCache, and MediaWiki\Interwiki\ClassicInterwikiLookup\$objectCacheExpiry.

Member Function Documentation

◆ buildCdbHash()

static MediaWiki\Interwiki\ClassicInterwikiLookup::buildCdbHash ( array  $allPrefixes,
int  $scope = 1,
?string  $thisSite = null 
)
static

Given the array returned by getAllPrefixes(), build a PHP hash which can be given to self::__construct() as $interwikiData, i.e.

as the value of $wgInterwikiCache. This is used to construct mock interwiki lookup services for testing (in particular, parsertests).

Parameters
array$allPrefixesAn array of interwiki information such as would be returned by ::getAllPrefixes()
int$scopeThe scope at which to insert interwiki prefixes. See the $interwikiScopes parameter to ::__construct().
?string$thisSite The value of $thisSite, if $scope is 3.
Returns
array A PHP associative array suitable to use as $wgInterwikiCache

Definition at line 382 of file ClassicInterwikiLookup.php.

◆ fetch()

MediaWiki\Interwiki\ClassicInterwikiLookup::fetch (   $prefix)

◆ fetchPregenerated()

MediaWiki\Interwiki\ClassicInterwikiLookup::fetchPregenerated (   $prefix)
private

Fetch interwiki prefix data from local cache in constant database.

Note
More logic is explained in docs/Configuration.md.
Parameters
string$prefixInterwiki prefix
Returns
Interwiki|false

Definition at line 206 of file ClassicInterwikiLookup.php.

References MediaWiki\Interwiki\ClassicInterwikiLookup\getPregeneratedEntry().

Referenced by MediaWiki\Interwiki\ClassicInterwikiLookup\fetch().

◆ getAllPrefixes()

MediaWiki\Interwiki\ClassicInterwikiLookup::getAllPrefixes (   $local = null)

Returns all interwiki prefixes.

Parameters
string | null$localIf set, limits output to local/non-local interwikis
Returns
array[] Interwiki rows, where each row is an associative array

Implements MediaWiki\Interwiki\InterwikiLookup.

Definition at line 439 of file ClassicInterwikiLookup.php.

◆ getAllPrefixesDB()

MediaWiki\Interwiki\ClassicInterwikiLookup::getAllPrefixesDB (   $local)
private

Fetch all interwiki prefixes from DB.

Parameters
bool | null$localIf not null, limits output to local/non-local interwikis
Returns
array[] Interwiki rows

Definition at line 411 of file ClassicInterwikiLookup.php.

References $res, and DB_REPLICA.

◆ getAllPrefixesPregenerated()

MediaWiki\Interwiki\ClassicInterwikiLookup::getAllPrefixesPregenerated (   $local)
private

Fetch all interwiki prefixes from pregenerated data.

Parameters
null | string$localIf not null, limits output to local/non-local interwikis
Returns
array List of prefixes, where each row is an associative array

Definition at line 321 of file ClassicInterwikiLookup.php.

References MediaWiki\Interwiki\ClassicInterwikiLookup\$data, MediaWiki\Interwiki\ClassicInterwikiLookup\$fallbackSite, $source, MediaWiki\Interwiki\ClassicInterwikiLookup\$thisSite, WikiMap\getCurrentWikiId(), and wfDebug().

◆ getPregeneratedEntry()

MediaWiki\Interwiki\ClassicInterwikiLookup::getPregeneratedEntry (   $prefix)
private

Get entry from pregenerated data.

Note
More logic is explained in docs/Configuration.md.
Parameters
string$prefixDatabase key
Returns
bool|string The interwiki entry or false if not found

Definition at line 226 of file ClassicInterwikiLookup.php.

References MediaWiki\Interwiki\ClassicInterwikiLookup\$fallbackSite, WikiMap\getCurrentWikiId(), and wfDebug().

Referenced by MediaWiki\Interwiki\ClassicInterwikiLookup\fetchPregenerated().

◆ invalidateCache()

MediaWiki\Interwiki\ClassicInterwikiLookup::invalidateCache (   $prefix)

Purge the in-process and object cache for an interwiki prefix.

Parameters
string$prefix

Implements MediaWiki\Interwiki\InterwikiLookup.

Definition at line 191 of file ClassicInterwikiLookup.php.

◆ isValidInterwiki()

MediaWiki\Interwiki\ClassicInterwikiLookup::isValidInterwiki (   $prefix)

Check whether an interwiki prefix exists.

Parameters
string$prefixInterwiki prefix to use
Returns
bool Whether it exists

Implements MediaWiki\Interwiki\InterwikiLookup.

Definition at line 143 of file ClassicInterwikiLookup.php.

References MediaWiki\Interwiki\ClassicInterwikiLookup\fetch().

◆ load()

MediaWiki\Interwiki\ClassicInterwikiLookup::load (   $prefix)
private

Load the interwiki, trying first memcached then the DB.

Parameters
string$prefixThe interwiki prefix
Returns
Interwiki|bool Interwiki if $prefix is valid, otherwise false

Definition at line 255 of file ClassicInterwikiLookup.php.

References $dbr, DB_REPLICA, Wikimedia\Rdbms\Database\getCacheSetOptions(), and MediaWiki\Interwiki\ClassicInterwikiLookup\loadFromArray().

Referenced by MediaWiki\Interwiki\ClassicInterwikiLookup\fetch().

◆ loadFromArray()

MediaWiki\Interwiki\ClassicInterwikiLookup::loadFromArray (   $mc)
private

Fill in member variables from an array (e.g.

memcached result, Database::fetchRow, etc)

Parameters
array$mcAssociative array: row from the interwiki table
Returns
Interwiki|bool Interwiki object or false if $mc['iw_url'] is not set

Definition at line 301 of file ClassicInterwikiLookup.php.

Referenced by MediaWiki\Interwiki\ClassicInterwikiLookup\load().

◆ resetLocalCache()

MediaWiki\Interwiki\ClassicInterwikiLookup::resetLocalCache ( )

Resets locally cached Interwiki objects.

This is intended for use during testing only. This does not invalidate entries in the persistent cache, as invalidateCache() does.

Since
1.27

Definition at line 183 of file ClassicInterwikiLookup.php.

◆ selectFields()

static MediaWiki\Interwiki\ClassicInterwikiLookup::selectFields ( )
staticprivate

Return the list of interwiki fields that should be selected to create a new Interwiki object.

Returns
string[]

Definition at line 452 of file ClassicInterwikiLookup.php.

Member Data Documentation

◆ $contLang

Language MediaWiki\Interwiki\ClassicInterwikiLookup::$contLang
private

◆ $data

array null MediaWiki\Interwiki\ClassicInterwikiLookup::$data
private

Complete pregenerated data if available.

Definition at line 73 of file ClassicInterwikiLookup.php.

Referenced by MediaWiki\Interwiki\ClassicInterwikiLookup\getAllPrefixesPregenerated().

◆ $fallbackSite

◆ $hookRunner

HookRunner MediaWiki\Interwiki\ClassicInterwikiLookup::$hookRunner
private

Definition at line 91 of file ClassicInterwikiLookup.php.

◆ $interwikiScopes

int MediaWiki\Interwiki\ClassicInterwikiLookup::$interwikiScopes
private

◆ $loadBalancer

ILoadBalancer MediaWiki\Interwiki\ClassicInterwikiLookup::$loadBalancer
private

◆ $localCache

MapCacheLRU MediaWiki\Interwiki\ClassicInterwikiLookup::$localCache
private

Definition at line 53 of file ClassicInterwikiLookup.php.

◆ $objectCache

WANObjectCache MediaWiki\Interwiki\ClassicInterwikiLookup::$objectCache
private

◆ $objectCacheExpiry

int MediaWiki\Interwiki\ClassicInterwikiLookup::$objectCacheExpiry
private

◆ $thisSite

string null MediaWiki\Interwiki\ClassicInterwikiLookup::$thisSite = null
private

The documentation for this class was generated from the following file: