MediaWiki
REL1_19
|
This class represents the result of the API operations. More...
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 |
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.
ApiResult::__construct | ( | $ | main | ) |
Constructor.
$main | ApiMain object |
Definition at line 52 of file ApiResult.php.
References reset().
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.
$path | array|string|null |
$name | string |
$value | mixed |
$overwrite | bool |
Definition at line 256 of file ApiResult.php.
References $path, $wgAPIMaxResultSize, setElement(), ApiBase\setWarning(), and size().
Referenced by setParsedLimit().
static ApiResult::cleanUp_helper | ( | &$ | s | ) | [static, private] |
Callback function for cleanUpUTF8()
$s | string |
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.
Status | $status | |
string | $errorType |
Definition at line 353 of file ApiResult.php.
References $result, 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 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().
Get the result's internal data array (read-only)
Definition at line 87 of file ApiResult.php.
Returns true whether the formatter requested raw data.
Definition at line 79 of file ApiResult.php.
Referenced by setIndexedTagName().
Get the size of the result, i.e.
the amount of bytes in it
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
Reimplemented from ApiBase.
Definition at line 371 of file ApiResult.php.
ApiResult::reset | ( | ) |
Clear the current result data.
Definition at line 62 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.
$arr | array to add the content element to |
$value | Mixed |
$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 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().
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.
$arr | array to add $value to |
$name | string Index of $arr to add $value at |
$value | mixed |
$overwrite | bool Whether overwriting an existing element is allowed |
Definition at line 142 of file ApiResult.php.
References 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 array that has numerical indexes.
$arr | array |
$tag | string Tag name |
Definition at line 191 of file ApiResult.php.
References ApiBase\dieDebug(), and getIsRawMode().
Referenced by 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.
$path | array Path to the array, like addValue()'s $path |
$tag | string |
Definition at line 228 of file ApiResult.php.
References $path, and setIndexedTagName().
ApiResult::setIndexedTagName_recursive | ( | &$ | arr, |
$ | tag | ||
) |
Calls setIndexedTagName() on each sub-array of $arr.
$arr | array |
$tag | string Tag name |
Definition at line 208 of file ApiResult.php.
References setIndexedTagName().
ApiResult::setParsedLimit | ( | $ | moduleName, |
$ | limit | ||
) |
Add a parsed limit=max to the result.
$moduleName | string |
$limit | int |
Definition at line 301 of file ApiResult.php.
References $limit, and addValue().
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.
$value | mixed |
Definition at line 97 of file ApiResult.php.
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()
$path | array |
$name | string |
Definition at line 313 of file ApiResult.php.
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.