Manual:$wgAPIModules

From MediaWiki.org
Jump to navigation Jump to search
This page is a translated version of the page Manual:$wgAPIModules and the translation is 21% complete.

Other languages:
Deutsch • ‎English • ‎español • ‎français • ‎italiano • ‎polski • ‎português • ‎português do Brasil • ‎中文 • ‎日本語
Extensões: $wgAPIModules
API module extensions.
Introduzida na versão:1.11.0 (r25364)
Removida na versão:ainda em uso
Valores permitidos:(array)
Valor por omissão:[]
Outras configurações: Lista Alfabética | Lista por Função

Detalhes

Associative array mapping module name to class name. Extension modules may override the core modules (which are initialized in ApiMain.php ).

Exemplo

Suppose you wanted to create an API module to calibrate the wiki's awesomeness level. You would write a new extension, CalibrateAwesomeness, putting the following in your CalibrateAwesomeness.php file:

$wgAutoloadClasses['ApiCalibrateAwesomeness'] = __DIR__ . 'ApiCalibrateAwesomeness.php';
$wgAPIModules['calibrateawesomeness'] = 'ApiCalibrateAwesomeness';

Then you would create an ApiCalibrateAwesomeness.php file containing an ApiCalibrateAwesomeness class that extends, say, ApiBase , e.g.

class ApiCalibrateAwesomeness extends ApiBase {
	public function execute() {
	...
	}

	public function getAllowedParams() {
		return array(
			'level' => array (
				ApiBase::PARAM_TYPE => 'integer',
				ApiBase::PARAM_REQUIRED => true
			)
		);
	}
}

After installing your new extension on the English Wikipedia, you could then access that module by using, e.g., https://en.wikipedia.org/w/api.php?action=calibrateawesomeness&level=1000.

If you want to use a factory for creating the API module, you can define it like this:

$wgAPIModules['calibrateawesomeness'] = [
    'class' => 'ApiCalibrateAwesomeness',
    'factory' => 'ApiCalibrateAwesomenessFactory::create',
];

where class is the class of the API module and factory is some callable.

See also