Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
MediaWiki\Extension\Translate\MessageLoading\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...

Public Member Functions

 __construct (MessageIndexStore $store, WANObjectCache $statusCache, JobQueueGroup $jobQueueGroup, HookRunner $hookRunner, LoggerInterface $logger, BagOStuff $interimCache, IConnectionProvider $connectionProvider, MessageGroupSubscription $messageGroupSubscription, ServiceOptions $options)
 
 getGroupIds (MessageHandle $handle)
 Retrieves a list of groups given MessageHandle belongs to.
 
 getGroupIdsForDatabaseTitle (int $namespace, string $title)
 Fast-path to retrieve groups for database titles.
 
 getPrimaryGroupId (MessageHandle $handle)
 
 get (string $key)
 
 getKeys ()
 
 rebuild (float $timestamp=null)
 Creates the index from scratch.
 
 getStatusCacheKey ()
 
 storeInterim (MessageGroup $group, array $newKeys)
 
 getArrayDiff (array $old, array $new)
 Compares two associative arrays.
 

Public Attributes

const SERVICE_OPTIONS
 

Protected Member Functions

 clearMessageGroupStats (array $diff)
 Purge stuff when set of keys have changed.
 
 checkAndAdd (array &$hugeArray, MessageGroup $g, bool $ignore=false)
 

Protected Attributes

BagOStuff $interimCache
 

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.

Author
Niklas Laxstrom

Definition at line 33 of file MessageIndex.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Extension\Translate\MessageLoading\MessageIndex::__construct ( MessageIndexStore $store,
WANObjectCache $statusCache,
JobQueueGroup $jobQueueGroup,
HookRunner $hookRunner,
LoggerInterface $logger,
BagOStuff $interimCache,
IConnectionProvider $connectionProvider,
MessageGroupSubscription $messageGroupSubscription,
ServiceOptions $options )

Definition at line 51 of file MessageIndex.php.

Member Function Documentation

◆ checkAndAdd()

MediaWiki\Extension\Translate\MessageLoading\MessageIndex::checkAndAdd ( array & $hugeArray,
MessageGroup $g,
bool $ignore = false )
protected

Definition at line 411 of file MessageIndex.php.

◆ clearMessageGroupStats()

MediaWiki\Extension\Translate\MessageLoading\MessageIndex::clearMessageGroupStats ( array $diff)
protected

Purge stuff when set of keys have changed.

Definition at line 394 of file MessageIndex.php.

◆ get()

MediaWiki\Extension\Translate\MessageLoading\MessageIndex::get ( string $key)

Definition at line 142 of file MessageIndex.php.

◆ getArrayDiff()

MediaWiki\Extension\Translate\MessageLoading\MessageIndex::getArrayDiff ( array $old,
array $new )

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 353 of file MessageIndex.php.

◆ getGroupIds()

MediaWiki\Extension\Translate\MessageLoading\MessageIndex::getGroupIds ( MessageHandle $handle)

Retrieves a list of groups given MessageHandle belongs to.

Returns
string[]

Definition at line 86 of file MessageIndex.php.

◆ getGroupIdsForDatabaseTitle()

MediaWiki\Extension\Translate\MessageLoading\MessageIndex::getGroupIdsForDatabaseTitle ( int $namespace,
string $title )

Fast-path to retrieve groups for database titles.

Performance is critical for stats that need to check groups for many rows. Do not include the language code subpage!

Returns
string[]

Definition at line 113 of file MessageIndex.php.

◆ getKeys()

MediaWiki\Extension\Translate\MessageLoading\MessageIndex::getKeys ( )
Returns
string[]

Definition at line 147 of file MessageIndex.php.

◆ getPrimaryGroupId()

MediaWiki\Extension\Translate\MessageLoading\MessageIndex::getPrimaryGroupId ( MessageHandle $handle)

Definition at line 122 of file MessageIndex.php.

◆ getStatusCacheKey()

MediaWiki\Extension\Translate\MessageLoading\MessageIndex::getStatusCacheKey ( )

Definition at line 284 of file MessageIndex.php.

◆ rebuild()

MediaWiki\Extension\Translate\MessageLoading\MessageIndex::rebuild ( float $timestamp = null)

Creates the index from scratch.

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

Definition at line 183 of file MessageIndex.php.

◆ storeInterim()

MediaWiki\Extension\Translate\MessageLoading\MessageIndex::storeInterim ( MessageGroup $group,
array $newKeys )

Definition at line 292 of file MessageIndex.php.

Member Data Documentation

◆ $interimCache

BagOStuff MediaWiki\Extension\Translate\MessageLoading\MessageIndex::$interimCache
protected

Definition at line 39 of file MessageIndex.php.

◆ SERVICE_OPTIONS

const MediaWiki\Extension\Translate\MessageLoading\MessageIndex::SERVICE_OPTIONS
Initial value:
= [
'TranslateMessageNamespaces'
]

Definition at line 47 of file MessageIndex.php.


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