Manual:ApiBase.php
This page is outdated. |
| MediaWiki file: ApiBase.php | |
|---|---|
| Location: | includes/api/ (includes/Api/ in 1.46 or later) |
| Source code: | master • 1.45.1 • 1.44.3 • 1.43.6 |
| Classes: | MediaWiki\Api\ApiBase |
The ApiBase class implements many basic API functions, and is the base of all API classes.
The class functions are divided into several areas of functionality:
- Module parameters: Derived classes can define
getAllowedParams()to specify which parameters to expect, how to parse and validate them. - Profiling: various methods to allow keeping tabs on various tasks and their time costs
- Self-documentation: code to allow the API to document its own state
Functions
[edit]getAllowedParams()
[edit]Specify which parameters are allowed and what requirements are to be imposed on them.
See the documentation at the top of includes/api/ApiBase.php for the constants PARAM_DFLT, PARAM_ISMULTI, PARAM_TYPE, PARAM_MAX, PARAM_MAX2, PARAM_MIN, PARAM_ALLOW_DUPLICATES, PARAM_DEPRECATED, PARAM_REQUIRED, PARAM_RANGE_ENFORCE.
The possible types of parameters are NULL, string, integer, limit, boolean, timestamp, user, or upload.
A "user" parameter is a username that is validated using Title::makeTitleSafe().
For boolean parameters, a default value of anything other than false is not allowed.
Example:
// Title parameter.
public function getAllowedParams() {
return array(
'title' => array (
ParamValidator::PARAM_TYPE => 'string',
ParamValidator::PARAM_REQUIRED => true
),
);
}
getResult()
[edit]Gets the API result (see Manual:ApiResult.php).
Hooks
[edit]Hooks called from this file are listed in the Category:MediaWiki hooks included in ApiBase.php category.
Notable changes
[edit]- The class became namespaced (MediaWiki\Api\ApiBase) in MW 1.43. Extensions must update uses of this class accordingly.