MediaWiki  REL1_22
ApiResult Class Reference

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

Inheritance diagram for ApiResult:
Collaboration diagram for ApiResult:

List of all members.

Public Member Functions

 __construct ($main)
 Constructor.
 addValue ($path, $name, $value, $flags=0)
 Add value to the output data at the given path.
 cleanUpUTF8 ()
 Ensure all values in this result are valid UTF-8.
 convertStatusToArray ($status, $errorType= 'error')
 Converts a Status object to an array suitable for addValue.
 disableSizeCheck ()
 Disable size checking in addValue().
 enableSizeCheck ()
 Re-enable size checking in addValue()
 execute ()
 Evaluates the parameters, performs the requested query, and sets up the result.
 getData ()
 Get the result's internal data array (read-only)
 getIsRawMode ()
 Returns true whether the formatter requested raw data.
 getSize ()
 Get the size of the result, i.e.
 reset ()
 Clear the current result data.
 setIndexedTagName (&$arr, $tag)
 In case the array contains indexed values (in addition to named), give all indexed values the given tag name.
 setIndexedTagName_internal ($path, $tag)
 Calls setIndexedTagName() on an array already in the result.
 setIndexedTagName_recursive (&$arr, $tag)
 Calls setIndexedTagName() on each sub-array of $arr.
 setParsedLimit ($moduleName, $limit)
 Add a parsed limit=max to the result.
 setRawMode ()
 Call this function when special elements such as '_element' are needed by the formatter, for example in XML printing.
 unsetValue ($path, $name)
 Unset a value previously added to the result set.

Static Public Member Functions

static setContent (&$arr, $value, $subElemName=null)
 Adds a content element to an array.
static setElement (&$arr, $name, $value, $flags=0)
 Add an output value to the array by name.
static size ($value)
 Get the 'real' size of a result item.

Public Attributes

 $mCheckingSize
 $mIsRawMode
 $mSize
const ADD_ON_TOP = 2
 For addValue() and setElement(), if the value does not exist, add it as the first element.
const OVERRIDE = 1
 override existing value in addValue() and setElement()

Static Private Member Functions

static cleanUp_helper (&$s)
 Callback function for cleanUpUTF8()

Private Attributes

 $mData

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.

There are two special key values that change how XML output is generated: '_element' This key sets the tag name for the rest of the elements in the current array. It is only inserted if the formatter returned true for getNeedsRawData() '*' This key has special meaning only to the XML formatter, and is outputted as is for all others. In XML it becomes the content of the current element.

Definition at line 44 of file ApiResult.php.


Constructor & Destructor Documentation

Constructor.

Parameters:
$mainApiMain object

Definition at line 65 of file ApiResult.php.

References reset().


Member Function Documentation

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. If $name is empty, the $value is added as a next list element data[] = $value.

Parameters:
$patharray|string|null
$namestring
$valuemixed
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 281 of file ApiResult.php.

References $flags, $name, $path, $value, ADD_ON_TOP, array(), as, global, setElement(), ApiBase\setWarning(), and size().

Referenced by MWDebug\appendDebugInfoToApiResult(), and setParsedLimit().

static ApiResult::cleanUp_helper ( &$  s) [static, private]

Callback function for cleanUpUTF8()

Parameters:
$sstring

Definition at line 372 of file ApiResult.php.

References $s, $wgContLang, and global.

Ensure all values in this result are valid UTF-8.

Definition at line 363 of file ApiResult.php.

References array().

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

Converts a Status object to an array suitable for addValue.

Parameters:
Status$status
string$errorType
Returns:
array

Definition at line 386 of file ApiResult.php.

References $error, $result, array(), as, and setIndexedTagName().

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)

Definition at line 136 of file ApiResult.php.

Re-enable size checking in addValue()

Definition at line 143 of file ApiResult.php.

Evaluates the parameters, performs the requested query, and sets up the result.

Concrete implementations of ApiBase must override this method to provide whatever functionality their module offers. Implementations must not produce any output on their own and are not expected to handle any errors.

The execute() method will be invoked directly by ApiMain immediately before the result of the module is output. Aside from the constructor, implementations should assume that no other methods will be called externally on the module before the result is processed.

The result data should be stored in the ApiResult object available through getResult().

Reimplemented from ApiBase.

Definition at line 400 of file ApiResult.php.

References ApiBase\dieDebug().

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

Returns:
array

Definition at line 100 of file ApiResult.php.

Returns true whether the formatter requested raw data.

Returns:
bool

Definition at line 92 of file ApiResult.php.

Referenced by setIndexedTagName().

Get the size of the result, i.e.

the amount of bytes in it

Returns:
int

Definition at line 127 of file ApiResult.php.

Clear the current result data.

Definition at line 75 of file ApiResult.php.

References array().

Referenced by __construct().

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

Adds a content element to an array.

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

Parameters:
array$arrto add the content element to
$valueMixed
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 192 of file ApiResult.php.

References $value, array(), ApiBase\dieDebug(), and setElement().

Referenced by ApiQuerySiteinfo\appendLanguages(), ApiQuerySiteinfo\appendNamespaceAliases(), ApiQuerySiteinfo\appendNamespaces(), ApiQuerySiteinfo\appendSkins(), ApiComparePages\execute(), ApiRsd\execute(), ApiExpandTemplates\execute(), ApiQueryLangLinks\execute(), ApiQueryAllMessages\execute(), ApiQueryDeletedrevs\execute(), ApiQueryExternalLinks\execute(), ApiQueryIWLinks\execute(), ApiQueryRevisions\extractRowInfo(), ApiRsd\formatRsdApiList(), ApiQueryUserInfo\getCurrentUserInfo(), ApiQueryAllCategories\run(), and ApiBase\setWarning().

static ApiResult::setElement ( &$  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.

Parameters:
array$arrto add $value to
string$nameIndex of $arr to add $value at
$valuemixed
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.
Since:
1.21 int $flags replaced boolean $override

Definition at line 159 of file ApiResult.php.

References $flags, $name, $value, ADD_ON_TOP, array(), ApiBase\dieDebug(), and OVERRIDE.

Referenced by addValue(), and setContent().

ApiResult::setIndexedTagName ( &$  arr,
tag 
)

In case the array contains indexed values (in addition to named), give all indexed values the given tag name.

This function MUST be called on every array that has numerical indexes.

Parameters:
$arrarray
string$tagTag name

Definition at line 213 of file ApiResult.php.

References ApiBase\dieDebug(), and getIsRawMode().

Referenced by MWDebug\appendDebugInfoToApiResult(), convertStatusToArray(), setIndexedTagName_internal(), and setIndexedTagName_recursive().

ApiResult::setIndexedTagName_internal ( path,
tag 
)

Calls setIndexedTagName() on an array already in the result.

Don't specify a path to a value that's not in the result, or you'll get nasty errors.

Parameters:
array$pathPath to the array, like addValue()'s $path
$tagstring

Definition at line 250 of file ApiResult.php.

References $path, array(), as, and setIndexedTagName().

ApiResult::setIndexedTagName_recursive ( &$  arr,
tag 
)

Calls setIndexedTagName() on each sub-array of $arr.

Parameters:
$arrarray
string$tagTag name

Definition at line 230 of file ApiResult.php.

References as, and setIndexedTagName().

ApiResult::setParsedLimit ( moduleName,
limit 
)

Add a parsed limit=max to the result.

Parameters:
$moduleNamestring
$limitint

Definition at line 334 of file ApiResult.php.

References $limit, addValue(), and OVERRIDE.

Call this function when special elements such as '_element' are needed by the formatter, for example in XML printing.

Definition at line 84 of file ApiResult.php.

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.

Parameters:
$valuemixed
Returns:
int

Definition at line 110 of file ApiResult.php.

References $s, $value, and as.

Referenced by addValue(), and unsetValue().

ApiResult::unsetValue ( path,
name 
)

Unset a value previously added to the result set.

Fails silently if the value isn't found. For parameters, see addValue()

Parameters:
$patharray|null
$namestring

Definition at line 346 of file ApiResult.php.

References $name, $path, array(), as, and size().


Member Data Documentation

ApiResult::$mCheckingSize

Definition at line 59 of file ApiResult.php.

ApiResult::$mData [private]

Definition at line 59 of file ApiResult.php.

ApiResult::$mIsRawMode

Definition at line 59 of file ApiResult.php.

ApiResult::$mSize

Definition at line 59 of file ApiResult.php.

For addValue() and setElement(), 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 addValue(), ApiQueryBase\setContinueEnumParameter(), setElement(), and ApiBase\setWarning().

override existing value in addValue() and setElement()

Since:
1.21

Definition at line 50 of file ApiResult.php.

Referenced by setElement(), setParsedLimit(), and ApiBase\setWarning().


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