Manual:Hooks/EditFilter

EditFilter
Available from version 1.6.0
Perform checks on an edit
Define function:
public static function onEditFilter( $editor, $text, $section, &$error, $summary ) { ... }
Attach hook: In extension.json:
{
	"Hooks": {
		"EditFilter": "MediaWiki\\Extension\\MyExtension\\Hooks::onEditFilter"
	}
}
Called from: File(s): EditPage.php
Interface: EditFilterHook.php

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

Details

edit
  • $editor: EditPage instance (object)
  • $text: Contents of the edit box
  • $section: Section being edited
  • &$error: Error message to return
  • $summary: edit summary provided for edit

Notes

edit
  • You have two options for filtering edits:
    • Return false to halt editing. You'll need to handle error messages, etc. yourself.
    • Return true and modify $error (set to a value other than ''). This will cause the page to stay in edit mode and will cause the contents of $error to be displayed above the edit box. Note: $error should be wikitext.
  • $text is the wikitext submitted by the editor. If only a section of the article was being edited, $text only contains that section. If your processing needs to take into account the entire article, use EditFilterMerged instead.

See also

edit