Available from version 1.25.0 (Gerrit change 161093)
Use to syntax-highlight API pretty-printed output. When highlighting, add output to $context->getOutput() and return false.
Define function:
public static function onApiFormatHighlight( $context, $text, $mime, $format ) { ... }
Attach hook:

In extension.json:

	"Hooks": {
		"ApiFormatHighlight": "MyExtensionHooks::onApiFormatHighlight"

For MediaWiki ≤1.25:

$wgHooks['ApiFormatHighlight'][] = 'MyExtensionHooks::onApiFormatHighlight';
Called from:File(s): api/ApiFormatBase.php
Function(s): closePrinter

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


  • $context: An IContextSource.
  • $text: Text to be highlighted.
  • $mime: MIME type of $text.
  • $format: API format code for $text.