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

This class abstract MessageGroup statistics calculation and storing. More...

Static Public Member Functions

static getEmptyStats ()
 Returns empty stats array.
 
static forItem ( $id, $code, $flags=0)
 Returns stats for given group in given language.
 
static forLanguage ( $code, $flags=0)
 Returns stats for all groups in given language.
 
static forGroup ( $id, $flags=0)
 Returns stats for all languages in given group.
 
static forEverything ( $flags=0)
 Returns stats for all group in all languages.
 
static clear (MessageHandle $handle)
 Recalculate stats for all groups associated with the message.
 
static clearGroup ( $id, int $flags=0)
 Recalculate stats for given group(s).
 
static getApproximateLanguageStats ()
 Fetch aggregated statistics for all languages across groups.
 
static getLanguages ()
 Get list of supported languages for statistics.
 
static clearLanguage ( $code)
 
static clearAll ()
 Purges all cached stats.
 
static multiAdd (&$a, $b)
 
static getDatabaseIdForGroupId ( $id)
 
static getStatsForCollection (MessageCollection $collection)
 

Public Attributes

const TOTAL = 0
 Array index.
 
const TRANSLATED = 1
 Array index.
 
const FUZZY = 2
 Array index.
 
const PROOFREAD = 3
 Array index.
 
const FLAG_CACHE_ONLY = 1
 If stats are not cached, do not attempt to calculate them on the fly.
 
const FLAG_NO_CACHE = 2
 Ignore cached values. Useful for updating stale values.
 
const FLAG_IMMEDIATE_WRITES = 4
 Do not defer updates. Meant for jobs like MessageGroupStatsRebuildJob.
 

Static Protected Member Functions

static getUnknownStats ()
 Returns empty stats array that indicates stats are incomplete or unknown.
 
static extractResults ( $res, array $ids, array $stats=[])
 Use this to extract results returned from selectRowsIdLang.
 
static extractNumbers ( $row)
 Returns an array of needed database fields.
 
static forLanguageInternal ( $code, array $stats, $flags)
 
static expandAggregates (AggregateMessageGroup $agg)
 
static forGroupInternal (MessageGroup $group, array $stats, $flags)
 
static selectRowsIdLang (?array $ids, ?array $codes, $flags)
 Fetch rows from the database.
 
static forItemInternal (&$stats, MessageGroup $group, $code, $flags)
 
static calculateGroup (MessageGroup $group, $code)
 
static queueUpdates ( $flags)
 
static withLock (IDatabase $dbw, $key, $method, $callback)
 

Static Protected Attributes

static $updates = []
 

Detailed Description

This class abstract MessageGroup statistics calculation and storing.

You can access stats easily per language or per group. Stat array for each item is of format array( total, translate, fuzzy ).

Definition at line 26 of file MessageGroupStats.php.

Member Function Documentation

◆ calculateGroup()

static MessageGroupStats::calculateGroup ( MessageGroup $group,
$code )
staticprotected
Parameters
MessageGroup$group
string$codeLanguage code
Returns
int[] ( total, translated, fuzzy, proofread )

Definition at line 614 of file MessageGroupStats.php.

◆ clear()

static MessageGroupStats::clear ( MessageHandle $handle)
static

Recalculate stats for all groups associated with the message.

Hook: TranslateEventTranslationReview

Parameters
MessageHandle$handle

Definition at line 196 of file MessageGroupStats.php.

◆ clearAll()

static MessageGroupStats::clearAll ( )
static

Purges all cached stats.

Mostly for testing purposes. Calling this in normal operation will cause performance issues.

Definition at line 351 of file MessageGroupStats.php.

◆ clearGroup()

static MessageGroupStats::clearGroup ( $id,
int $flags = 0 )
static

Recalculate stats for given group(s).

Parameters
string | string[]$idMessage group ids.
int$flagsCombination of FLAG_* constants.

Definition at line 211 of file MessageGroupStats.php.

◆ clearLanguage()

static MessageGroupStats::clearLanguage ( $code)
static

Definition at line 336 of file MessageGroupStats.php.

◆ expandAggregates()

static MessageGroupStats::expandAggregates ( AggregateMessageGroup $agg)
staticprotected
Parameters
AggregateMessageGroup$agg
Returns
MessageGroup[]

Definition at line 425 of file MessageGroupStats.php.

◆ extractNumbers()

static MessageGroupStats::extractNumbers ( $row)
staticprotected

Returns an array of needed database fields.

Parameters
stdClass$row
Returns
array

Definition at line 389 of file MessageGroupStats.php.

◆ extractResults()

static MessageGroupStats::extractResults ( $res,
array $ids,
array $stats = [] )
staticprotected

Use this to extract results returned from selectRowsIdLang.

You must pass the message group ids you want to retrieve. Entries that do not match are not returned.

Parameters
iterable$resDatabase result object
string[]$idsList of message group ids
array[]$statsOptional array to append results to.
Returns
array[]

Definition at line 366 of file MessageGroupStats.php.

◆ forEverything()

static MessageGroupStats::forEverything ( $flags = 0)
static

Returns stats for all group in all languages.

Might be slow, might use lots of memory. Returns two dimensional array indexed by group and language.

Parameters
int$flagsCombination of FLAG_* constants.
Returns
array[]

Definition at line 166 of file MessageGroupStats.php.

◆ forGroup()

static MessageGroupStats::forGroup ( $id,
$flags = 0 )
static

Returns stats for all languages in given group.

Parameters
string$idGroup id
int$flagsCombination of FLAG_* constants.
Returns
array[]

Definition at line 140 of file MessageGroupStats.php.

◆ forGroupInternal()

static MessageGroupStats::forGroupInternal ( MessageGroup $group,
array $stats,
$flags )
staticprotected
Parameters
MessageGroup$group
array[]$stats
int$flagsCombination of FLAG_* constants.
Returns
array[]

Definition at line 446 of file MessageGroupStats.php.

◆ forItem()

static MessageGroupStats::forItem ( $id,
$code,
$flags = 0 )
static

Returns stats for given group in given language.

Parameters
string$idGroup id
string$codeLanguage code
int$flagsCombination of FLAG_* constants.
Returns
null[]|int[]

Definition at line 87 of file MessageGroupStats.php.

◆ forItemInternal()

static MessageGroupStats::forItemInternal ( & $stats,
MessageGroup $group,
$code,
$flags )
staticprotected
Parameters
array[]&$stats
MessageGroup$group
string$codeLanguage code
int$flagsCombination of FLAG_* constants.
Returns
null[]|int[]

Definition at line 505 of file MessageGroupStats.php.

◆ forLanguage()

static MessageGroupStats::forLanguage ( $code,
$flags = 0 )
static

Returns stats for all groups in given language.

Parameters
string$codeLanguage code
int$flagsCombination of FLAG_* constants.
Returns
array[]

Definition at line 111 of file MessageGroupStats.php.

◆ forLanguageInternal()

static MessageGroupStats::forLanguageInternal ( $code,
array $stats,
$flags )
staticprotected
Parameters
string$codeLanguage code
array[]$stats
int$flagsCombination of FLAG_* constants.
Returns
array[]

Definition at line 404 of file MessageGroupStats.php.

◆ getApproximateLanguageStats()

static MessageGroupStats::getApproximateLanguageStats ( )
static

Fetch aggregated statistics for all languages across groups.

The stats are cached in the WANObjectCache, and recalculated on the fly if the values are stale. The statistics may lag behind the actuals due to extra and missing values

Returns
array[] ( Language Code => Language Stats )

Definition at line 227 of file MessageGroupStats.php.

◆ getDatabaseIdForGroupId()

static MessageGroupStats::getDatabaseIdForGroupId ( $id)
static

Definition at line 704 of file MessageGroupStats.php.

◆ getEmptyStats()

static MessageGroupStats::getEmptyStats ( )
static

Returns empty stats array.

Useful because the number of elements may change.

Returns
int[]
Since
2012-09-21

Definition at line 55 of file MessageGroupStats.php.

◆ getLanguages()

static MessageGroupStats::getLanguages ( )
static

Get list of supported languages for statistics.

Returns
string[]

Definition at line 326 of file MessageGroupStats.php.

◆ getStatsForCollection()

static MessageGroupStats::getStatsForCollection ( MessageCollection $collection)
static

Definition at line 715 of file MessageGroupStats.php.

◆ getUnknownStats()

static MessageGroupStats::getUnknownStats ( )
staticprotected

Returns empty stats array that indicates stats are incomplete or unknown.

Returns
null[]
Since
2013-01-02

Definition at line 65 of file MessageGroupStats.php.

◆ multiAdd()

static MessageGroupStats::multiAdd ( & $a,
$b )
static

Definition at line 598 of file MessageGroupStats.php.

◆ queueUpdates()

static MessageGroupStats::queueUpdates ( $flags)
staticprotected

Definition at line 639 of file MessageGroupStats.php.

◆ selectRowsIdLang()

static MessageGroupStats::selectRowsIdLang ( ?array $ids,
?array $codes,
$flags )
staticprotected

Fetch rows from the database.

Use extractResults to process this value.

Parameters
?string[]$idsList of message group ids
?string[]$codesList of language codes
int$flagsCombination of FLAG_* constants.
Returns
iterable Database result object

Definition at line 477 of file MessageGroupStats.php.

◆ withLock()

static MessageGroupStats::withLock ( IDatabase $dbw,
$key,
$method,
$callback )
staticprotected

Definition at line 688 of file MessageGroupStats.php.

Member Data Documentation

◆ $updates

MessageGroupStats::$updates = []
staticprotected

Definition at line 45 of file MessageGroupStats.php.

◆ FLAG_CACHE_ONLY

const MessageGroupStats::FLAG_CACHE_ONLY = 1

If stats are not cached, do not attempt to calculate them on the fly.

Definition at line 38 of file MessageGroupStats.php.

◆ FLAG_IMMEDIATE_WRITES

const MessageGroupStats::FLAG_IMMEDIATE_WRITES = 4

Do not defer updates. Meant for jobs like MessageGroupStatsRebuildJob.

Definition at line 42 of file MessageGroupStats.php.

◆ FLAG_NO_CACHE

const MessageGroupStats::FLAG_NO_CACHE = 2

Ignore cached values. Useful for updating stale values.

Definition at line 40 of file MessageGroupStats.php.

◆ FUZZY

const MessageGroupStats::FUZZY = 2

Array index.

Definition at line 34 of file MessageGroupStats.php.

◆ PROOFREAD

const MessageGroupStats::PROOFREAD = 3

Array index.

Definition at line 35 of file MessageGroupStats.php.

◆ TOTAL

const MessageGroupStats::TOTAL = 0

Array index.

Definition at line 32 of file MessageGroupStats.php.

◆ TRANSLATED

const MessageGroupStats::TRANSLATED = 1

Array index.

Definition at line 33 of file MessageGroupStats.php.


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