Manual:Hooks/APIQueryAfterExecute

APIQueryAfterExecute
Available from version 1.14.0
Use this hook to extend core query modules
Define function:
public static function onAPIQueryAfterExecute( ApiBase &$module ) { ... }
Attach hook: In extension.json:
{
	"Hooks": {
		"APIQueryAfterExecute": "MediaWiki\\Extension\\MyExtension\\Hooks::onAPIQueryAfterExecute"
	}
}
Called from: File(s): api/ApiQuery.php
Interface: APIQueryAfterExecuteHook.php

For more information about attaching hooks, see Manual:Hooks .
For examples of extensions using this hook, see Category:APIQueryAfterExecute extensions.


Details edit

Called after calling the execute() method of an API query module.

  • $module: ApiBase object

Extending edit

To extend from one particular API module as opposed to all of them, run an instanceof check against the particular class in the ./includes/API directory. So that, to extend the parse module you would do a check against the class ApiParse, returning true even if it isn't the module you intend to extend.

Sample code:

function apiExtensionFunction( &$module ) {
	if( !( $module instanceof ApiParse ) ) {
		return true;
	}
	// ... extension code here ...
}

Without adding this, all modules of the API will be affected by the extension.

To add additional output to the feed, the result must be pulled from the module. Original output may be modified using the same method.

Sample code:

$result = $module->getResult();
$data = $result->getData();

$status = $result->addValue(
	array( 'foo', 'bar' ),
	'etc',
	$addition_value
);

In effect, what the above sample will do is append a new value onto the data structure foo->bar so that at foo->bar->etc the value will be whatever is contained within $addition_value. Where in the hierarchy exactly things may go is up to the extension developer however each API feed does have a somewhat unique data hierarchy which it should placed into.