Jump to content

Handleiding:ApiBase.php

From mediawiki.org
This page is a translated version of the page Manual:ApiBase.php and the translation is 45% complete.
Outdated translations are marked like this.

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.

Sien ook