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

Static Public Member Functions

static getIsoCode ( $code, $name, $class)
 
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 getPreferredMonolingualString (array $multilingualStr, array $languages)
 Filters ZMonolingualString to preferred language.
 
static normalize ( $input)
 Returns a normalized ZObject.
 
static isTypeEqualTo ( $type1, $type2)
 Asserts whether two types are equivalent.
 
static normalizeZStringsAndZReferences ( $input)
 Returns the ZObject with normalized ZStrings and ZReferences.
 
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)
 

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: To consider further changes.

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

◆ getIsoCode()

static MediaWiki\Extension\WikiLambda\ZObjectUtils::getIsoCode ( $code,
$name,
$class )
static
Parameters
string$codeThe MW language code
string$nameThe plain text name of the language
string$classThe name of the class for the HTML element
Returns
string the element to be rendered

◆ 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

◆ getPreferredMonolingualString()

static MediaWiki\Extension\WikiLambda\ZObjectUtils::getPreferredMonolingualString ( array $multilingualStr,
array $languages )
static

Filters ZMonolingualString to preferred language.

Returns the preferred ZMonolingualString of a ZMultilingualString given an array of preferred languages.

Parameters
array$multilingualStrdecoded JSON for a ZMultilingualString value (Z12K1)
string[]$languagesarray of language Zids
Returns
array same ZMultilingualString value with only one item of the preferred language

◆ getRequiredZids()

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

◆ 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

◆ 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

◆ normalize()

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

Returns a normalized ZObject.

Parameters
string | array | stdClass$inputdecoded JSON canonical form of a ZObject
Returns
string|array|stdClass same ZObject in normal form

◆ normalizeZStringsAndZReferences()

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

Returns the ZObject with normalized ZStrings and ZReferences.

Given a canonical ZObject, returns the normal form with the following exceptions: lists, ZMultilingualString, ZMonolingualString

Deprecated
Parameters
string | array | stdClass$inputdecoded JSON canonical form of a ZObject
Returns
string|array|stdClass same ZObject in normal form except lists, ZMultilingualStrings and ZMonolingualStrings

◆ 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)

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