Manual:Hooks/AlternateEditPreview

From MediaWiki.org
Jump to: navigation, search
AlternateEditPreview
Available from version 1.21.0 (Gerrit change 32675)
Allows replacement of the edit preview
Define function:
public static function onAlternateEditPreview( $editor, &$content, &$previewHTML, &$parserOutput ) { ... }
Attach hook:

In extension.json:

{
	"Hooks": {
		"AlternateEditPreview": [
			"MyExtensionHooks::onAlternateEditPreview"
		]
	}
}

For MediaWiki ≤1.25:

$wgHooks['AlternateEditPreview'][] = 'MyExtensionHooks::onAlternateEditPreview';
Called from: File(s): EditPage.php

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

Details[edit]

  • $editor: EditPage instance
  • &$content: Content object for the text field from the edit page
  • &$previewHTML: Text to be placed into the page for the preview
  • &$parserOutput: the ParserOutput object for the preview

Return true to continue with the normal page preview, or false to use the values set in &$previewHTML and &$parserOutput.

Purpose[edit]

This hook is called at the beginning of getPreviewText() when the page is being previewed during &action=edit. This can be used to replace the normal edit preview by setting the HTML to be output as the preview into &$previewHTML and the ParserOutput object into &$parserOutput, and then returning false.

Note that $editor->previewTextAfterContent is not automatically appended to &$previewHTML; the hook function must do this itself if this is should be included.