Manual:Hooks/AlternateEditPreview

AlternateEditPreview
Available from version 1.21.0 (Gerrit change 32675)
Allows replacement of the edit preview
Define function:
public static function onAlternateEditPreview( EditPage $editor, Content $content, string &$previewHTML, ?ParserOutput &$parserOutput ) { ... }
Attach hook: In extension.json:
{
	"Hooks": {
		"AlternateEditPreview": "MediaWiki\\Extension\\MyExtension\\Hooks::onAlternateEditPreview"
	}
}
Called from: File(s): EditPage.php
Interface: AlternateEditPreviewHook.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: Out-parameter for the text to be placed into the page for the preview, initialized with an empty string
  • &$parserOutput: Out-parameter for the ParserOutput object for the preview, initialized with null

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.