MediaWiki  1.27.2
ApiResult Class Reference

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

Inheritance diagram for ApiResult:
Collaboration diagram for ApiResult:

Public Member Functions

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

Public Attributes

 $mainForContinuation
 
 $maxSize
 
 $size
 
const ADD_ON_TOP = 2
 For addValue(), setValue() and similar functions, if the value does not exist, add it as the first element. More...
 
const META_BC_BOOLS = '_BC_bools'
 Key for the 'BC bools' metadata item. More...
 
const META_BC_SUBELEMENTS = '_BC_subelements'
 Key for the 'BC subelements' metadata item. More...
 
const META_CONTENT = '_content'
 Key for the 'content' metadata item. More...
 
const META_INDEXED_TAG_NAME = '_element'
 Key for the 'indexed tag name' metadata item. More...
 
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. More...
 
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. More...
 
const META_PRESERVE_KEYS = '_preservekeys'
 Key for the 'preserve keys' metadata item. More...
 
const META_SUBELEMENTS = '_subelements'
 Key for the 'subelements' metadata item. More...
 
const META_TYPE = '_type'
 Key for the 'type' metadata item. More...
 
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. More...
 
const NO_VALIDATE = 12
 For addValue(), setValue() and similar functions, do not validate data. More...
 
const OVERRIDE = 1
 Override existing value in addValue(), setValue(), and similar functions. More...
 

Private Attributes

 $checkingSize
 
 $data
 
 $errorFormatter
 

Content

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

Metadata

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

Utility

static isMetadataKey ($key)
 Test whether a key should be considered metadata. More...
 
static stripMetadata ($data)
 Recursively remove metadata keys from a data array or object. More...
 
static stripMetadataNonRecursive ($data, &$metadata=null)
 Remove metadata keys from a data array or object, non-recursive. More...
 
static addMetadataToResultVars ($vars, $forceHash=true)
 Add the correct metadata to an array of vars we want to export through the API. More...
 
static valueSize ($value)
 Get the 'real' size of a result item. More...
 
static applyTransformations (array $dataIn, array $transforms)
 Apply transformations to an array, returning the transformed array. More...
 
path ($path, $create= 'append')
 Return a reference to the internal data at $path. More...
 

Deprecated

 setRawMode ($flag=true)
 Formerly used to enable/disable "raw mode". More...
 
 getIsRawMode ()
 Returns true, the equivalent of "raw mode" is always enabled now. More...
 
 getData ()
 Get the result's internal data array (read-only) More...
 
 disableSizeCheck ()
 Disable size checking in addValue(). More...
 
 enableSizeCheck ()
 Re-enable size checking in addValue() More...
 
 setIndexedTagName_recursive (&$arr, $tag)
 Set indexed tag name on all subarrays of $arr. More...
 
 setIndexedTagName_internal ($path, $tag)
 Alias for self::addIndexedTagName() More...
 
 setParsedLimit ($moduleName, $limit)
 Alias for self::addParsedLimit() More...
 
 setMainForContinuation (ApiMain $main)
 Set the ApiMain for use by $this->beginContinuation() More...
 
 beginContinuation ($continue, array $allModules=[], array $generatedModules=[])
 Parse a 'continue' parameter and return status information. More...
 
 setContinueParam (ApiBase $module, $paramName, $paramValue)
 
 setGeneratorContinueParam (ApiBase $module, $paramName, $paramValue)
 
 endContinuation ($style= 'standard')
 Close continuation, writing the data into the result. More...
 
 cleanUpUTF8 ()
 No-op, this is now checked on insert. More...
 
 convertStatusToArray ($status, $errorType= 'error')
 Converts a Status object to an array suitable for addValue. More...
 
static setElement (&$arr, $name, $value, $flags=0)
 Alias for self::setValue() More...
 
static setContent (&$arr, $value, $subElemName=null)
 Adds a content element to an array. More...
 
static size ($value)
 Get the 'real' size of a result item. More...
 

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 33 of file ApiResult.php.

Constructor & Destructor Documentation

ApiResult::__construct (   $maxSize)
Parameters
int | bool$maxSizeMaximum result "size", or false for no limit
Since
1.25 Takes an integer|bool rather than an ApiMain

Definition at line 153 of file ApiResult.php.

References $maxSize, reset(), and wfDeprecated().

Member Function Documentation

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$kvpKeyNameSee ApiResult::META_KVP_KEY_NAME

Definition at line 749 of file ApiResult.php.

References $path, $tag, and path().

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$kvpKeyNameSee ApiResult::META_KVP_KEY_NAME

Definition at line 777 of file ApiResult.php.

References $path, $tag, and path().

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 555 of file ApiResult.php.

References $flags, $name, $path, ADD_ON_TOP, and path().

Referenced by addContentValue().

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 $flags, $name, $path, $value, addContentField(), and addValue().

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 631 of file ApiResult.php.

References $path, $tag, and path().

Referenced by setIndexedTagName_internal().

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 662 of file ApiResult.php.

References $path, $tag, and path().

static 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 1156 of file ApiResult.php.

References $keys, $vars, array(), as, META_BC_BOOLS, META_INDEXED_TAG_NAME, META_KVP_KEY_NAME, META_PRESERVE_KEYS, and META_TYPE.

Referenced by ApiExpandTemplates\execute(), ApiParse\execute(), and ApiResultTest\testAddMetadataToResultVars().

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 $limit, addValue(), NO_SIZE_CHECK, and OVERRIDE.

Referenced by setParsedLimit().

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 692 of file ApiResult.php.

References $path, and path().

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 582 of file ApiResult.php.

References $path, and path().

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 array('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 405 of file ApiResult.php.

References $flags, $name, $path, $value, ADD_ON_TOP, NO_SIZE_CHECK, NO_VALIDATE, path(), and size().

Referenced by addContentValue(), addParsedLimit(), MWDebug\appendDebugInfoToApiResult(), endContinuation(), and ApiContinuationManager\setContinuationIntoResult().

static 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|object

Definition at line 808 of file ApiResult.php.

References $data, $key, $keys, $ret, $type, array(), as, and object.

ApiResult::beginContinuation (   $continue,
array  $allModules = [],
array  $generatedModules = [] 
)

Parse a 'continue' parameter and return status information.

This must be balanced by a call to endContinuation().

Since
1.24
Deprecated:
since 1.25, use ApiContinuationManager instead
Parameters
string | null$continue
ApiBase[]$allModules
array$generatedModules
Returns
array

Definition at line 1376 of file ApiResult.php.

References wfDeprecated().

ApiResult::cleanUpUTF8 ( )

No-op, this is now checked on insert.

Deprecated:
since 1.25

Definition at line 1478 of file ApiResult.php.

References wfDeprecated().

ApiResult::convertStatusToArray (   $status,
  $errorType = 'error' 
)

Converts a Status object to an array suitable for addValue.

Deprecated:
since 1.25, use ApiErrorFormatter::arrayFromStatus()
Parameters
Status$status
string$errorType
Returns
array

Definition at line 1503 of file ApiResult.php.

References $status, and wfDeprecated().

ApiResult::disableSizeCheck ( )

Disable size checking in addValue().

Don't use this unless you REALLY know what you're doing. Values added while size checking was disabled will not be counted (ever)

Deprecated:
since 1.24, use ApiResult::NO_SIZE_CHECK

Definition at line 1250 of file ApiResult.php.

References wfDeprecated().

ApiResult::enableSizeCheck ( )

Re-enable size checking in addValue()

Deprecated:
since 1.24, use ApiResult::NO_SIZE_CHECK

Definition at line 1259 of file ApiResult.php.

References wfDeprecated().

ApiResult::endContinuation (   $style = 'standard')

Close continuation, writing the data into the result.

Since
1.24
Deprecated:
since 1.25, use ApiContinuationManager instead
Parameters
string$style'standard' for the new style since 1.21, 'raw' for the style used in 1.20 and earlier.

Definition at line 1458 of file ApiResult.php.

References $data, addValue(), and wfDeprecated().

ApiResult::getData ( )

Get the result's internal data array (read-only)

Deprecated:
since 1.25, use $this->getResultData() instead
Returns
array

Definition at line 1235 of file ApiResult.php.

References getResultData(), and wfDeprecated().

ApiResult::getIsRawMode ( )

Returns true, the equivalent of "raw mode" is always enabled now.

Deprecated:
since 1.25, you shouldn't have been using it in the first place
Returns
bool

Definition at line 1225 of file ApiResult.php.

References wfDeprecated().

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 array( '*' => $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 = array(); foreach ( $input as $key => $value ) { $pair = array(); $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 $last, $path, $ret, array(), data, and path().

Referenced by ApiErrorFormatter\arrayFromStatus(), and getData().

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.

References $size.

static ApiResult::isMetadataKey (   $key)
static

Test whether a key should be considered metadata.

Parameters
string$key
Returns
bool

Definition at line 795 of file ApiResult.php.

References $key.

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

& ApiResult::path (   $path,
  $create = 'append' 
)
private

Return a reference to the internal data at $path.

Parameters
array | string | null$path
string$createIf 'append', append empty arrays. If 'prepend', prepend empty arrays. If 'dummy', return a dummy array. Else, raise an error.
Returns
array

Definition at line 1119 of file ApiResult.php.

References $data, $path, $ret, array(), and as.

Referenced by addArrayType(), addArrayTypeRecursive(), addContentField(), addIndexedTagName(), addIndexedTagNameRecursive(), addPreserveKeysList(), addSubelementsList(), addValue(), getResultData(), removePreserveKeysList(), removeSubelementsList(), and removeValue().

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 717 of file ApiResult.php.

References $path, and path().

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 607 of file ApiResult.php.

References $path, and path().

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 $flags, $name, $path, $ret, array(), NO_SIZE_CHECK, path(), and size().

ApiResult::reset ( )

Clear the current result data.

Definition at line 192 of file ApiResult.php.

References data, and size().

Referenced by __construct().

ApiResult::serializeForApiResult ( )

Allow for adding one ApiResult into another.

Since
1.25
Returns
mixed

Implements ApiSerializable.

Definition at line 180 of file ApiResult.php.

References $data.

static 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$kvpKeyNameSee ApiResult::META_KVP_KEY_NAME

Definition at line 761 of file ApiResult.php.

References $type, and as.

Referenced by ApiQueryFileRepoInfo\execute(), and ApiResultTest\testMetadata().

static ApiResult::setContent ( $arr,
  $value,
  $subElemName = null 
)
static

Adds a content element to an array.

Use this function instead of hardcoding the '*' element.

Deprecated:
since 1.25, use self::setContentValue() instead
Parameters
array$arrTo add the content element to
mixed$value
string$subElemNameWhen present, content element is created as a sub item of $arr. Use this parameter to create elements in format "<elem>text</elem>" without attributes.

Definition at line 1292 of file ApiResult.php.

References $value, and wfDeprecated().

Referenced by ApiResultTest\testDeprecatedFunctions().

static 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 534 of file ApiResult.php.

References $flags, and $name.

ApiResult::setContinueParam ( ApiBase  $module,
  $paramName,
  $paramValue 
)
Since
1.24
Deprecated:
since 1.25, use ApiContinuationManager instead
Parameters
ApiBase$module
string$paramName
string | array$paramValue

Definition at line 1426 of file ApiResult.php.

References wfDeprecated().

static ApiResult::setElement ( $arr,
  $name,
  $value,
  $flags = 0 
)
static

Alias for self::setValue()

Since
1.21 int $flags replaced boolean $override
Deprecated:
since 1.25, use self::setValue() instead
Parameters
array$arrTo add $value to
string$nameIndex of $arr to add $value at
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.

Definition at line 1277 of file ApiResult.php.

References $flags, $name, $value, and wfDeprecated().

ApiResult::setErrorFormatter ( ApiErrorFormatter  $formatter)

Set the error formatter.

Since
1.25
Parameters
ApiErrorFormatter$formatter

Definition at line 171 of file ApiResult.php.

ApiResult::setGeneratorContinueParam ( ApiBase  $module,
  $paramName,
  $paramValue 
)
Since
1.24
Deprecated:
since 1.25, use ApiContinuationManager instead
Parameters
ApiBase$module
string$paramName
string | array$paramValue

Definition at line 1442 of file ApiResult.php.

References wfDeprecated().

static 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 618 of file ApiResult.php.

References $tag.

Referenced by ApiQueryBase\addPageSubItems(), ApiErrorFormatter\addWarningOrError(), ApiQuerySiteinfo\appendDbReplLagInfo(), MWDebug\appendDebugInfoToApiResult(), ApiQuerySiteinfo\appendExtensions(), ApiQuerySiteinfo\appendExtensionTags(), ApiQuerySiteinfo\appendFileExtensions(), ApiQuerySiteinfo\appendFunctionHooks(), ApiQuerySiteinfo\appendGeneralInfo(), ApiQuerySiteinfo\appendInstalledLibraries(), ApiQuerySiteinfo\appendInterwikiMap(), ApiQuerySiteinfo\appendLanguages(), ApiQuerySiteinfo\appendMagicWords(), ApiQuerySiteinfo\appendNamespaceAliases(), ApiQuerySiteinfo\appendNamespaces(), ApiQuerySiteinfo\appendProtocols(), ApiQuerySiteinfo\appendRestrictions(), ApiQuerySiteinfo\appendSkins(), ApiQuerySiteinfo\appendSpecialPageAliases(), ApiQuerySiteinfo\appendSubscribedHooks(), ApiQuerySiteinfo\appendUserGroups(), ApiQuerySiteinfo\appendVariables(), ApiErrorFormatter_BackCompat\arrayFromStatus(), ApiUpload\checkVerification(), ApiTag\execute(), ApiProtect\execute(), ApiMove\execute(), ApiImport\execute(), ApiRevisionDelete\execute(), ApiRsd\execute(), ApiWatch\execute(), ApiExpandTemplates\execute(), ApiSetNotificationTimestamp\execute(), ApiEditPage\execute(), ApiPurge\execute(), ApiQueryDeletedrevs\execute(), ApiParamInfo\execute(), ApiQueryFileRepoInfo\execute(), ApiQueryAllUsers\execute(), ApiUserrights\execute(), ApiImageRotate\execute(), ApiResetPassword\execute(), ApiQueryUsers\execute(), ApiQueryInfo\extractPageInfo(), ApiQueryRevisionsBase\extractRevisionInfo(), ApiQueryLogEvents\extractRowInfo(), ApiQueryContributions\extractRowInfo(), ApiQueryRecentChanges\extractRowInfo(), ApiRevisionDelete\extractStatusInfo(), ApiParamInfo\formatHelpMessages(), RightsLogFormatter\formatParametersForApi(), BlockLogFormatter\formatParametersForApi(), DeleteLogFormatter\formatParametersForApi(), LogFormatter\formatParametersForApi(), ApiRsd\formatRsdApiList(), ApiRevisionDelete\formatStatusMessages(), ApiPageSet\getConvertedTitlesAsResult(), ApiQueryUserInfo\getCurrentUserInfo(), ApiPageSet\getInterwikiTitlesAsResult(), ApiPageSet\getMissingRevisionIDsAsResult(), ApiParamInfo\getModuleInfo(), ApiPageSet\getNormalizedTitlesAsResult(), ApiPageSet\getRedirectTitlesAsResult(), ApiQuery\outputGeneralPageInfo(), ApiUpload\performUpload(), ApiOpenSearch\populateResult(), ApiTag\processIndividual(), ApiQueryImageInfo\processMetaData(), ApiQueryAllRevisions\run(), ApiQueryAllDeletedRevisions\run(), ApiQueryBacklinks\run(), ApiParse\setIndexedTagNames(), LogFormatterTest\testApiParamFormatting(), ApiResultTest\testMetadata(), and ApiUpload\transformWarnings().

ApiResult::setIndexedTagName_internal (   $path,
  $tag 
)

Alias for self::addIndexedTagName()

Deprecated:
since 1.25, use $this->addIndexedTagName() instead
Parameters
array$pathPath to the array, like addValue()'s $path
string$tag

Definition at line 1338 of file ApiResult.php.

References $path, $tag, addIndexedTagName(), and wfDeprecated().

ApiResult::setIndexedTagName_recursive ( $arr,
  $tag 
)

Set indexed tag name on all subarrays of $arr.

Does not set the tag name for $arr itself.

Deprecated:
since 1.25, use self::setIndexedTagNameRecursive() instead
Parameters
array$arr
string$tagTag name

Definition at line 1316 of file ApiResult.php.

References $tag, as, and wfDeprecated().

static 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 643 of file ApiResult.php.

References $tag, and as.

Referenced by ApiParse\formatLimitReportData(), and ApiResultTest\testMetadata().

ApiResult::setMainForContinuation ( ApiMain  $main)

Set the ApiMain for use by $this->beginContinuation()

Since
1.25
Deprecated:
for backwards compatibility only, do not use
Parameters
ApiMain$main

Definition at line 1360 of file ApiResult.php.

ApiResult::setParsedLimit (   $moduleName,
  $limit 
)

Alias for self::addParsedLimit()

Deprecated:
since 1.25, use $this->addParsedLimit() instead
Parameters
string$moduleName
int$limit

Definition at line 1349 of file ApiResult.php.

References $limit, addParsedLimit(), and wfDeprecated().

static 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 677 of file ApiResult.php.

References array().

Referenced by FormatMetadata\sanitizeArrayForAPI(), and ApiResultTest\testMetadata().

ApiResult::setRawMode (   $flag = true)

Formerly used to enable/disable "raw mode".

Deprecated:
since 1.25, you shouldn't have been using it in the first place
Since
1.23 $flag parameter added
Parameters
bool$flagSet the raw mode flag to this state

Definition at line 1216 of file ApiResult.php.

References wfDeprecated().

static 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 567 of file ApiResult.php.

References array().

Referenced by ApiRsd\execute(), ApiExpandTemplates\execute(), ApiHelp\execute(), ApiRsd\formatRsdApiList(), ApiParamInfo\getModuleInfo(), ApiOpenSearch\populateResult(), and ApiResultTest\testMetadata().

static 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.

References $flags, $keys, $name, $value, ADD_ON_TOP, NO_VALIDATE, and OVERRIDE.

Referenced by ApiResultTest\testObjectSerialization(), and ApiResultTest\testStaticDataMethods().

static ApiResult::size (   $value)
static

Get the 'real' size of a result item.

This means the strlen() of the item, or the sum of the strlen()s of the elements if the item is an array.

Deprecated:
since 1.25, no external users known and there doesn't seem to be any case for such use over just checking the return value from the add/set methods.
Parameters
mixed$value
Returns
int

Definition at line 1491 of file ApiResult.php.

References $value, and wfDeprecated().

Referenced by addValue(), removeValue(), and reset().

static 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 | object$data
Returns
array|object

Definition at line 1026 of file ApiResult.php.

References $data, array(), as, and object.

Referenced by ApiResultTest\testUtilityFunctions().

static 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 | object$data
array&$metadataStore metadata here, if provided
Returns
array|object

Definition at line 1060 of file ApiResult.php.

References $data, array(), as, and object.

Referenced by ApiQuery\outputGeneralPageInfo(), and ApiResultTest\testUtilityFunctions().

static 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 704 of file ApiResult.php.

References array().

Referenced by ApiResultTest\testMetadata().

static 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 594 of file ApiResult.php.

References array().

Referenced by ApiResultTest\testMetadata().

static 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.

References $name, and $ret.

Referenced by ApiResultTest\testStaticDataMethods().

static ApiResult::validateValue (   $value)
staticprivate

Validate a value for addition to the result.

Parameters
mixed$value
Returns
array|mixed|string

Definition at line 332 of file ApiResult.php.

References $type, $value, $wgContLang, array(), as, global, and string.

static ApiResult::valueSize (   $value)
staticprivate

Get the 'real' size of a result item.

This means the strlen() of the item, or the sum of the strlen()s of the elements if the item is an array.

Note
Once the deprecated public self::size is removed, we can rename this back to a less awkward name.
Parameters
mixed$valueValidated value (see self::validateValue())
Returns
int

Definition at line 1093 of file ApiResult.php.

References $s, $value, and as.

Member Data Documentation

ApiResult::$checkingSize
private

Definition at line 147 of file ApiResult.php.

ApiResult::$data
private
ApiResult::$errorFormatter
private

Definition at line 144 of file ApiResult.php.

ApiResult::$mainForContinuation

Definition at line 147 of file ApiResult.php.

ApiResult::$maxSize

Definition at line 143 of file ApiResult.php.

Referenced by __construct().

ApiResult::$size

Definition at line 143 of file ApiResult.php.

Referenced by getSize().

const 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 47 of file ApiResult.php.

Referenced by addContentField(), addValue(), ApiErrorFormatter\addWarningOrError(), ApiErrorFormatter_BackCompat\addWarningOrError(), ApiQuery\execute(), ApiContinuationManager\setContinuationIntoResult(), setValue(), ApiResultTest\testInstanceDataMethods(), and ApiResultTest\testStaticDataMethods().

const ApiResult::META_BC_SUBELEMENTS = '_BC_subelements'
const 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 117 of file ApiResult.php.

Referenced by addMetadataToResultVars(), ApiFormatNoneTest\provideGeneralEncoding(), ApiFormatJsonTest\provideGeneralEncoding(), ApiFormatPhpTest\provideGeneralEncoding(), ApiFormatXmlTest\provideGeneralEncoding(), ApiResultTest\provideTransformations(), ApiResultTest\testAddMetadataToResultVars(), and ApiResultTest\testMetadata().

const 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 127 of file ApiResult.php.

Referenced by ApiResultTest\provideTransformations().

const ApiResult::META_PRESERVE_KEYS = '_preservekeys'
const ApiResult::META_SUBELEMENTS = '_subelements'
const 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 108 of file ApiResult.php.

Referenced by addMetadataToResultVars(), ApiQuerySiteinfo\appendNamespaces(), ApiResultTest\customTransform(), ApiTokens\execute(), ApiQueryTokens\execute(), ApiQueryBlocks\execute(), ApiFormatXml\execute(), ApiQueryLogEvents\extractRowInfo(), ApiAuthManagerHelper\formatRequests(), ApiQueryImageInfo\getInfo(), ApiQueryUserInfo\getRateLimits(), LogFormatterTest\provideApiParamFormatting(), ApiFormatNoneTest\provideGeneralEncoding(), ApiFormatJsonTest\provideGeneralEncoding(), ApiFormatPhpTest\provideGeneralEncoding(), ApiFormatXmlTest\provideGeneralEncoding(), ApiResultTest\provideTransformations(), ApiFormatXml\recXmlPrint(), ApiQueryExtLinksUsage\run(), ApiQueryPagesWithProp\run(), ApiQueryCategoryMembers\run(), ApiQueryAllLinks\run(), ApiResultTest\testAddMetadataToResultVars(), ApiErrorFormatterTest\testErrorFormatter(), ApiErrorFormatterTest\testErrorFormatterBC(), ApiResultTest\testInstanceDataMethods(), ApiResultTest\testMetadata(), ApiResultTest\testObjectSerialization(), ApiResultTest\testStaticDataMethods(), and ApiResultTest\testUtilityFunctions().

const 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 56 of file ApiResult.php.

Referenced by addParsedLimit(), addValue(), ApiErrorFormatter\addWarningOrError(), ApiErrorFormatter_BackCompat\addWarningOrError(), ApiQuery\doExport(), ApiHelp\execute(), ApiFormatXml\execute(), ApiQuery\execute(), removeValue(), ApiContinuationManager\setContinuationIntoResult(), ApiMain\setupExecuteAction(), ApiMain\substituteResultWithError(), ApiResultTest\testInstanceDataMethods(), and ApiResultTest\testStaticDataMethods().

const ApiResult::NO_VALIDATE = 12

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 64 of file ApiResult.php.

Referenced by addValue(), ApiFormatFeedWrapper\setResult(), setValue(), ApiResultTest\testInstanceDataMethods(), and ApiResultTest\testStaticDataMethods().

const ApiResult::OVERRIDE = 1

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