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

Core message collection class. More...

Inheritance diagram for MessageCollection:

Public Member Functions

 __construct ( $code)
 Constructors.
 
 getLanguage ()
 
 setInFile (array $messages)
 Set translation from file, as opposed to translation which only exists in the wiki because they are not exported and committed yet.
 
 setTags ( $type, array $keys)
 Set message tags.
 
 keys ()
 Returns list of available message keys.
 
 getTitles ()
 Returns list of TitleValues of messages that are used in this collection after filtering.
 
 getMessageKeys ()
 Returns list of message keys that are used in this collection after filtering.
 
 getTags ( $type)
 Returns stored message tags.
 
 getAuthors ()
 Lists all translators that have contributed to the latest revisions of each translation.
 
 addCollectionAuthors ( $authors, $mode='append')
 Add external authors (usually from the file).
 
 loadTranslations ()
 Loads all message data.
 
 resetForNewLanguage ( $code)
 Some statistics scripts for example loop the same collection over every language.
 
 slice ( $offset, $limit)
 For paging messages.
 
 filter ( $type, $condition=true, $value=null)
 Filters messages based on some condition.
 
 filterUntranslatedOptional ()
 
 getReverseMap ()
 Creates a two-dimensional map of namespace and pagenames.
 
 initMessages ()
 Constructs all TMessages from the data accumulated so far.
 
 offsetExists ( $offset)
 ArrayAccess methods.
 
 offsetGet ( $offset)
 
 offsetSet ( $offset, $value)
 
 offsetUnset ( $offset)
 
 __get ( $name)
 Fail fast if trying to access unknown properties.
 
 __set ( $name, $value)
 Fail fast if trying to access unknown properties.
 
 rewind ()
 Iterator method.
 
 current ()
 
 key ()
 
 next ()
 
 valid ()
 
 count ()
 

Static Public Member Functions

static newFromDefinitions (MessageDefinitions $definitions, $code)
 Construct a new message collection from definitions.
 
static getAvailableFilters ()
 

Public Attributes

 $code
 

Protected Member Functions

 applyFilter ( $filter, $condition, $value)
 Really apply a filter.
 
 filterOnCondition (array $keys, array $condKeys, $condition=true)
 Filters list of keys with other list of keys according to the condition.
 
 filterFuzzy (array $keys, $condition)
 Filters list of keys according to whether the translation is fuzzy.
 
 filterHastranslation (array $keys, $condition)
 Filters list of keys according to whether they have a translation.
 
 filterChanged (array $keys, $condition)
 Filters list of keys according to whether the current translation differs from the commited translation.
 
 filterReviewer (array $keys, $condition, $user)
 Filters list of keys according to whether the user has accepted them.
 
 filterLastTranslator (array $keys, $condition, $user)
 
 fixKeys ()
 Takes list of keys and converts them into database format.
 
 loadInfo (array $keys, ?array $titleConds=null)
 Loads existence and fuzzy state for given list of keys.
 
 loadReviewInfo (array $keys, ?array $titleConds=null)
 Loads reviewers for given messages.
 
 loadData (array $keys, ?array $titleConds=null)
 Loads translation for given list of keys.
 
 getTitleConds ( $db)
 Of the current set of keys, construct database query conditions.
 
 rowToKey ( $row)
 Given two-dimensional map of namespace and pagenames, this uses database fields page_namespace and page_title as keys and returns the value for those indexes.
 

Protected Attributes

 $keys = []
 
 $messages = []
 
 $tags = []
 

Detailed Description

Core message collection class.

Message collection is collection of messages of one message group in one language. It handles loading of the messages in one huge batch, and also stores information that can be used to filter the collection in different ways.

Definition at line 25 of file MessageCollection.php.

Constructor & Destructor Documentation

◆ __construct()

MessageCollection::__construct ( $code)

Constructors.

Use newFromDefinitions() instead.

Parameters
string$codeLanguage code.

Definition at line 74 of file MessageCollection.php.

Member Function Documentation

◆ __get()

MessageCollection::__get ( $name)

Fail fast if trying to access unknown properties.

Parameters
string$name
Exceptions
MWException
Returns
never

Definition at line 944 of file MessageCollection.php.

◆ __set()

MessageCollection::__set ( $name,
$value )

Fail fast if trying to access unknown properties.

Parameters
string$name
mixed$value
Exceptions
MWException
Returns
never

Definition at line 955 of file MessageCollection.php.

◆ addCollectionAuthors()

MessageCollection::addCollectionAuthors ( $authors,
$mode = 'append' )

Add external authors (usually from the file).

Parameters
string[]$authorsList of authors.
string$modeEither append or set authors.
Exceptions
MWExceptionIf invalid $mode given.

Definition at line 198 of file MessageCollection.php.

◆ applyFilter()

MessageCollection::applyFilter ( $filter,
$condition,
$value )
protected

Really apply a filter.

Some filters need multiple conditions.

Parameters
string$filterFilter name.
bool$conditionWhether to return messages which do not satisfy
mixed$valueValue for properties filtering. the given filter condition (true), or only which do (false).
Exceptions
MWException

Definition at line 355 of file MessageCollection.php.

◆ count()

MessageCollection::count ( )

Definition at line 990 of file MessageCollection.php.

◆ current()

MessageCollection::current ( )

Definition at line 969 of file MessageCollection.php.

◆ filter()

MessageCollection::filter ( $type,
$condition = true,
$value = null )

Filters messages based on some condition.

Some filters cause data to be loaded from the database. PAGEINFO: existence and fuzzy tags. TRANSLATIONS: translations for every message. It is recommended to first filter with messages that do not need those. It is recommended to add translations from file with addInfile, and it is needed for changed filter to work.

Parameters
string$type
  • fuzzy: messages with fuzzy tag (PAGEINFO)
  • optional: messages marked for optional.
  • ignored: messages which are not for translation.
  • hastranslation: messages which have translation (be if fuzzy or not) (PAGEINFO, *INFILE).
  • translated: messages which have translation which is not fuzzy (PAGEINFO, *INFILE).
  • changed: translation in database differs from infile. (INFILE, TRANSLATIONS)
bool$conditionWhether to return messages which do not satisfy the given filter condition (true), or only which do (false).
mixed | null$valueValue for properties filtering.
Exceptions
MWExceptionIf given invalid filter name.

Definition at line 326 of file MessageCollection.php.

◆ filterChanged()

MessageCollection::filterChanged ( array $keys,
$condition )
protected

Filters list of keys according to whether the current translation differs from the commited translation.

Parameters
string[]$keysList of keys to filter.
bool$conditionTrue to filter changed translations, false to filter unchanged translations.
Returns
string[] Filtered keys.

Definition at line 503 of file MessageCollection.php.

◆ filterFuzzy()

MessageCollection::filterFuzzy ( array $keys,
$condition )
protected

Filters list of keys according to whether the translation is fuzzy.

Parameters
string[]$keysList of keys to filter.
bool$conditionTrue to filter away fuzzy translations, false to filter non-fuzzy translations.
Returns
string[] Filtered keys.

Definition at line 442 of file MessageCollection.php.

◆ filterHastranslation()

MessageCollection::filterHastranslation ( array $keys,
$condition )
protected

Filters list of keys according to whether they have a translation.

Parameters
string[]$keysList of keys to filter.
bool$conditionTrue to filter away translated, false to filter untranslated.
Returns
string[] Filtered keys.

Definition at line 470 of file MessageCollection.php.

◆ filterLastTranslator()

MessageCollection::filterLastTranslator ( array $keys,
$condition,
$user )
protected
Parameters
string[]$keysList of keys to filter.
bool$conditionTrue to remove translatations where last translator is $user false to get only last translations done by others.
int$userUserid
Returns
string[] Filtered keys.

Definition at line 583 of file MessageCollection.php.

◆ filterOnCondition()

MessageCollection::filterOnCondition ( array $keys,
array $condKeys,
$condition = true )
protected

Filters list of keys with other list of keys according to the condition.

In other words, you have a list of keys, and you have determined list of keys that have some feature. Now you can either take messages that are both in the first list and the second list OR are in the first list but are not in the second list (conditition = false and true respectively). What makes this more complex is that second list of keys might not be a subset of the first list of keys.

Parameters
string[]$keysList of keys to filter.
string[]$condKeysSecond list of keys for filtering.
bool$conditionTrue (default) to return keys which are on first but not on the second list, false to return keys which are on both. second.
Returns
string[] Filtered keys.

Definition at line 417 of file MessageCollection.php.

◆ filterReviewer()

MessageCollection::filterReviewer ( array $keys,
$condition,
$user )
protected

Filters list of keys according to whether the user has accepted them.

Parameters
string[]$keysList of keys to filter.
bool$conditionTrue to remove translatations $user has accepted, false to get only translations accepted by $user.
int$userUserid
Returns
string[] Filtered keys.

Definition at line 556 of file MessageCollection.php.

◆ filterUntranslatedOptional()

MessageCollection::filterUntranslatedOptional ( )

Definition at line 390 of file MessageCollection.php.

◆ fixKeys()

MessageCollection::fixKeys ( )
protected

Takes list of keys and converts them into database format.

Returns
array ( string => string ) Array of keys in database format indexed by display format.

Definition at line 605 of file MessageCollection.php.

◆ getAuthors()

MessageCollection::getAuthors ( )

Lists all translators that have contributed to the latest revisions of each translation.

Causes translations to be loaded from the database. Is not affected by filters.

Returns
string[] List of usernames.

Definition at line 158 of file MessageCollection.php.

◆ getAvailableFilters()

static MessageCollection::getAvailableFilters ( )
static
Returns
array

Definition at line 334 of file MessageCollection.php.

◆ getLanguage()

MessageCollection::getLanguage ( )
Returns
string

Definition at line 93 of file MessageCollection.php.

◆ getMessageKeys()

MessageCollection::getMessageKeys ( )

Returns list of message keys that are used in this collection after filtering.

Returns
string[]
Since
2011-12-28

Definition at line 139 of file MessageCollection.php.

◆ getReverseMap()

MessageCollection::getReverseMap ( )

Creates a two-dimensional map of namespace and pagenames.

Since
2011-12-23
Returns
array

Definition at line 794 of file MessageCollection.php.

◆ getTags()

MessageCollection::getTags ( $type)

Returns stored message tags.

Parameters
string$typeTag type, usually optional or ignored.
Returns
string[] List of keys with given tag.

Definition at line 148 of file MessageCollection.php.

◆ getTitleConds()

MessageCollection::getTitleConds ( $db)
protected

Of the current set of keys, construct database query conditions.

Since
2011-12-28
Parameters
\Wikimedia\Rdbms\IDatabase$db
Returns
string[]

Definition at line 740 of file MessageCollection.php.

◆ getTitles()

MessageCollection::getTitles ( )

Returns list of TitleValues of messages that are used in this collection after filtering.

Returns
TitleValue[]
Since
2011-12-28

Definition at line 130 of file MessageCollection.php.

◆ initMessages()

MessageCollection::initMessages ( )

Constructs all TMessages from the data accumulated so far.

Usually there is no need to call this method directly.

Definition at line 813 of file MessageCollection.php.

◆ key()

MessageCollection::key ( )

Definition at line 978 of file MessageCollection.php.

◆ keys()

MessageCollection::keys ( )

Returns list of available message keys.

This is affected by filtering.

Returns
array List of database keys indexed by display keys (TitleValue).

Definition at line 121 of file MessageCollection.php.

◆ loadData()

MessageCollection::loadData ( array $keys,
?array $titleConds = null )
protected

Loads translation for given list of keys.

Parameters
string[]$keysList of keys in database format.
string[] | null$titleCondsDatabase query condition based on current keys.

Definition at line 702 of file MessageCollection.php.

◆ loadInfo()

MessageCollection::loadInfo ( array $keys,
?array $titleConds = null )
protected

Loads existence and fuzzy state for given list of keys.

Parameters
string[]$keysList of keys in database format.
string[] | null$titleCondsDatabase query condition based on current keys.

Definition at line 624 of file MessageCollection.php.

◆ loadReviewInfo()

MessageCollection::loadReviewInfo ( array $keys,
?array $titleConds = null )
protected

Loads reviewers for given messages.

Parameters
string[]$keysList of keys in database format.
string[] | null$titleCondsDatabase query condition based on current keys.

Definition at line 663 of file MessageCollection.php.

◆ loadTranslations()

MessageCollection::loadTranslations ( )

Loads all message data.

Must be called before accessing the messages with ArrayAccess or iteration.

Definition at line 218 of file MessageCollection.php.

◆ newFromDefinitions()

static MessageCollection::newFromDefinitions ( MessageDefinitions $definitions,
$code )
static

Construct a new message collection from definitions.

Parameters
MessageDefinitions$definitions
string$codeLanguage code.
Returns
self

Definition at line 84 of file MessageCollection.php.

◆ next()

MessageCollection::next ( )

Definition at line 982 of file MessageCollection.php.

◆ offsetExists()

MessageCollection::offsetExists ( $offset)

ArrayAccess methods.

Parameters
mixed$offset
Returns
bool

Definition at line 911 of file MessageCollection.php.

◆ offsetGet()

MessageCollection::offsetGet ( $offset)
Parameters
mixed$offset
Returns
?TMessage

Definition at line 919 of file MessageCollection.php.

◆ offsetSet()

MessageCollection::offsetSet ( $offset,
$value )
Parameters
mixed$offset
mixed$value

Definition at line 927 of file MessageCollection.php.

◆ offsetUnset()

MessageCollection::offsetUnset ( $offset)
Parameters
mixed$offset

Definition at line 932 of file MessageCollection.php.

◆ resetForNewLanguage()

MessageCollection::resetForNewLanguage ( $code)

Some statistics scripts for example loop the same collection over every language.

This is a shortcut which keeps tags and definitions.

Parameters
string$code

Definition at line 235 of file MessageCollection.php.

◆ rewind()

MessageCollection::rewind ( )

Iterator method.

Definition at line 964 of file MessageCollection.php.

◆ rowToKey()

MessageCollection::rowToKey ( $row)
protected

Given two-dimensional map of namespace and pagenames, this uses database fields page_namespace and page_title as keys and returns the value for those indexes.

Since
2011-12-23
Parameters
stdClass$row
Returns
string|null

Definition at line 778 of file MessageCollection.php.

◆ setInFile()

MessageCollection::setInFile ( array $messages)

Set translation from file, as opposed to translation which only exists in the wiki because they are not exported and committed yet.

Parameters
string[]$messagesArray of translations indexed by display key.

Definition at line 104 of file MessageCollection.php.

◆ setTags()

MessageCollection::setTags ( $type,
array $keys )

Set message tags.

Parameters
string$typeTag type, usually ignored or optional.
string[]$keysList of display keys.

Definition at line 113 of file MessageCollection.php.

◆ slice()

MessageCollection::slice ( $offset,
$limit )

For paging messages.

One can count messages before and after slice.

Parameters
string$offset
int$limit
Returns
array Offsets that can be used for paging backwards and forwards
Since
String offests and return value since 2013-01-10

Definition at line 256 of file MessageCollection.php.

◆ valid()

MessageCollection::valid ( )

Definition at line 986 of file MessageCollection.php.

Member Data Documentation

◆ $code

MessageCollection::$code

Definition at line 35 of file MessageCollection.php.

◆ $keys

MessageCollection::$keys = []
protected

Definition at line 43 of file MessageCollection.php.

◆ $messages

MessageCollection::$messages = []
protected

Definition at line 45 of file MessageCollection.php.

◆ $tags

MessageCollection::$tags = []
protected

Definition at line 61 of file MessageCollection.php.


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