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 ( $forRebuild=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 25 of file MessageIndex.php.

Constructor & Destructor Documentation

◆ __construct()

MessageIndex::__construct ( )

Definition at line 39 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 391 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 370 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 131 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 325 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 74 of file MessageIndex.php.

◆ getKeys()

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

Reimplemented in CDBMessageIndex.

Definition at line 147 of file MessageIndex.php.

◆ getPrimaryGroupId()

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

Definition at line 110 of file MessageIndex.php.

◆ getStatusCacheKey()

MessageIndex::getStatusCacheKey ( )
Since
2021.10
Returns
string

Definition at line 265 of file MessageIndex.php.

◆ lock()

MessageIndex::lock ( )
protected

Definition at line 153 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 168 of file MessageIndex.php.

◆ retrieve()

MessageIndex::retrieve ( $forRebuild = false)
abstract
Parameters
bool$forRebuild
Returns
array

Reimplemented in SerializedMessageIndex, DatabaseMessageIndex, CachedMessageIndex, CDBMessageIndex, and HashMessageIndex.

◆ 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 432 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 64 of file MessageIndex.php.

◆ singleton()

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

Definition at line 50 of file MessageIndex.php.

◆ storeInterim()

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

Definition at line 273 of file MessageIndex.php.

◆ unlock()

MessageIndex::unlock ( )
protected

Definition at line 157 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 29 of file MessageIndex.php.

◆ $interimCache

MessageIndex::$interimCache
protected

Definition at line 33 of file MessageIndex.php.


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