Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
MessageIndex Class Reference

Creates a database of keys in all groups, so that namespace and key can be used to get the groups they belong to. More...

Inheritance diagram for MessageIndex:
CDBMessageIndex CachedMessageIndex DatabaseMessageIndex HashMessageIndex SerializedMessageIndex

Public Member Functions

 retrieve (bool $readLatest=false)
 
 getKeys ()
 
 rebuild (float $timestamp=null)
 Creates the index from scratch.
 
 getStatusCacheKey ()
 
 storeInterim (MessageGroup $group, array $newKeys)
 

Static Public Member Functions

static singleton ()
 
static setInstance (self $instance)
 Override the global instance, for testing.
 
static getGroupIds (MessageHandle $handle)
 Retrieves a list of groups given MessageHandle belongs to.
 
static getPrimaryGroupId (MessageHandle $handle)
 
static getArrayDiff (array $old, array $new)
 Compares two associative arrays.
 

Protected Member Functions

 get ( $key)
 Looks up the stored value for single key.
 
 store (array $array, array $diff)
 
 lock ()
 
 unlock ()
 
 clearMessageGroupStats (array $diff)
 Purge stuff when set of keys have changed.
 
 checkAndAdd (&$hugearray, MessageGroup $g, $ignore=false)
 
 serialize ( $data)
 These are probably slower than serialize and unserialize, but they are more space efficient because we only need strings and arrays.
 
 unserialize ( $data)
 

Protected Attributes

 $interimCache
 

Static Protected Attributes

static $instance
 

Detailed Description

Creates a database of keys in all groups, so that namespace and key can be used to get the groups they belong to.

This is used as a fallback when loadgroup parameter is not provided in the request, which happens if someone reaches a messages from somewhere else than Special:Translate. Also used by Special:TranslationStats and alike which need to map lots of titles to message groups.

Definition at line 28 of file MessageIndex.php.

Constructor & Destructor Documentation

◆ __construct()

MessageIndex::__construct ( )

Definition at line 46 of file MessageIndex.php.

Member Function Documentation

◆ checkAndAdd()

MessageIndex::checkAndAdd ( & $hugearray,
MessageGroup $g,
$ignore = false )
protected
Parameters
array&$hugearray
MessageGroup$g
bool$ignore

Definition at line 395 of file MessageIndex.php.

◆ clearMessageGroupStats()

MessageIndex::clearMessageGroupStats ( array $diff)
protected

Purge stuff when set of keys have changed.

Parameters
array$diff

Reimplemented in HashMessageIndex.

Definition at line 374 of file MessageIndex.php.

◆ get()

MessageIndex::get ( $key)
protected

Looks up the stored value for single key.

Only for testing.

Since
2012-04-10
Parameters
string$key
Returns
string|array|null

Reimplemented in DatabaseMessageIndex, CDBMessageIndex, and HashMessageIndex.

Definition at line 139 of file MessageIndex.php.

◆ getArrayDiff()

static MessageIndex::getArrayDiff ( array $old,
array $new )
static

Compares two associative arrays.

Values must be a string or list of strings. Returns an array of added, deleted and modified keys as well as value changes (you can think values as categories and keys as pages). Each of the keys ('add', 'del', 'mod' respectively) maps to an array whose keys are the changed keys of the original arrays and values are lists where first element contains the old value and the second element the new value.

$a = [ 'a' => '1', 'b' => '2', 'c' => '3' ];
$b = [ 'b' => '2', 'c' => [ '3', '2' ], 'd' => '4' ];
self::getArrayDiff( $a, $b ) === [
'keys' => [
'add' => [ 'd' => [ [], [ '4' ] ] ],
'del' => [ 'a' => [ [ '1' ], [] ] ],
'mod' => [ 'c' => [ [ '3' ], [ '3', '2' ] ] ],
],
'values' => [ 2, 4, 1 ]
];
Parameters
array$old
array$new
Returns
array

Definition at line 329 of file MessageIndex.php.

◆ getGroupIds()

static MessageIndex::getGroupIds ( MessageHandle $handle)
static

Retrieves a list of groups given MessageHandle belongs to.

Since
2012-01-04
Parameters
MessageHandle$handle
Returns
string[]

Definition at line 82 of file MessageIndex.php.

◆ getKeys()

MessageIndex::getKeys ( )
Since
2018.01
Returns
string[]

Reimplemented in CDBMessageIndex.

Definition at line 151 of file MessageIndex.php.

◆ getPrimaryGroupId()

static MessageIndex::getPrimaryGroupId ( MessageHandle $handle)
static
Since
2012-01-04
Parameters
MessageHandle$handle
Returns
?string

Definition at line 118 of file MessageIndex.php.

◆ getStatusCacheKey()

MessageIndex::getStatusCacheKey ( )
Since
2021.10
Returns
string

Definition at line 269 of file MessageIndex.php.

◆ lock()

MessageIndex::lock ( )
protected

Definition at line 157 of file MessageIndex.php.

◆ rebuild()

MessageIndex::rebuild ( float $timestamp = null)

Creates the index from scratch.

Parameters
float | null$timestampPurge interim caches older than this timestamp.
Returns
array
Exceptions
Exception

Definition at line 172 of file MessageIndex.php.

◆ retrieve()

MessageIndex::retrieve ( bool $readLatest = false)
abstract

Reimplemented in CDBMessageIndex.

◆ serialize()

MessageIndex::serialize ( $data)
protected

These are probably slower than serialize and unserialize, but they are more space efficient because we only need strings and arrays.

Parameters
mixed$data
Returns
mixed

Definition at line 436 of file MessageIndex.php.

◆ setInstance()

static MessageIndex::setInstance ( self $instance)
static

Override the global instance, for testing.

Since
2015.04
Parameters
MessageIndex$instance

Definition at line 72 of file MessageIndex.php.

◆ singleton()

static MessageIndex::singleton ( )
static
Deprecated
Since 2020.10 Use Services::getMessageIndex()
Returns
self

Definition at line 58 of file MessageIndex.php.

◆ storeInterim()

MessageIndex::storeInterim ( MessageGroup $group,
array $newKeys )

Definition at line 277 of file MessageIndex.php.

◆ unlock()

MessageIndex::unlock ( )
protected

Definition at line 161 of file MessageIndex.php.

◆ unserialize()

MessageIndex::unserialize ( $data)
protected

Definition at line 440 of file MessageIndex.php.

Member Data Documentation

◆ $instance

MessageIndex::$instance
staticprotected

Definition at line 34 of file MessageIndex.php.

◆ $interimCache

MessageIndex::$interimCache
protected

Definition at line 38 of file MessageIndex.php.


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