MediaWiki  REL1_19
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, $overwrite=false)
 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.
 getVersion ()
 Returns a string that identifies the version of the extending class.
 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, $overwrite=false)
 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

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

References reset().

Here is the call graph for this function:


Member Function Documentation

ApiResult::addValue ( path,
name,
value,
overwrite = false 
)

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
$overwritebool
Returns:
bool True if $value fits in the result, false if not

Definition at line 256 of file ApiResult.php.

References $path, $wgAPIMaxResultSize, setElement(), ApiBase\setWarning(), and size().

Referenced by setParsedLimit().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Callback function for cleanUpUTF8()

Parameters:
$sstring

Definition at line 339 of file ApiResult.php.

References $wgContLang.

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

Definition at line 330 of file ApiResult.php.

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

References $result, and setIndexedTagName().

Here is the call graph for this function:

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

Re-enable size checking in addValue()

Definition at line 130 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 367 of file ApiResult.php.

References ApiBase\dieDebug().

Here is the call graph for this function:

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

Returns:
array

Definition at line 87 of file ApiResult.php.

Returns true whether the formatter requested raw data.

Returns:
bool

Definition at line 79 of file ApiResult.php.

Referenced by setIndexedTagName().

Here is the caller graph for this function:

Get the size of the result, i.e.

the amount of bytes in it

Returns:
int

Definition at line 114 of file ApiResult.php.

Returns a string that identifies the version of the extending class.

Typically includes the class name, the svn revision, timestamp, and last author. Usually done with SVN's Id keyword

Returns:
string

Reimplemented from ApiBase.

Definition at line 371 of file ApiResult.php.

Clear the current result data.

Definition at line 62 of file ApiResult.php.

Referenced by __construct().

Here is the caller graph for this function:

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

Adds a content element to an array.

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

Parameters:
$arrarray to add the content element to
$valueMixed
$subElemNamestring when 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 170 of file ApiResult.php.

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

Referenced by ApiQuerySiteinfo\appendLanguages(), ApiQuerySiteinfo\appendNamespaceAliases(), ApiQuerySiteinfo\appendNamespaces(), ApiQuerySiteinfo\appendSkins(), ApiQuery\doExport(), ApiComparePages\execute(), ApiQueryLangLinks\execute(), ApiRsd\execute(), ApiQueryAllmessages\execute(), ApiQueryDeletedrevs\execute(), ApiQueryExternalLinks\execute(), ApiQueryIWLinks\execute(), ApiQueryRevisions\extractRowInfo(), ApiRsd\formatRsdApiList(), ApiQueryUserInfo\getCurrentUserInfo(), ApiBase\setWarning(), and ApiMain\substituteResultWithError().

Here is the call graph for this function:

Here is the caller graph for this function:

static ApiResult::setElement ( &$  arr,
name,
value,
overwrite = false 
) [static]

Add an output value to the array by name.

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

Parameters:
$arrarray to add $value to
$namestring Index of $arr to add $value at
$valuemixed
$overwritebool Whether overwriting an existing element is allowed

Definition at line 142 of file ApiResult.php.

References ApiBase\dieDebug().

Referenced by addValue(), and setContent().

Here is the call graph for this function:

Here is the caller graph for this function:

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
$tagstring Tag name

Definition at line 191 of file ApiResult.php.

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

Referenced by convertStatusToArray(), setIndexedTagName_internal(), and setIndexedTagName_recursive().

Here is the call graph for this function:

Here is the caller graph for this function:

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:
$patharray Path to the array, like addValue()'s $path
$tagstring

Definition at line 228 of file ApiResult.php.

References $path, and setIndexedTagName().

Here is the call graph for this function:

ApiResult::setIndexedTagName_recursive ( &$  arr,
tag 
)

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

Parameters:
$arrarray
$tagstring Tag name

Definition at line 208 of file ApiResult.php.

References setIndexedTagName().

Here is the call graph for this function:

ApiResult::setParsedLimit ( moduleName,
limit 
)

Add a parsed limit=max to the result.

Parameters:
$moduleNamestring
$limitint

Definition at line 301 of file ApiResult.php.

References $limit, and addValue().

Here is the call graph for this function:

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

Definition at line 71 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 97 of file ApiResult.php.

Referenced by addValue(), and unsetValue().

Here is the caller graph for this function:

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
$namestring

Definition at line 313 of file ApiResult.php.

References $path, and size().

Here is the call graph for this function:


Member Data Documentation

ApiResult::$mCheckingSize

Definition at line 46 of file ApiResult.php.

ApiResult::$mData [private]

Definition at line 46 of file ApiResult.php.

ApiResult::$mIsRawMode

Definition at line 46 of file ApiResult.php.

ApiResult::$mSize

Definition at line 46 of file ApiResult.php.


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