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

Factory class for accessing message groups individually by id or all of them as an 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 ( $id)
 Fetch a message group by id.
 
static normalizeId ( $id)
 Fixes the id and resolves aliases.
 
static exists ( $id)
 
static labelExists ( $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, $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, $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 ( $type)
 Get only groups of specific type (class).
 
static getGroupStructure ()
 Returns a tree of message groups.
 
static groupLabelSort ( $a, $b)
 Sorts groups by label value.
 
static subGroups (AggregateMessageGroup $parent, array &$childIds=[], $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 ( $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 an list.

Todo
Clean up the mixed static/member method interface.

Definition at line 20 of file MessageGroups.php.

Member Function Documentation

◆ appendAutoloader()

static 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 215 of file MessageGroups.php.

◆ clearCache()

static MessageGroups::clearCache ( )
static

Manually reset group cache.

Use when automatic dependency tracking fails.

Definition at line 156 of file MessageGroups.php.

◆ clearProcessCache()

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.

Since
2016.08

Definition at line 176 of file MessageGroups.php.

◆ exists()

static MessageGroups::exists ( $id)
static
Parameters
string$id
Returns
bool

Definition at line 330 of file MessageGroups.php.

◆ expandWildcards()

static 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[]
Since
2012-02-13

Definition at line 588 of file MessageGroups.php.

◆ getAllGroups()

static MessageGroups::getAllGroups ( )
static

Get all enabled message groups.

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

Definition at line 351 of file MessageGroups.php.

◆ getCache()

MessageGroups::getCache ( )
protected

Definition at line 183 of file MessageGroups.php.

◆ getCachedGroupDefinitions()

MessageGroups::getCachedGroupDefinitions ( $recache = false)
protected
Parameters
bool | string$recacheEither "recache" or false
Returns
array

Definition at line 59 of file MessageGroups.php.

◆ getCacheGroupLoaders()

MessageGroups::getCacheGroupLoaders ( )
protected

Returns group loaders that implement the CachedMessageGroupLoader.

Returns
CachedMessageGroupLoader[]

Definition at line 273 of file MessageGroups.php.

◆ getCacheKey()

MessageGroups::getCacheKey ( )

Returns the cache key.

Returns
string

Definition at line 205 of file MessageGroups.php.

◆ getDynamicGroups()

static MessageGroups::getDynamicGroups ( )
static

Contents on these groups changes on a whim.

Since
2011-12-28
Returns
array

Definition at line 623 of file MessageGroups.php.

◆ getGroup()

static MessageGroups::getGroup ( $id)
static

Fetch a message group by id.

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

Definition at line 286 of file MessageGroups.php.

◆ getGroupLoaders()

MessageGroups::getGroupLoaders ( )
protected

Loads and returns group loaders.

Group loaders must implement MessageGroupLoader and may additionally implement CachedMessageGroupLoader

Returns
MessageGroupLoader[]

Definition at line 232 of file MessageGroups.php.

◆ getGroups()

MessageGroups::getGroups ( )

Get all enabled non-dynamic message groups.

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

Definition at line 547 of file MessageGroups.php.

◆ getGroupsById()

static MessageGroups::getGroupsById ( array $ids,
$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 561 of file MessageGroups.php.

◆ getGroupsByType()

static MessageGroups::getGroupsByType ( $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 640 of file MessageGroups.php.

◆ getGroupStructure()

static 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]]

Exceptions
MWExceptionIf cyclic structure is detected.
Returns
array Map of (group ID => MessageGroup or recursive array)

Definition at line 662 of file MessageGroups.php.

◆ getParentGroups()

static 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.

Since
2012-12-10
Parameters
MessageGroup$targetGroup
Returns
array[]

Definition at line 465 of file MessageGroups.php.

◆ getPriority()

static 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
Since
2011-12-12

Definition at line 364 of file MessageGroups.php.

◆ getSharedGroups()

static MessageGroups::getSharedGroups ( MessageGroup $group)
static

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

Since
2011-12-25; renamed in 2012-12-10 from getParentGroups.
Parameters
MessageGroup$group
Returns
string[]

Definition at line 439 of file MessageGroups.php.

◆ groupLabelSort()

static MessageGroups::groupLabelSort ( $a,
$b )
static

Sorts groups by label value.

Parameters
MessageGroup$a
MessageGroup$b
Returns
int

Definition at line 725 of file MessageGroups.php.

◆ haveSingleSourceLanguage()

static 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.
Since
2013.09

Definition at line 795 of file MessageGroups.php.

◆ init()

MessageGroups::init ( )
protected

Initialises the list of groups.

Definition at line 41 of file MessageGroups.php.

◆ initGroupsFromDefinitions()

MessageGroups::initGroupsFromDefinitions ( $groups)
protected

Expand process cached groups to objects.

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

Definition at line 114 of file MessageGroups.php.

◆ isDynamic()

static MessageGroups::isDynamic ( MessageGroup $group)
static
Since
2011-12-28
Parameters
MessageGroup$group
Returns
bool

Definition at line 426 of file MessageGroups.php.

◆ isTranslatableMessage()

static 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
Since
2013.10

Definition at line 819 of file MessageGroups.php.

◆ labelExists()

static MessageGroups::labelExists ( $name)
static

Check if a particular aggregate group label exists.

Parameters
string$name
Returns
bool

Definition at line 339 of file MessageGroups.php.

◆ normalizeId()

static MessageGroups::normalizeId ( $id)
static

Fixes the id and resolves aliases.

Parameters
string$id
Returns
string
Since
2016.01

Definition at line 311 of file MessageGroups.php.

◆ recache()

MessageGroups::recache ( )

Immediately update the cache.

Since
2015.04

Definition at line 129 of file MessageGroups.php.

◆ setCache()

MessageGroups::setCache ( WANObjectCache $cache = null)

Override cache, for example during tests.

Parameters
WANObjectCache | null$cache

Definition at line 196 of file MessageGroups.php.

◆ setPriority()

static MessageGroups::setPriority ( $group,
$priority = '' )
static

Sets the message group priority.

Parameters
MessageGroup | string$groupMessage group
string$priorityPriority (empty string to unset)
Since
2013-03-01

Definition at line 394 of file MessageGroups.php.

◆ singleton()

static MessageGroups::singleton ( )
static
Returns
self

Definition at line 533 of file MessageGroups.php.

◆ subGroups()

static MessageGroups::subGroups ( AggregateMessageGroup $parent,
array & $childIds = [],
$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]
Exceptions
MWException
Returns
array
Since
Public since 2012-11-29

Definition at line 743 of file MessageGroups.php.


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