Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups Class Reference

Factory class for accessing message groups individually by id or all of them as a list. More...

Public Member Functions

 recache ()
 Immediately update the cache.
 
 clearProcessCache ()
 Manually reset the process cache.
 
 setCache (?WANObjectCache $cache=null)
 Override cache, for example during tests.
 
 getCacheKey ()
 Returns the cache key.
 
 getGroups ()
 Get all enabled non-dynamic message groups.
 

Static Public Member Functions

static clearCache ()
 Manually reset group cache.
 
static getGroup (string $id)
 Fetch a message group by id.
 
static normalizeId (?string $id)
 Fixes the id and resolves aliases.
 
static exists (string $id)
 
static labelExists (string $name)
 Check if a particular aggregate group label exists.
 
static getAllGroups ()
 Get all enabled message groups.
 
static getPriority ( $group)
 We want to de-emphasize time sensitive groups like news for 2009.
 
static setPriority ( $group, string $priority='')
 Sets the message group priority.
 
static isDynamic (MessageGroup $group)
 
static getSharedGroups (MessageGroup $group)
 Returns a list of message groups that share (certain) messages with this group.
 
static getParentGroups (MessageGroup $targetGroup)
 Returns a list of parent message groups.
 
static singleton ()
 
static getGroupsById (array $ids, bool $skipMeta=false)
 Get message groups for corresponding message group ids.
 
static expandWildcards ( $ids)
 If the list of message group ids contains wildcards, this function will match them against the list of all supported message groups and return matched message group ids.
 
static getDynamicGroups ()
 Contents on these groups changes on a whim.
 
static getGroupsByType (string $type)
 Get only groups of specific type (class).
 
static getGroupStructure ()
 Returns a tree of message groups.
 
static groupLabelSort (MessageGroup $a, MessageGroup $b)
 Sorts groups by label value.
 
static subGroups (AggregateMessageGroup $parent, array &$childIds=[], string $fname='caller')
 Like getGroupStructure but start from one root which must be an AggregateMessageGroup.
 
static haveSingleSourceLanguage (array $groups)
 Checks whether all the message groups have the same source language.
 
static isTranslatableMessage (MessageHandle $handle, string $targetLanguage)
 Filters out messages that should not be translated under normal conditions.
 

Protected Member Functions

 init ()
 Initialises the list of groups.
 
 getCachedGroupDefinitions ( $recache=false)
 
 initGroupsFromDefinitions (array $groups)
 Expand process cached groups to objects.
 
 getCache ()
 
 getGroupLoaders ()
 Loads and returns group loaders.
 
 getCacheGroupLoaders ()
 Returns group loaders that implement the CachedMessageGroupLoader.
 

Static Protected Member Functions

static appendAutoloader (array &$additions, array &$to)
 Safely merges first array to second array, throwing warning on duplicates and removing duplicates from the first array.
 

Detailed Description

Factory class for accessing message groups individually by id or all of them as a list.

Todo
Clean up the mixed static/member method interface.
Author
Niklas Laxström
Siebrand Mazeland

Definition at line 34 of file MessageGroups.php.

Member Function Documentation

◆ appendAutoloader()

static MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups::appendAutoloader ( array & $additions,
array & $to )
staticprotected

Safely merges first array to second array, throwing warning on duplicates and removing duplicates from the first array.

Parameters
array&$additionsThings to append
array&$toWhere to append

Definition at line 208 of file MessageGroups.php.

◆ clearCache()

static MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups::clearCache ( )
static

Manually reset group cache.

Use when automatic dependency tracking fails.

Definition at line 160 of file MessageGroups.php.

◆ clearProcessCache()

MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups::clearProcessCache ( )

Manually reset the process cache.

This is helpful for long running scripts where the process cache might get stale even though the global cache is updated.

Definition at line 179 of file MessageGroups.php.

◆ exists()

static MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups::exists ( string $id)
static

Definition at line 315 of file MessageGroups.php.

◆ expandWildcards()

static MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups::expandWildcards ( $ids)
static

If the list of message group ids contains wildcards, this function will match them against the list of all supported message groups and return matched message group ids.

Parameters
string[] | string$ids
Returns
string[]

Definition at line 525 of file MessageGroups.php.

◆ getAllGroups()

static MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups::getAllGroups ( )
static

Get all enabled message groups.

Returns
MessageGroup[] Map of (string => MessageGroup)

Definition at line 332 of file MessageGroups.php.

◆ getCache()

MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups::getCache ( )
protected

Definition at line 184 of file MessageGroups.php.

◆ getCachedGroupDefinitions()

MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups::getCachedGroupDefinitions ( $recache = false)
protected
Parameters
string | false$recacheEither "recache" or false

Definition at line 66 of file MessageGroups.php.

◆ getCacheGroupLoaders()

MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups::getCacheGroupLoaders ( )
protected

Returns group loaders that implement the CachedMessageGroupLoader.

Returns
CachedMessageGroupLoader[]

Definition at line 266 of file MessageGroups.php.

◆ getCacheKey()

MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups::getCacheKey ( )

Returns the cache key.

Definition at line 198 of file MessageGroups.php.

◆ getDynamicGroups()

static MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups::getDynamicGroups ( )
static

Contents on these groups changes on a whim.

Definition at line 556 of file MessageGroups.php.

◆ getGroup()

static MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups::getGroup ( string $id)
static

Fetch a message group by id.

Parameters
string$idMessage group id.
Returns
MessageGroup|null if it doesn't exist.

Definition at line 279 of file MessageGroups.php.

◆ getGroupLoaders()

MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups::getGroupLoaders ( )
protected

Loads and returns group loaders.

Group loaders must implement MessageGroupLoader and may additionally implement CachedMessageGroupLoader

Returns
MessageGroupLoader[]

Definition at line 225 of file MessageGroups.php.

◆ getGroups()

MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups::getGroups ( )

Get all enabled non-dynamic message groups.

Returns
MessageGroup[] Map of (group ID => MessageGroup)

Definition at line 485 of file MessageGroups.php.

◆ getGroupsById()

static MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups::getGroupsById ( array $ids,
bool $skipMeta = false )
static

Get message groups for corresponding message group ids.

Parameters
string[]$idsGroup IDs
bool$skipMetaSkip aggregate message groups
Returns
MessageGroup[]
Since
2012-02-13

Definition at line 499 of file MessageGroups.php.

◆ getGroupsByType()

static MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups::getGroupsByType ( string $type)
static

Get only groups of specific type (class).

@phan-template T

Parameters
string$typeClass name of wanted type @phan-param class-string<T> $type
Returns
MessageGroup[] Map of (group ID => MessageGroupBase) @phan-return array<T&MessageGroup>
Since
2012-04-30

Definition at line 573 of file MessageGroups.php.

◆ getGroupStructure()

static MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups::getGroupStructure ( )
static

Returns a tree of message groups.

First group in each subgroup is the aggregate group. Groups can be nested infinitely, though in practice other code might not handle more than two (or even one) nesting levels. One group can exist multiple times in different parts of the tree. In other words: [Group1, Group2, [AggGroup, Group3, Group4]]

Returns
array Map of (group ID => MessageGroup or recursive array)

Definition at line 594 of file MessageGroups.php.

◆ getParentGroups()

static MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups::getParentGroups ( MessageGroup $targetGroup)
static

Returns a list of parent message groups.

If message group exists in multiple places in the tree, multiple lists are returned.

Definition at line 404 of file MessageGroups.php.

◆ getPriority()

static MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups::getPriority ( $group)
static

We want to de-emphasize time sensitive groups like news for 2009.

They can still exist in the system, but should not appear in front of translators looking to do some useful work.

Parameters
MessageGroup | string$groupMessage group ID
Returns
string Message group priority

Definition at line 344 of file MessageGroups.php.

◆ getSharedGroups()

static MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups::getSharedGroups ( MessageGroup $group)
static

Returns a list of message groups that share (certain) messages with this group.

Definition at line 381 of file MessageGroups.php.

◆ groupLabelSort()

static MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups::groupLabelSort ( MessageGroup $a,
MessageGroup $b )
static

Sorts groups by label value.

Definition at line 651 of file MessageGroups.php.

◆ haveSingleSourceLanguage()

static MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups::haveSingleSourceLanguage ( array $groups)
static

Checks whether all the message groups have the same source language.

Parameters
array$groupsA list of message groups objects.
Returns
string Language code if the languages are the same, empty string otherwise.

Definition at line 718 of file MessageGroups.php.

◆ init()

MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups::init ( )
protected

Initialises the list of groups.

Definition at line 51 of file MessageGroups.php.

◆ initGroupsFromDefinitions()

MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups::initGroupsFromDefinitions ( array $groups)
protected

Expand process cached groups to objects.

Parameters
array$groupsMap of (group ID => mixed)

Definition at line 122 of file MessageGroups.php.

◆ isDynamic()

static MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups::isDynamic ( MessageGroup $group)
static

Definition at line 371 of file MessageGroups.php.

◆ isTranslatableMessage()

static MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups::isTranslatableMessage ( MessageHandle $handle,
string $targetLanguage )
static

Filters out messages that should not be translated under normal conditions.

Parameters
MessageHandle$handleHandle for the translation target.
string$targetLanguage
Returns
bool

Definition at line 741 of file MessageGroups.php.

◆ labelExists()

static MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups::labelExists ( string $name)
static

Check if a particular aggregate group label exists.

Definition at line 320 of file MessageGroups.php.

◆ normalizeId()

static MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups::normalizeId ( ?string $id)
static

Fixes the id and resolves aliases.

Definition at line 298 of file MessageGroups.php.

◆ recache()

MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups::recache ( )

Immediately update the cache.

Definition at line 133 of file MessageGroups.php.

◆ setCache()

MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups::setCache ( ?WANObjectCache $cache = null)

Override cache, for example during tests.

Definition at line 193 of file MessageGroups.php.

◆ setPriority()

static MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups::setPriority ( $group,
string $priority = '' )
static

Sets the message group priority.

Parameters
MessageGroup | string$groupMessage group
string$priorityPriority (empty string to unset)

Definition at line 360 of file MessageGroups.php.

◆ singleton()

static MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups::singleton ( )
static

Definition at line 471 of file MessageGroups.php.

◆ subGroups()

static MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups::subGroups ( AggregateMessageGroup $parent,
array & $childIds = [],
string $fname = 'caller' )
static

Like getGroupStructure but start from one root which must be an AggregateMessageGroup.

Parameters
AggregateMessageGroup$parent
string[]&$childIdsFlat list of child group IDs [returned]
string$fnameCalling method name; used to identify recursion [optional]
Returns
array

Definition at line 667 of file MessageGroups.php.


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