Podręcznik:$wgAPIModules

This page is a translated version of the page Manual:$wgAPIModules and the translation is 47% complete.
API: $wgAPIModules
Rozszerzenia modułów API.
Wprowadzono w wersji:1.11.0 (r25364)
Usunięto w wersji:nadal w użyciu
Dozwolone wartości:(tablica)
Domyślna wartość:[]

Szczegóły

Tablica asocjacyjna łącząca nazwę modułu z nazwą klasy. Extension modules may override the core modules (which are initialized in ApiMain.php ).

Przykład

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 extension.json file:

	"AutoloadNamespaces": {
		"MediaWiki\\Extension\\CalibrateAwesomeness\\": "src/"
	},
	"APIModules": {
		"calibrateawesomeness": "MediaWiki\\Extension\\CalibrateAwesomeness\\ApiCalibrateAwesomeness"
	},

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

namespace MediaWiki\Extension\CalibrateAwesomeness;

use ApiBase;
use Wikimedia\ParamValidator\ParamValidator;

class ApiCalibrateAwesomeness extends ApiBase {

	public function execute() {
		/* … */
	}

	public function getAllowedParams() {
		return [
			'level' => [
				ParamValidator::PARAM_TYPE => 'integer',
				ParamValidator::PARAM_REQUIRED => true,
			]
		];
	}
}

After installing your new extension, you could then access that module by using, e.g., https://example.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:

	"APIModules": {
		"calibrateawesomeness": {
			"class": "MediaWiki\\Extension\\CalibrateAwesomeness\\ApiCalibrateAwesomeness",
			"factory": "MediaWiki\\Extension\\CalibrateAwesomeness\\ApiCalibrateAwesomenessFactory::create"
	},

Where class is the class of the API module and factory is some callable. There are more options available, see ObjectFactory for the full syntax.


Zobacz też