MediaWiki master
MediaWiki\Api\ApiResult Class Reference

This class represents the result of the API operations. More...

Inherits MediaWiki\Api\ApiSerializable.

Collaboration diagram for MediaWiki\Api\ApiResult:

Public Member Functions

 __construct ( $maxSize)
 
 serializeForApiResult ()
 Allow for adding one ApiResult into another.
 
 setErrorFormatter (ApiErrorFormatter $formatter)
 

Public Attributes

const ADD_ON_TOP = 2
 For addValue(), setValue() and similar functions, if the value does not exist, add it as the first element.
 
const META_BC_BOOLS = '_BC_bools'
 Key for the 'BC bools' metadata item.
 
const META_BC_SUBELEMENTS = '_BC_subelements'
 Key for the 'BC subelements' metadata item.
 
const META_CONTENT = '_content'
 Key for the 'content' metadata item.
 
const META_INDEXED_TAG_NAME = '_element'
 Key for the 'indexed tag name' metadata item.
 
const META_KVP_KEY_NAME = '_kvpkeyname'
 Key for the metadata item whose value specifies the name used for the kvp key in the alternative output format with META_TYPE 'kvp' or 'BCkvp', i.e.
 
const META_KVP_MERGE = '_kvpmerge'
 Key for the metadata item that indicates that the KVP key should be added into an assoc value, i.e.
 
const META_PRESERVE_KEYS = '_preservekeys'
 Key for the 'preserve keys' metadata item.
 
const META_SUBELEMENTS = '_subelements'
 Key for the 'subelements' metadata item.
 
const META_TYPE = '_type'
 Key for the 'type' metadata item.
 
const NO_SIZE_CHECK = 4
 For addValue() and similar functions, do not check size while adding a value Don't use this unless you REALLY know what you're doing.
 
const NO_VALIDATE = self::NO_SIZE_CHECK | 8
 For addValue(), setValue() and similar functions, do not validate data.
 
const OVERRIDE = 1
 Override existing value in addValue(), setValue(), and similar functions.
 

Content

 reset ()
 Clear the current result data.
 
 getResultData ( $path=[], $transforms=[])
 Get the result data array.
 
 getSize ()
 Get the size of the result, i.e.
 
 addValue ( $path, $name, $value, $flags=0)
 Add value to the output data at the given path.
 
 removeValue ( $path, $name, $flags=0)
 Remove value from the output data at the given path.
 
 addContentValue ( $path, $name, $value, $flags=0)
 Add value to the output data at the given path and mark as META_CONTENT.
 
 addParsedLimit ( $moduleName, $limit)
 Add the numeric limit for a limit=max to the result.
 
static setValue (array &$arr, $name, $value, $flags=0)
 Add an output value to the array by name.
 
static unsetValue (array &$arr, $name)
 Remove an output value to the array by name.
 
static setContentValue (array &$arr, $name, $value, $flags=0)
 Add an output value to the array by name and mark as META_CONTENT.
 

Metadata

 addContentField ( $path, $name, $flags=0)
 Set the name of the content field name (META_CONTENT)
 
 addSubelementsList ( $path, $names)
 Causes the elements with the specified names to be output as subelements rather than attributes.
 
 removeSubelementsList ( $path, $names)
 Causes the elements with the specified names to be output as attributes (when possible) rather than as subelements.
 
 addIndexedTagName ( $path, $tag)
 Set the tag name for numeric-keyed values in XML format.
 
 addIndexedTagNameRecursive ( $path, $tag)
 Set indexed tag name on $path and all subarrays.
 
 addPreserveKeysList ( $path, $names)
 Preserve specified keys.
 
 removePreserveKeysList ( $path, $names)
 Don't preserve specified keys.
 
 addArrayType ( $path, $tag, $kvpKeyName=null)
 Set the array data type for a path.
 
 addArrayTypeRecursive ( $path, $tag, $kvpKeyName=null)
 Set the array data type for a path recursively.
 
static setContentField (array &$arr, $name, $flags=0)
 Set the name of the content field name (META_CONTENT)
 
static setSubelementsList (array &$arr, $names)
 Causes the elements with the specified names to be output as subelements rather than attributes.
 
static unsetSubelementsList (array &$arr, $names)
 Causes the elements with the specified names to be output as attributes (when possible) rather than as subelements.
 
static setIndexedTagName (array &$arr, $tag)
 Set the tag name for numeric-keyed values in XML format.
 
static setIndexedTagNameRecursive (array &$arr, $tag)
 Set indexed tag name on $arr and all subarrays.
 
static setPreserveKeysList (array &$arr, $names)
 Preserve specified keys.
 
static unsetPreserveKeysList (array &$arr, $names)
 Don't preserve specified keys.
 
static setArrayType (array &$arr, $type, $kvpKeyName=null)
 Set the array data type.
 
static setArrayTypeRecursive (array &$arr, $type, $kvpKeyName=null)
 Set the array data type recursively.
 

Utility

static isMetadataKey ( $key)
 Test whether a key should be considered metadata.
 
static stripMetadata ( $data)
 Recursively remove metadata keys from a data array or object.
 
static stripMetadataNonRecursive ( $data, &$metadata=null)
 Remove metadata keys from a data array or object, non-recursive.
 
static addMetadataToResultVars ( $vars, $forceHash=true)
 Add the correct metadata to an array of vars we want to export through the API.
 
static formatExpiry ( $expiry, $infinity='infinity')
 Format an expiry timestamp for API output.
 
static applyTransformations (array $dataIn, array $transforms)
 Apply transformations to an array, returning the transformed array.
 

Detailed Description

This class represents the result of the API operations.

It simply wraps a nested array structure, adding some functions to simplify array's modifications. As various modules execute, they add different pieces of information to this result, structuring it as it will be given to the client.

Each subarray may either be a dictionary - key-value pairs with unique keys, or lists, where the items are added using $data[] = $value notation.

Since
1.25 this is no longer a subclass of ApiBase

Definition at line 43 of file ApiResult.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Api\ApiResult::__construct ( $maxSize)
Parameters
int | false$maxSizeMaximum result "size", or false for no limit

Definition at line 163 of file ApiResult.php.

References MediaWiki\Api\ApiResult\reset().

Member Function Documentation

◆ addArrayType()

MediaWiki\Api\ApiResult::addArrayType ( $path,
$tag,
$kvpKeyName = null )

Set the array data type for a path.

Since
1.25
Parameters
array | string | null$pathSee ApiResult::addValue()
string$tagSee ApiResult::META_TYPE
string | null$kvpKeyNameSee ApiResult::META_KVP_KEY_NAME

Definition at line 748 of file ApiResult.php.

References $path, and MediaWiki\Api\ApiResult\setArrayType().

◆ addArrayTypeRecursive()

MediaWiki\Api\ApiResult::addArrayTypeRecursive ( $path,
$tag,
$kvpKeyName = null )

Set the array data type for a path recursively.

Since
1.25
Parameters
array | string | null$pathSee ApiResult::addValue()
string$tagSee ApiResult::META_TYPE
string | null$kvpKeyNameSee ApiResult::META_KVP_KEY_NAME

Definition at line 776 of file ApiResult.php.

References $path, and MediaWiki\Api\ApiResult\setArrayTypeRecursive().

◆ addContentField()

MediaWiki\Api\ApiResult::addContentField ( $path,
$name,
$flags = 0 )

Set the name of the content field name (META_CONTENT)

Since
1.25
Parameters
array | string | null$pathSee ApiResult::addValue()
string | int$nameName of the field
int$flagsZero or more OR-ed flags like OVERRIDE | ADD_ON_TOP.

Definition at line 554 of file ApiResult.php.

References $path, and MediaWiki\Api\ApiResult\setContentField().

Referenced by MediaWiki\Api\ApiResult\addContentValue().

◆ addContentValue()

MediaWiki\Api\ApiResult::addContentValue ( $path,
$name,
$value,
$flags = 0 )

Add value to the output data at the given path and mark as META_CONTENT.

Since
1.25
Parameters
array | string | null$pathSee ApiResult::addValue()
string | int$nameSee ApiResult::setValue()
mixed$value
int$flagsZero or more OR-ed flags like OVERRIDE | ADD_ON_TOP.
Returns
bool True if $value fits in the result, false if not

Definition at line 498 of file ApiResult.php.

References $path, MediaWiki\Api\ApiResult\addContentField(), and MediaWiki\Api\ApiResult\addValue().

◆ addIndexedTagName()

MediaWiki\Api\ApiResult::addIndexedTagName ( $path,
$tag )

Set the tag name for numeric-keyed values in XML format.

Since
1.25
Parameters
array | string | null$pathSee ApiResult::addValue()
string$tagTag name

Definition at line 630 of file ApiResult.php.

References $path, and MediaWiki\Api\ApiResult\setIndexedTagName().

◆ addIndexedTagNameRecursive()

MediaWiki\Api\ApiResult::addIndexedTagNameRecursive ( $path,
$tag )

Set indexed tag name on $path and all subarrays.

Since
1.25
Parameters
array | string | null$pathSee ApiResult::addValue()
string$tagTag name

Definition at line 661 of file ApiResult.php.

References $path, and MediaWiki\Api\ApiResult\setIndexedTagNameRecursive().

◆ addMetadataToResultVars()

static MediaWiki\Api\ApiResult::addMetadataToResultVars ( $vars,
$forceHash = true )
static

Add the correct metadata to an array of vars we want to export through the API.

Parameters
array$vars
bool$forceHash
Returns
array

Definition at line 1178 of file ApiResult.php.

References MediaWiki\Api\ApiResult\addMetadataToResultVars().

Referenced by MediaWiki\Api\ApiResult\addMetadataToResultVars(), MediaWiki\Api\ApiExpandTemplates\execute(), and MediaWiki\Api\ApiParse\execute().

◆ addParsedLimit()

MediaWiki\Api\ApiResult::addParsedLimit ( $moduleName,
$limit )

Add the numeric limit for a limit=max to the result.

Since
1.25
Parameters
string$moduleName
int$limit

Definition at line 513 of file ApiResult.php.

References MediaWiki\Api\ApiResult\addValue().

◆ addPreserveKeysList()

MediaWiki\Api\ApiResult::addPreserveKeysList ( $path,
$names )

Preserve specified keys.

Since
1.25
See also
self::setPreserveKeysList()
Parameters
array | string | null$pathSee ApiResult::addValue()
array | string$namesThe element name(s) to preserve

Definition at line 691 of file ApiResult.php.

References $path, and MediaWiki\Api\ApiResult\setPreserveKeysList().

◆ addSubelementsList()

MediaWiki\Api\ApiResult::addSubelementsList ( $path,
$names )

Causes the elements with the specified names to be output as subelements rather than attributes.

Since
1.25
Parameters
array | string | null$pathSee ApiResult::addValue()
array | string | int$namesThe element name(s) to be output as subelements

Definition at line 581 of file ApiResult.php.

References $path, and MediaWiki\Api\ApiResult\setSubelementsList().

◆ addValue()

MediaWiki\Api\ApiResult::addValue ( $path,
$name,
$value,
$flags = 0 )

Add value to the output data at the given path.

Path can be an indexed array, each element specifying the branch at which to add the new value. Setting $path to [ 'a', 'b', 'c' ] is equivalent to data['a']['b']['c'] = $value. If $path is null, the value will be inserted at the data root.

Parameters
array | string | int | null$path
string | int | null$nameSee ApiResult::setValue()
mixed$value
int$flagsZero or more OR-ed flags like OVERRIDE | ADD_ON_TOP. This parameter used to be boolean, and the value of OVERRIDE=1 was specifically chosen so that it would be backwards compatible with the new method signature.
Returns
bool True if $value fits in the result, false if not
Since
1.21 int $flags replaced boolean $override

Definition at line 407 of file ApiResult.php.

References $path, MediaWiki\Api\ApiResult\NO_VALIDATE, MediaWiki\Message\Message\numParam(), and MediaWiki\Api\ApiResult\setValue().

Referenced by MediaWiki\Api\ApiResult\addContentValue(), MediaWiki\Api\ApiResult\addParsedLimit(), MediaWiki\Debug\MWDebug\appendDebugInfoToApiResult(), MediaWiki\Api\ApiPageSet\populateGeneratorData(), and MediaWiki\Api\ApiContinuationManager\setContinuationIntoResult().

◆ applyTransformations()

static MediaWiki\Api\ApiResult::applyTransformations ( array $dataIn,
array $transforms )
staticprotected

Apply transformations to an array, returning the transformed array.

See also
ApiResult::getResultData()
Since
1.25
Parameters
array$dataIn
array$transforms
Returns
array|stdClass

Definition at line 809 of file ApiResult.php.

References MediaWiki\Api\ApiResult\applyTransformations(), MediaWiki\Api\ApiResult\META_CONTENT, MediaWiki\Api\ApiResult\META_KVP_KEY_NAME, MediaWiki\Api\ApiResult\META_TYPE, MediaWiki\Api\ApiResult\setPreserveKeysList(), and MediaWiki\Api\ApiResult\stripMetadataNonRecursive().

Referenced by MediaWiki\Api\ApiResult\applyTransformations(), and MediaWiki\Api\ApiResult\getResultData().

◆ formatExpiry()

static MediaWiki\Api\ApiResult::formatExpiry ( $expiry,
$infinity = 'infinity' )
static

Format an expiry timestamp for API output.

Since
1.29
Parameters
string$expiryExpiry timestamp, likely from the database
string$infinityUse this string for infinite expiry (only use this to maintain backward compatibility with existing output)
Returns
string Formatted expiry

Definition at line 1233 of file ApiResult.php.

References MediaWiki\MediaWikiServices\getInstance(), wfIsInfinity(), and wfTimestamp().

Referenced by MediaWiki\Api\ApiBlock\execute(), MediaWiki\Api\ApiProtect\execute(), MediaWiki\Api\ApiQueryBlocks\execute(), MediaWiki\Api\ApiQueryUsers\execute(), MediaWiki\Api\ApiQueryUserInfo\getCurrentUserInfo(), MediaWiki\Api\getExpiryFromParams(), and MediaWiki\Api\getWatchlistExpiry().

◆ getResultData()

MediaWiki\Api\ApiResult::getResultData ( $path = [],
$transforms = [] )

Get the result data array.

The returned value should be considered read-only.

Transformations include:

Custom: (callable) Applied before other transformations. Signature is function ( &$data, &$metadata ), return value is ignored. Called for each nested array.

BC: (array) This transformation does various adjustments to bring the output in line with the pre-1.25 result format. The value array is a list of flags: 'nobool', 'no*', 'nosub'.

  • Boolean-valued items are changed to '' if true or removed if false, unless listed in META_BC_BOOLS. This may be skipped by including 'nobool' in the value array.
  • The tag named by META_CONTENT is renamed to '*', and META_CONTENT is set to '*'. This may be skipped by including 'no*' in the value array.
  • Tags listed in META_BC_SUBELEMENTS will have their values changed to [ '*' => $value ]. This may be skipped by including 'nosub' in the value array.
  • If META_TYPE is 'BCarray', set it to 'default'
  • If META_TYPE is 'BCassoc', set it to 'default'
  • If META_TYPE is 'BCkvp', perform the transformation (even if the Types transformation is not being applied).

Types: (assoc) Apply transformations based on META_TYPE. The values array is an associative array with the following possible keys:

  • AssocAsObject: (bool) If true, return arrays with META_TYPE 'assoc' as objects.
  • ArmorKVP: (string) If provided, transform arrays with META_TYPE 'kvp' and 'BCkvp' into arrays of two-element arrays, something like this: $output = []; foreach ( $input as $key => $value ) { $pair = []; $pair[$META_KVP_KEY_NAME ?: $ArmorKVP_value] = $key; ApiResult::setContentValue( $pair, 'value', $value ); $output[] = $pair; }

Strip: (string) Strips metadata keys from the result.

  • 'all': Strip all metadata, recursively
  • 'base': Strip metadata at the top-level only.
  • 'none': Do not strip metadata.
  • 'bc': Like 'all', but leave certain pre-1.25 keys.
Since
1.25
Parameters
array | string | null$pathPath to fetch, see ApiResult::addValue
array$transformsSee above
Returns
mixed Result data, or null if not found

Definition at line 252 of file ApiResult.php.

References $path, and MediaWiki\Api\ApiResult\applyTransformations().

◆ getSize()

MediaWiki\Api\ApiResult::getSize ( )

Get the size of the result, i.e.

the amount of bytes in it

Returns
int

Definition at line 273 of file ApiResult.php.

◆ isMetadataKey()

static MediaWiki\Api\ApiResult::isMetadataKey ( $key)
static

Test whether a key should be considered metadata.

Parameters
string | int$key
Returns
bool

Definition at line 793 of file ApiResult.php.

Referenced by MediaWiki\Api\ApiFeedWatchlist\execute(), and MediaWiki\Api\ApiFormatXml\recXmlPrint().

◆ removePreserveKeysList()

MediaWiki\Api\ApiResult::removePreserveKeysList ( $path,
$names )

Don't preserve specified keys.

Since
1.25
See also
self::setPreserveKeysList()
Parameters
array | string | null$pathSee ApiResult::addValue()
array | string$namesThe element name(s) to not preserve

Definition at line 716 of file ApiResult.php.

References $path, and MediaWiki\Api\ApiResult\unsetPreserveKeysList().

◆ removeSubelementsList()

MediaWiki\Api\ApiResult::removeSubelementsList ( $path,
$names )

Causes the elements with the specified names to be output as attributes (when possible) rather than as subelements.

Since
1.25
Parameters
array | string | null$pathSee ApiResult::addValue()
array | string | int$namesThe element name(s) to not be output as subelements

Definition at line 606 of file ApiResult.php.

References $path, and MediaWiki\Api\ApiResult\unsetSubelementsList().

◆ removeValue()

MediaWiki\Api\ApiResult::removeValue ( $path,
$name,
$flags = 0 )

Remove value from the output data at the given path.

Since
1.25
Parameters
array | string | null$pathSee ApiResult::addValue()
string | int | null$nameIndex to remove at $path. If null, $path itself is removed.
int$flagsFlags used when adding the value
Returns
mixed Old value, or null

Definition at line 455 of file ApiResult.php.

References $path, and MediaWiki\Api\ApiResult\unsetValue().

◆ reset()

MediaWiki\Api\ApiResult::reset ( )

Clear the current result data.

Definition at line 192 of file ApiResult.php.

Referenced by MediaWiki\Api\ApiResult\__construct().

◆ serializeForApiResult()

MediaWiki\Api\ApiResult::serializeForApiResult ( )

Allow for adding one ApiResult into another.

Since
1.25
Returns
mixed

Implements MediaWiki\Api\ApiSerializable.

Definition at line 181 of file ApiResult.php.

◆ setArrayType()

◆ setArrayTypeRecursive()

static MediaWiki\Api\ApiResult::setArrayTypeRecursive ( array & $arr,
$type,
$kvpKeyName = null )
static

Set the array data type recursively.

Since
1.25
Parameters
array&$arr
string$typeSee ApiResult::META_TYPE
string | null$kvpKeyNameSee ApiResult::META_KVP_KEY_NAME

Definition at line 760 of file ApiResult.php.

References MediaWiki\Api\ApiResult\setArrayType(), and MediaWiki\Api\ApiResult\setArrayTypeRecursive().

Referenced by MediaWiki\Api\ApiResult\addArrayTypeRecursive(), MediaWiki\Api\ApiQueryFileRepoInfo\execute(), and MediaWiki\Api\ApiResult\setArrayTypeRecursive().

◆ setContentField()

static MediaWiki\Api\ApiResult::setContentField ( array & $arr,
$name,
$flags = 0 )
static

Set the name of the content field name (META_CONTENT)

Since
1.25
Parameters
array&$arr
string | int$nameName of the field
int$flagsZero or more OR-ed flags like OVERRIDE | ADD_ON_TOP.

Definition at line 533 of file ApiResult.php.

References MediaWiki\Api\ApiResult\META_CONTENT.

Referenced by MediaWiki\Api\ApiResult\addContentField(), and MediaWiki\Api\ApiResult\setContentValue().

◆ setContentValue()

◆ setErrorFormatter()

MediaWiki\Api\ApiResult::setErrorFormatter ( ApiErrorFormatter $formatter)
Since
1.25
Parameters
ApiErrorFormatter$formatter

Definition at line 172 of file ApiResult.php.

◆ setIndexedTagName()

static MediaWiki\Api\ApiResult::setIndexedTagName ( array & $arr,
$tag )
static

Set the tag name for numeric-keyed values in XML format.

Since
1.25 is static
Parameters
array&$arr
string$tagTag name

Definition at line 617 of file ApiResult.php.

References MediaWiki\Api\ApiResult\META_INDEXED_TAG_NAME.

Referenced by MediaWiki\Api\ApiResult\addIndexedTagName(), MediaWiki\Api\ApiQueryBase\addPageSubItems(), MediaWiki\Api\ApiQuerySiteinfo\appendDbReplLagInfo(), MediaWiki\Debug\MWDebug\appendDebugInfoToApiResult(), MediaWiki\Api\ApiQuerySiteinfo\appendExtensions(), MediaWiki\Api\ApiQuerySiteinfo\appendExtensionTags(), MediaWiki\Api\ApiQuerySiteinfo\appendFileExtensions(), MediaWiki\Api\ApiQuerySiteinfo\appendFunctionHooks(), MediaWiki\Api\ApiQuerySiteinfo\appendGeneralInfo(), MediaWiki\Api\ApiQuerySiteinfo\appendInstalledClientLibraries(), MediaWiki\Api\ApiQuerySiteinfo\appendInstalledLibraries(), MediaWiki\Api\ApiQuerySiteinfo\appendInterwikiMap(), MediaWiki\Api\ApiQuerySiteinfo\appendLanguages(), MediaWiki\Api\ApiQuerySiteinfo\appendLanguageVariants(), MediaWiki\Api\ApiQuerySiteinfo\appendMagicWords(), MediaWiki\Api\ApiQuerySiteinfo\appendNamespaceAliases(), MediaWiki\Api\ApiQuerySiteinfo\appendNamespaces(), MediaWiki\Api\ApiQuerySiteinfo\appendProtocols(), MediaWiki\Api\ApiQuerySiteinfo\appendRestrictions(), MediaWiki\Api\ApiQuerySiteinfo\appendSkins(), MediaWiki\Api\ApiQuerySiteinfo\appendSpecialPageAliases(), MediaWiki\Api\ApiQuerySiteinfo\appendSubscribedHooks(), MediaWiki\Api\ApiQuerySiteinfo\appendUserGroups(), MediaWiki\Api\ApiQuerySiteinfo\appendVariables(), MediaWiki\Api\ApiErrorFormatter_BackCompat\arrayFromStatus(), MediaWiki\Api\ApiEditPage\execute(), MediaWiki\Api\ApiExpandTemplates\execute(), MediaWiki\Api\ApiImageRotate\execute(), MediaWiki\Api\ApiImport\execute(), MediaWiki\Api\ApiMove\execute(), MediaWiki\Api\ApiParamInfo\execute(), MediaWiki\Api\ApiProtect\execute(), MediaWiki\Api\ApiPurge\execute(), MediaWiki\Api\ApiQueryAllUsers\execute(), MediaWiki\Api\ApiQueryDeletedrevs\execute(), MediaWiki\Api\ApiQueryFileRepoInfo\execute(), MediaWiki\Api\ApiQueryLanguageinfo\execute(), MediaWiki\Api\ApiQueryUsers\execute(), MediaWiki\Api\ApiRevisionDelete\execute(), MediaWiki\Api\ApiRsd\execute(), MediaWiki\Api\ApiSetNotificationTimestamp\execute(), MediaWiki\Api\ApiTag\execute(), MediaWiki\Api\ApiUserrights\execute(), MediaWiki\Api\ApiWatch\execute(), MediaWiki\Api\ApiQueryRevisionsBase\extractRevisionInfo(), MediaWiki\Api\ApiQueryRecentChanges\extractRowInfo(), MediaWiki\Api\ApiParamInfo\formatHelpMessages(), MediaWiki\Api\ApiRsd\formatRsdApiList(), MediaWiki\Api\ApiQueryUserInfo\getCurrentUserInfo(), MediaWiki\Api\ApiOpenSearch\populateResult(), MediaWiki\Api\ApiTag\processIndividual(), MediaWiki\Api\ApiQueryImageInfo\processMetaData(), MediaWiki\Api\ApiQueryAllDeletedRevisions\run(), and MediaWiki\Api\ApiQueryAllRevisions\run().

◆ setIndexedTagNameRecursive()

static MediaWiki\Api\ApiResult::setIndexedTagNameRecursive ( array & $arr,
$tag )
static

Set indexed tag name on $arr and all subarrays.

Since
1.25
Parameters
array&$arr
string$tagTag name

Definition at line 642 of file ApiResult.php.

References MediaWiki\Api\ApiResult\META_INDEXED_TAG_NAME, and MediaWiki\Api\ApiResult\setIndexedTagNameRecursive().

Referenced by MediaWiki\Api\ApiResult\addIndexedTagNameRecursive(), and MediaWiki\Api\ApiResult\setIndexedTagNameRecursive().

◆ setPreserveKeysList()

static MediaWiki\Api\ApiResult::setPreserveKeysList ( array & $arr,
$names )
static

Preserve specified keys.

This prevents XML name mangling and preventing keys from being removed by self::stripMetadata().

Since
1.25
Parameters
array&$arr
array | string$namesThe element name(s) to preserve

Definition at line 676 of file ApiResult.php.

References MediaWiki\Api\ApiResult\META_PRESERVE_KEYS.

Referenced by MediaWiki\Api\ApiResult\addPreserveKeysList(), and MediaWiki\Api\ApiResult\applyTransformations().

◆ setSubelementsList()

static MediaWiki\Api\ApiResult::setSubelementsList ( array & $arr,
$names )
static

Causes the elements with the specified names to be output as subelements rather than attributes.

Since
1.25 is static
Parameters
array&$arr
array | string | int$namesThe element name(s) to be output as subelements

Definition at line 566 of file ApiResult.php.

References MediaWiki\Api\ApiResult\META_SUBELEMENTS.

Referenced by MediaWiki\Api\ApiResult\addSubelementsList(), MediaWiki\Api\ApiExpandTemplates\execute(), MediaWiki\Api\ApiHelp\execute(), MediaWiki\Api\ApiRsd\execute(), MediaWiki\Api\ApiRsd\formatRsdApiList(), and MediaWiki\Api\ApiOpenSearch\populateResult().

◆ setValue()

static MediaWiki\Api\ApiResult::setValue ( array & $arr,
$name,
$value,
$flags = 0 )
static

Add an output value to the array by name.

Verifies that value with the same name has not been added before.

Since
1.25
Parameters
array&$arrTo add $value to
string | int | null$nameIndex of $arr to add $value at, or null to use the next numeric index.
mixed$value
int$flagsZero or more OR-ed flags like OVERRIDE | ADD_ON_TOP.

Definition at line 289 of file ApiResult.php.

Referenced by MediaWiki\Api\ApiResult\addValue(), and MediaWiki\Api\ApiResult\setContentValue().

◆ stripMetadata()

static MediaWiki\Api\ApiResult::stripMetadata ( $data)
static

Recursively remove metadata keys from a data array or object.

Note this removes all potential metadata keys, not just the defined ones.

Since
1.25
Parameters
array | stdClass$data
Returns
array|stdClass

Definition at line 1050 of file ApiResult.php.

References MediaWiki\Api\ApiResult\stripMetadata().

Referenced by MediaWiki\Api\ApiResult\stripMetadata().

◆ stripMetadataNonRecursive()

static MediaWiki\Api\ApiResult::stripMetadataNonRecursive ( $data,
& $metadata = null )
static

Remove metadata keys from a data array or object, non-recursive.

Note this removes all potential metadata keys, not just the defined ones.

Since
1.25
Parameters
array | stdClass$data
array | null&$metadataStore metadata here, if provided
Returns
array|stdClass

Definition at line 1084 of file ApiResult.php.

Referenced by MediaWiki\Api\ApiResult\applyTransformations().

◆ unsetPreserveKeysList()

static MediaWiki\Api\ApiResult::unsetPreserveKeysList ( array & $arr,
$names )
static

Don't preserve specified keys.

Since
1.25
See also
self::setPreserveKeysList()
Parameters
array&$arr
array | string$namesThe element name(s) to not preserve

Definition at line 703 of file ApiResult.php.

References MediaWiki\Api\ApiResult\META_PRESERVE_KEYS.

Referenced by MediaWiki\Api\ApiResult\removePreserveKeysList().

◆ unsetSubelementsList()

static MediaWiki\Api\ApiResult::unsetSubelementsList ( array & $arr,
$names )
static

Causes the elements with the specified names to be output as attributes (when possible) rather than as subelements.

Since
1.25
Parameters
array&$arr
array | string | int$namesThe element name(s) to not be output as subelements

Definition at line 593 of file ApiResult.php.

References MediaWiki\Api\ApiResult\META_SUBELEMENTS.

Referenced by MediaWiki\Api\ApiResult\removeSubelementsList().

◆ unsetValue()

static MediaWiki\Api\ApiResult::unsetValue ( array & $arr,
$name )
static

Remove an output value to the array by name.

Parameters
array&$arrTo remove $value from
string | int$nameIndex of $arr to remove
Returns
mixed Old value, or null

Definition at line 436 of file ApiResult.php.

Referenced by MediaWiki\Api\ApiResult\removeValue().

Member Data Documentation

◆ ADD_ON_TOP

const MediaWiki\Api\ApiResult::ADD_ON_TOP = 2

For addValue(), setValue() and similar functions, if the value does not exist, add it as the first element.

In case the new value has no name (numerical index), all indexes will be renumbered.

Since
1.21

Definition at line 57 of file ApiResult.php.

Referenced by MediaWiki\Api\ApiErrorFormatter_BackCompat\addWarningOrError(), MediaWiki\Api\ApiQuery\execute(), and MediaWiki\Api\ApiContinuationManager\setContinuationIntoResult().

◆ META_BC_BOOLS

const MediaWiki\Api\ApiResult::META_BC_BOOLS = '_BC_bools'

◆ META_BC_SUBELEMENTS

const MediaWiki\Api\ApiResult::META_BC_SUBELEMENTS = '_BC_subelements'

Key for the 'BC subelements' metadata item.

Value is string[]. Note no setter is provided.

Since
1.25

Definition at line 151 of file ApiResult.php.

Referenced by MediaWiki\Api\ApiExpandTemplates\execute(), MediaWiki\Api\ApiParse\execute(), and MediaWiki\Api\ApiFormatXml\recXmlPrint().

◆ META_CONTENT

const MediaWiki\Api\ApiResult::META_CONTENT = '_content'

Key for the 'content' metadata item.

Value is string.

Since
1.25

Definition at line 98 of file ApiResult.php.

Referenced by MediaWiki\Api\ApiResult\applyTransformations(), MediaWiki\Api\ApiFormatXml\recXmlPrint(), and MediaWiki\Api\ApiResult\setContentField().

◆ META_INDEXED_TAG_NAME

const MediaWiki\Api\ApiResult::META_INDEXED_TAG_NAME = '_element'

Key for the 'indexed tag name' metadata item.

Value is string.

Since
1.25

Definition at line 80 of file ApiResult.php.

Referenced by MediaWiki\Api\ApiFormatXml\recXmlPrint(), MediaWiki\Api\ApiResult\setIndexedTagName(), and MediaWiki\Api\ApiResult\setIndexedTagNameRecursive().

◆ META_KVP_KEY_NAME

const MediaWiki\Api\ApiResult::META_KVP_KEY_NAME = '_kvpkeyname'

Key for the metadata item whose value specifies the name used for the kvp key in the alternative output format with META_TYPE 'kvp' or 'BCkvp', i.e.

the "name" in <container>value</container>. Value is string.

Since
1.25

Definition at line 127 of file ApiResult.php.

Referenced by MediaWiki\Api\ApiResult\applyTransformations(), and MediaWiki\Api\ApiResult\setArrayType().

◆ META_KVP_MERGE

const MediaWiki\Api\ApiResult::META_KVP_MERGE = '_kvpmerge'

Key for the metadata item that indicates that the KVP key should be added into an assoc value, i.e.

{"key":{"val1":"a","val2":"b"}} transforms to {"name":"key","val1":"a","val2":"b"} rather than {"name":"key","value":{"val1":"a","val2":"b"}}. Value is boolean.

Since
1.26

Definition at line 137 of file ApiResult.php.

◆ META_PRESERVE_KEYS

const MediaWiki\Api\ApiResult::META_PRESERVE_KEYS = '_preservekeys'

Key for the 'preserve keys' metadata item.

Value is string[].

Since
1.25

Definition at line 92 of file ApiResult.php.

Referenced by MediaWiki\Api\ApiFormatXml\recXmlPrint(), MediaWiki\Api\ApiResult\setPreserveKeysList(), and MediaWiki\Api\ApiResult\unsetPreserveKeysList().

◆ META_SUBELEMENTS

const MediaWiki\Api\ApiResult::META_SUBELEMENTS = '_subelements'

◆ META_TYPE

const MediaWiki\Api\ApiResult::META_TYPE = '_type'

Key for the 'type' metadata item.

Value is one of the following strings:

  • default: Like 'array' if all (non-metadata) keys are numeric with no gaps, otherwise like 'assoc'.
  • array: Keys are used for ordering, but are not output. In a format like JSON, outputs as [].
  • assoc: In a format like JSON, outputs as {}.
  • kvp: For a format like XML where object keys have a restricted character set, use an alternative output format. For example, <container>value</container> rather than <container key="value" >
  • BCarray: Like 'array' normally, 'default' in backwards-compatibility mode.
  • BCassoc: Like 'assoc' normally, 'default' in backwards-compatibility mode.
  • BCkvp: Like 'kvp' normally. In backwards-compatibility mode, forces the alternative output format for all formats, for example [{"name":key,"*":value}] in JSON. META_KVP_KEY_NAME must also be set.
    Since
    1.25

Definition at line 118 of file ApiResult.php.

Referenced by MediaWiki\Api\ApiQuerySiteinfo\appendNamespaces(), MediaWiki\Api\ApiResult\applyTransformations(), MediaWiki\Api\ApiFormatXml\execute(), MediaWiki\Api\ApiQueryBlocks\execute(), MediaWiki\Api\ApiAuthManagerHelper\formatRequests(), MediaWiki\Api\ApiQueryImageInfo\getInfo(), MediaWiki\Api\ApiQueryUserInfo\getRateLimits(), MediaWiki\Api\ApiFormatXml\recXmlPrint(), and MediaWiki\Api\ApiResult\setArrayType().

◆ NO_SIZE_CHECK

const MediaWiki\Api\ApiResult::NO_SIZE_CHECK = 4

For addValue() and similar functions, do not check size while adding a value Don't use this unless you REALLY know what you're doing.

Values added while the size checking was disabled will never be counted. Ignored for setValue() and similar functions.

Since
1.24

Definition at line 66 of file ApiResult.php.

Referenced by MediaWiki\Api\ApiMain\addRequestedFields(), MediaWiki\Api\ApiErrorFormatter_BackCompat\addWarningOrError(), MediaWiki\Api\ApiComparePages\execute(), MediaWiki\Api\ApiFormatXml\execute(), MediaWiki\Api\ApiHelp\execute(), MediaWiki\Api\ApiQuery\execute(), MediaWiki\Api\ApiContinuationManager\setContinuationIntoResult(), and MediaWiki\Api\ApiMain\substituteResultWithError().

◆ NO_VALIDATE

const MediaWiki\Api\ApiResult::NO_VALIDATE = self::NO_SIZE_CHECK | 8

For addValue(), setValue() and similar functions, do not validate data.

Also disables size checking. If you think you need to use this, you're probably wrong.

Since
1.25

Definition at line 74 of file ApiResult.php.

Referenced by MediaWiki\Api\ApiResult\addValue(), and MediaWiki\Api\ApiFormatFeedWrapper\setResult().

◆ OVERRIDE

const MediaWiki\Api\ApiResult::OVERRIDE = 1

Override existing value in addValue(), setValue(), and similar functions.

Since
1.21

Definition at line 49 of file ApiResult.php.

Referenced by MediaWiki\Api\ApiErrorFormatter_BackCompat\addWarningOrError().


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