Handleiding:ApiBase.php
This page is outdated. |
| MediaWiki file: ApiBase.php | |
|---|---|
| Location: | includes/api/ (includes/Api/ in 1.46 or later) |
| Source code: | master • 1.46.0 • 1.45.4 • 1.43.9 |
| Classes: | MediaWiki\Api\ApiBase |
Die 'ApiBase klas' implementeer baie basiese API-funksies, en is die basis van alle API-klasse.
Die klasfunksies word in verskillende funksiesareas verdeel:
- 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
Funksies
getAllowedParams()
Spesifiseer watter parameters toegelaat word en watter vereistes daaraan gestel moet word. Kyk na die dokumentasie aan die bokant van $apiBase vir die konstante PARAM_DFLT, PARAM_ISMULTI, PARAM_TYPE, PARAM_MAX, PARAM_MAX2, PARAM_MIN, PARAM_ALLOW_DUPLICATES, PARAM_DEPRECATED, PARAM_REQUIRED en PARAM_RANGE_ENFOR. Die moontlike tipes parameters is NULL, string, heelgetal, limiet, Boole, tydstempel, gebruiker of oplaai. 'N "Gebruiker" -parameter is 'n gebruikersnaam wat bekragtig word met Titel :: makeTitleSafe () . Vir Boole-parameters is 'n standaardwaarde van iets anders as 'onwaar' nie toegelaat nie.
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, 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.
Voorbeeld"
// Title parameter.
public function getAllowedParams() {
return array(
'title' => array (
ParamValidator::PARAM_TYPE => 'string',
ParamValidator::PARAM_REQUIRED => true
),
);
}
getResult()
kry die API-resultaat (sien Manual:ApiResult.php).
Hooks
Haken wat van heirdie lêer genoem word, word gelys in die Category:MediaWiki hooks included in ApiBase.php kategorie.
Notable changes
- The class became namespaced (MediaWiki\Api\ApiBase) in MW 1.43. Extensions must update uses of this class accordingly.