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 (private readonly MessageIndexStore $messageIndexStore, private readonly WANObjectCache $statusCache, private readonly JobQueueGroup $jobQueueGroup, private readonly HookRunner $hookRunner, private readonly LoggerInterface $logger, private readonly BagOStuff $interimCache, private readonly IConnectionProvider $dbProvider, ServiceOptions $options)
 
 getGroupIds (MessageHandle $handle)
 Retrieves a list of groups given MessageHandle belongs to.
 
 getGroupIdsForBaseDatabaseTitle (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)
 

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

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Extension\Translate\MessageLoading\MessageIndex::__construct ( private readonly MessageIndexStore $messageIndexStore,
private readonly WANObjectCache $statusCache,
private readonly JobQueueGroup $jobQueueGroup,
private readonly HookRunner $hookRunner,
private readonly LoggerInterface $logger,
private readonly BagOStuff $interimCache,
private readonly IConnectionProvider $dbProvider,
ServiceOptions $options )

Definition at line 43 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 393 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 377 of file MessageIndex.php.

◆ get()

MediaWiki\Extension\Translate\MessageLoading\MessageIndex::get ( string $key)
Returns
mixed|null

Definition at line 126 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 336 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 69 of file MessageIndex.php.

◆ getGroupIdsForBaseDatabaseTitle()

MediaWiki\Extension\Translate\MessageLoading\MessageIndex::getGroupIdsForBaseDatabaseTitle ( 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 96 of file MessageIndex.php.

◆ getKeys()

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

Definition at line 131 of file MessageIndex.php.

◆ getPrimaryGroupId()

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

Definition at line 105 of file MessageIndex.php.

◆ getStatusCacheKey()

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

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

◆ storeInterim()

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

Definition at line 275 of file MessageIndex.php.

Member Data Documentation

◆ SERVICE_OPTIONS

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

Definition at line 39 of file MessageIndex.php.


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