WikiLambda
MediaWiki WikiLambda extension
Loading...
Searching...
No Matches
MediaWiki\Extension\WikiLambda\ZObjectUtils Class Reference

Static Public Member Functions

static wrapBCP47CodeInFakeCodexChip (string $code, string $label, string $class)
 Render a language 'Chip' of a language code with a hover-title of the language's label.
 
static isValidSerialisedZObject (string $input)
 
static isValidZObject ( $input)
 
static isValidZObjectList (array $input)
 
static isValidZObjectResolver ( $input)
 
static isValidZObjectRecord (stdClass $input)
 
static canonicalize ( $input)
 Canonicalizes a ZObject.
 
static orderZKeyIDs (string $left, string $right)
 Compares IDs of ZKeys in an order.
 
static canonicalizeZRecord (stdClass $input)
 Canonicalizes a record-like ZObject.
 
static comparableString (string $input)
 Normalise and down-cast a label for database comparison by normalising Unicode, lower-casing, and collapsing accents.
 
static filterZMultilingualStringsToLanguage ( $input, array $languages=[])
 Filters ZObject to preferred language.
 
static isTypeEqualTo ( $type1, $type2)
 Asserts whether two types are equivalent.
 
static isValidZObjectReference (string $input)
 Is the input a ZObject reference key (e.g.
 
static isNullReference (string $input)
 Is the input a null reference (Z0)?
 
static isValidOrNullZObjectReference (string $input)
 Is the input a ZObject reference key (e.g.
 
static isValidId (string $input)
 Is the input a valid possible identifier across WMF projects?
 
static isValidZObjectKey (string $input)
 Is the input a ZObject reference key (e.g.
 
static isValidZObjectGlobalKey (string $input)
 Is the input a global ZObject reference key (e.g.
 
static getZObjectReferenceFromKey (string $input)
 Split out the ZObject reference from a given global reference key (e.g.
 
static getIterativeList ( $list)
 Given an array or a ZTypedList, returns an array that can be iterated over.
 
static getRequiredZids ( $zobject)
 
static getLabelOfReference ( $zid, $zobject, $lang)
 Returns the natural language label of a given Zid in the language passed as parameter or available fallback languages.
 
static getLabelOfGlobalKey ( $key, $zobject, $lang)
 Returns the natural language label of a given type key, function argument or error key in the language passed as parameter or available fallback languages.
 
static getLabelOfLocalKey ( $key, $zobject, $data, $lang)
 
static getLabelOfErrorTypeKey ( $key, $zobject, $lang)
 Returns the natural language label of a given ZKey in the language passed as parameter or available fallback languages.
 
static getLabelOfTypeKey ( $key, $zobject, $lang)
 Returns the natural language label of a given ZKey in the language passed as parameter or available fallback languages.
 
static getLabelOfFunctionArgument ( $key, $zobject, $lang)
 Returns the natural language label of a given ZArgument in the language passed as parameter or available fallback languages.
 
static extractHumanReadableZObject ( $zobject, $data, $lang)
 Translates a serialized ZObject from Zids and ZKeys to natural language in the language passed as parameter or available fallback languages.
 
static isCompatibleType (ZObject $accepted, ZObject $input)
 
static getZid ( $zobject)
 Get the ZID of the input if it's a persistent ZObject or a reference to one.
 
static makeCacheKeyFromZObject ( $query)
 Walk a given input ZObject, and make a cache key constructed of its keys and values, with any ZObject referenced being expanded to also include its revision ID.
 
static readTestFile ( $fileName)
 Reads file contents from test data directory.
 

Member Function Documentation

◆ canonicalize()

static MediaWiki\Extension\WikiLambda\ZObjectUtils::canonicalize ( $input)
static

Canonicalizes a ZObject.

Parameters
string | array | stdClass$inputdecoded JSON object for a valid ZObject
Returns
string|array|stdClass canonical decoded JSON object of same ZObject

◆ canonicalizeZRecord()

static MediaWiki\Extension\WikiLambda\ZObjectUtils::canonicalizeZRecord ( stdClass $input)
static

Canonicalizes a record-like ZObject.

This trims and sorts the keys.

Parameters
stdClass$inputThe decoded JSON object of a well-formed ZObject
Returns
stdClass Canonical decoded JSON object representing the same ZObject

◆ comparableString()

static MediaWiki\Extension\WikiLambda\ZObjectUtils::comparableString ( string $input)
static

Normalise and down-cast a label for database comparison by normalising Unicode, lower-casing, and collapsing accents.

TODO (T362250): To consider further changes; is this sufficient for all use cases and languages?

Parameters
string$inputThe input
Returns
string

◆ extractHumanReadableZObject()

static MediaWiki\Extension\WikiLambda\ZObjectUtils::extractHumanReadableZObject ( $zobject,
$data,
$lang )
static

Translates a serialized ZObject from Zids and ZKeys to natural language in the language passed as parameter or available fallback languages.

Parameters
stdClass | array | string$zobject
ZPersistentObject[]$data
Language$lang
Returns
stdClass|array|string

◆ filterZMultilingualStringsToLanguage()

static MediaWiki\Extension\WikiLambda\ZObjectUtils::filterZMultilingualStringsToLanguage ( $input,
array $languages = [] )
static

Filters ZObject to preferred language.

Given a ZObject, reduces all its ZMultilingualStrings to only the preferred language or fallbacks.

Parameters
array | stdClass | string$inputdecoded JSON object for a ZObject
string[]$languagesarray of language Zids
Returns
string|array|stdClass same ZObject with only selected Monolingual string for each of its Multilingual strings

◆ getIterativeList()

static MediaWiki\Extension\WikiLambda\ZObjectUtils::getIterativeList ( $list)
static

Given an array or a ZTypedList, returns an array that can be iterated over.

Parameters
array | ZTypedList$list
Returns
array
+ Here is the caller graph for this function:

◆ getLabelOfErrorTypeKey()

static MediaWiki\Extension\WikiLambda\ZObjectUtils::getLabelOfErrorTypeKey ( $key,
$zobject,
$lang )
static

Returns the natural language label of a given ZKey in the language passed as parameter or available fallback languages.

If not available, returns the non-translated ZKey.

Parameters
string$key
ZPersistentObject$zobject
Language$lang
Returns
string

◆ getLabelOfFunctionArgument()

static MediaWiki\Extension\WikiLambda\ZObjectUtils::getLabelOfFunctionArgument ( $key,
$zobject,
$lang )
static

Returns the natural language label of a given ZArgument in the language passed as parameter or available fallback languages.

If not available, returns the non-translated ZKey.

Parameters
string$key
ZPersistentObject$zobject
Language$lang
Returns
string

◆ getLabelOfGlobalKey()

static MediaWiki\Extension\WikiLambda\ZObjectUtils::getLabelOfGlobalKey ( $key,
$zobject,
$lang )
static

Returns the natural language label of a given type key, function argument or error key in the language passed as parameter or available fallback languages.

If not available, returns the untranslated key Id.

Parameters
string$key
ZPersistentObject$zobject
Language$lang
Returns
string

◆ getLabelOfLocalKey()

static MediaWiki\Extension\WikiLambda\ZObjectUtils::getLabelOfLocalKey ( $key,
$zobject,
$data,
$lang )
static
Parameters
string$key
\stdClass$zobject
ZPersistentObject[]$data
Language$lang
Returns
string

◆ getLabelOfReference()

static MediaWiki\Extension\WikiLambda\ZObjectUtils::getLabelOfReference ( $zid,
$zobject,
$lang )
static

Returns the natural language label of a given Zid in the language passed as parameter or available fallback languages.

If not available, returns the non-translated Zid.

Parameters
string$zid
ZPersistentObject$zobject
Language$lang
Returns
string

◆ getLabelOfTypeKey()

static MediaWiki\Extension\WikiLambda\ZObjectUtils::getLabelOfTypeKey ( $key,
$zobject,
$lang )
static

Returns the natural language label of a given ZKey in the language passed as parameter or available fallback languages.

If not available, returns the non-translated ZKey.

Parameters
string$key
ZPersistentObject$zobject
Language$lang
Returns
string

◆ getRequiredZids()

static MediaWiki\Extension\WikiLambda\ZObjectUtils::getRequiredZids ( $zobject)
static
Parameters
string | array | \stdClass$zobject
Returns
array

◆ getZid()

static MediaWiki\Extension\WikiLambda\ZObjectUtils::getZid ( $zobject)
static

Get the ZID of the input if it's a persistent ZObject or a reference to one.

Parameters
mixed$zobjectThe ZObject to examine for
Returns
string The ZID of the given ZObject, or Z0
+ Here is the call graph for this function:

◆ getZObjectReferenceFromKey()

static MediaWiki\Extension\WikiLambda\ZObjectUtils::getZObjectReferenceFromKey ( string $input)
static

Split out the ZObject reference from a given global reference key (e.g.

'Z1' from 'Z1K1').

Parameters
string$input
Returns
string
+ Here is the caller graph for this function:

◆ isCompatibleType()

static MediaWiki\Extension\WikiLambda\ZObjectUtils::isCompatibleType ( ZObject $accepted,
ZObject $input )
static
Parameters
ZObject$acceptedThe ZObject we accept (typically a ZReference)
ZObject$inputA ZObject we're looking to evaluate whether it's compatible
Returns
bool True if the types are compatible

◆ isNullReference()

static MediaWiki\Extension\WikiLambda\ZObjectUtils::isNullReference ( string $input)
static

Is the input a null reference (Z0)?

Parameters
string$input
Returns
bool

◆ isTypeEqualTo()

static MediaWiki\Extension\WikiLambda\ZObjectUtils::isTypeEqualTo ( $type1,
$type2 )
static

Asserts whether two types are equivalent.

Parameters
stdClass | string$type1
stdClass | string$type2
Returns
bool

◆ isValidId()

static MediaWiki\Extension\WikiLambda\ZObjectUtils::isValidId ( string $input)
static

Is the input a valid possible identifier across WMF projects?

Parameters
string$input
Returns
bool
+ Here is the caller graph for this function:

◆ isValidOrNullZObjectReference()

static MediaWiki\Extension\WikiLambda\ZObjectUtils::isValidOrNullZObjectReference ( string $input)
static

Is the input a ZObject reference key (e.g.

Z1 or Z12345)?

Parameters
string$input
Returns
bool

◆ isValidSerialisedZObject()

static MediaWiki\Extension\WikiLambda\ZObjectUtils::isValidSerialisedZObject ( string $input)
static
Parameters
string$input
Returns
bool
+ Here is the call graph for this function:

◆ isValidZObject()

static MediaWiki\Extension\WikiLambda\ZObjectUtils::isValidZObject ( $input)
static
Parameters
string | array | stdClass$input
Returns
bool
Exceptions
ZErrorException
+ Here is the caller graph for this function:

◆ isValidZObjectGlobalKey()

static MediaWiki\Extension\WikiLambda\ZObjectUtils::isValidZObjectGlobalKey ( string $input)
static

Is the input a global ZObject reference key (e.g.

Z1K1)?

Parameters
string$input
Returns
bool

◆ isValidZObjectKey()

static MediaWiki\Extension\WikiLambda\ZObjectUtils::isValidZObjectKey ( string $input)
static

Is the input a ZObject reference key (e.g.

Z1K1 or K12345)?

Parameters
string$input
Returns
bool
+ Here is the caller graph for this function:

◆ isValidZObjectList()

static MediaWiki\Extension\WikiLambda\ZObjectUtils::isValidZObjectList ( array $input)
static
Parameters
array$input
Returns
bool
Exceptions
ZErrorException

◆ isValidZObjectRecord()

static MediaWiki\Extension\WikiLambda\ZObjectUtils::isValidZObjectRecord ( stdClass $input)
static
Parameters
stdClass$input
Returns
bool
Exceptions
ZErrorException

◆ isValidZObjectReference()

static MediaWiki\Extension\WikiLambda\ZObjectUtils::isValidZObjectReference ( string $input)
static

Is the input a ZObject reference key (e.g.

Z1 or Z12345)?

Parameters
string$input
Returns
bool
+ Here is the caller graph for this function:

◆ isValidZObjectResolver()

static MediaWiki\Extension\WikiLambda\ZObjectUtils::isValidZObjectResolver ( $input)
static
Parameters
mixed$input
Returns
bool
Exceptions
ZErrorException

◆ makeCacheKeyFromZObject()

static MediaWiki\Extension\WikiLambda\ZObjectUtils::makeCacheKeyFromZObject ( $query)
static

Walk a given input ZObject, and make a cache key constructed of its keys and values, with any ZObject referenced being expanded to also include its revision ID.

E.g. { "Z1K1": "Z7", "Z7K1": "Z801", "Z801K1": "Hey" } => 'Z1K1|Z7#1,Z7K1|Z801#2,Z801K1|Hey'

TODO (T338245): Is this cache key too broad? Can we simplify?

TODO (T338246): When a Z7/Function call, we also need to poison the key with the revision ID of the relevant implementation, but we don't know which was selected, as that's the call of the function orchestrator.

Parameters
\stdClass | array$query
Returns
string response object returned by orchestrator

◆ orderZKeyIDs()

static MediaWiki\Extension\WikiLambda\ZObjectUtils::orderZKeyIDs ( string $left,
string $right )
static

Compares IDs of ZKeys in an order.

First come global ZIDs, then local ones. The globals are sorted first numerically by the Z-Number, and then by the K-Number.

Parameters
string$leftleft key for comparision
string$rightright key for comparision
Returns
int whether left is smaller (-1) than right or not (+1)

◆ readTestFile()

static MediaWiki\Extension\WikiLambda\ZObjectUtils::readTestFile ( $fileName)
static

Reads file contents from test data directory.

Parameters
string$fileName
Returns
string file contents @codeCoverageIgnore
+ Here is the caller graph for this function:

◆ wrapBCP47CodeInFakeCodexChip()

static MediaWiki\Extension\WikiLambda\ZObjectUtils::wrapBCP47CodeInFakeCodexChip ( string $code,
string $label,
string $class )
static

Render a language 'Chip' of a language code with a hover-title of the language's label.

TODO (T309039): use the chip component and ZID language object here instead

Parameters
string$codeThe BCP47 language code, e.g. 'fr' or 'en-US'.
string$labelThe plain text label of the language, e.g. 'français' or 'American English'
string$classThe name of the class for the HTML element in which to wrap the label
Returns
string The HTML of the element to be rendered
+ Here is the caller graph for this function:

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