ApiResult Class Reference
[API]

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

Inherits ApiBase.

List of all members.

Public Member Functions

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

Static Public Member Functions

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

Static Private Member Functions

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

Private Attributes

 $mData
 $mIsRawMode
 $mSize
 $mCheckingSize


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


Constructor & Destructor Documentation

ApiResult::__construct ( main  ) 

Constructor.

Parameters:
$main ApiMain object

Definition at line 56 of file ApiResult.php.

References reset().


Member Function Documentation

ApiResult::addValue ( path,
name,
value 
)

Add value to the output data at the given path.

Path is an indexed array, each element specifing 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 $name is empty, the $value is added as a next list element data[] = $value

Returns:
bool True if $value fits in the result, false if not

Definition at line 242 of file ApiResult.php.

References $name, $path, $wgAPIMaxResultSize, setElement(), and size().

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

Callback function for cleanUpUTF8().

Definition at line 303 of file ApiResult.php.

References $s, and UtfNormal::cleanUp().

ApiResult::cleanUpUTF8 (  ) 

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

Definition at line 295 of file ApiResult.php.

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)

Definition at line 125 of file ApiResult.php.

ApiResult::enableSizeCheck (  ) 

Re-enable size checking in addValue().

Definition at line 132 of file ApiResult.php.

ApiResult::execute (  ) 

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

References ApiBase::dieDebug().

ApiResult::getData (  ) 

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

Returns:
array

Definition at line 91 of file ApiResult.php.

ApiResult::getIsRawMode (  ) 

Returns true whether the formatter requested raw data.

Returns:
bool

Definition at line 83 of file ApiResult.php.

Referenced by setIndexedTagName().

ApiResult::getSize (  ) 

Get the size of the result, i.e.

the amount of bytes in it

Returns:
int

Definition at line 116 of file ApiResult.php.

ApiResult::getVersion (  ) 

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

ApiResult::reset (  ) 

Clear the current result data.

Definition at line 66 of file ApiResult.php.

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:
$arr array to add the content element to
$subElemName string 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 168 of file ApiResult.php.

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

Referenced by ApiQuerySiteinfo::appendNamespaceAliases(), ApiQuerySiteinfo::appendNamespaces(), ApiQueryLangLinks::execute(), ApiQueryExternalLinks::execute(), ApiQueryDeletedrevs::execute(), ApiQueryRevisions::extractRowInfo(), ApiQuery::outputGeneralPageInfo(), ApiBase::setWarning(), and ApiMain::substituteResultWithError().

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

Add an output value to the array by name.

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

Parameters:
$arr array to add $value to
$name string Index of $arr to add $value at
$value mixed

Definition at line 143 of file ApiResult.php.

References $name, and ApiBase::dieDebug().

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 arrray that has numerical indexes.

Parameters:
$arr array
$tag string Tag name

Definition at line 187 of file ApiResult.php.

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

Referenced by 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:
$path array Path to the array, like addValue()'s $path
$tag string

Definition at line 222 of file ApiResult.php.

References $path, and setIndexedTagName().

ApiResult::setIndexedTagName_recursive ( &$  arr,
tag 
)

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

Parameters:
$arr array
$tag string Tag name

Definition at line 202 of file ApiResult.php.

References setIndexedTagName().

ApiResult::setRawMode (  ) 

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

Definition at line 75 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:
$value mixed
Returns:
int

Definition at line 101 of file ApiResult.php.

References $s.

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:
$path array
$name string

Definition at line 280 of file ApiResult.php.

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


Member Data Documentation

ApiResult::$mCheckingSize [private]

Definition at line 50 of file ApiResult.php.

ApiResult::$mData [private]

Definition at line 50 of file ApiResult.php.

ApiResult::$mIsRawMode [private]

Definition at line 50 of file ApiResult.php.

ApiResult::$mSize [private]

Definition at line 50 of file ApiResult.php.


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

Generated on Sat Sep 5 02:08:32 2009 for MediaWiki by  doxygen 1.5.9