Open main menu

Manual:Hooks/PageContentSave

< Manual:Hooks
PageContentSave
Available from version 1.21.0
Before an article is saved.
Define function:
public static function onPageContentSave( &$wikiPage, &$user, &$content, &$summary, 
$isMinor, $isWatch, $section, &$flags, &$status ) { ... }
Attach hook:

In extension.json:

{
	"Hooks": {
		"PageContentSave": "MyExtensionHooks::onPageContentSave"
	}
}

For MediaWiki ≤1.25:

$wgHooks['PageContentSave'][] = 'MyExtensionHooks::onPageContentSave';
Called from:File(s): WikiPage.php

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

DetailsEdit

  • $wikiPage: the WikiPage (object) being saved
  • $user: the User (object) saving the article
  • $content: the new article content, as a Content object
  • &$summary: CommentStoreComment object containing the edit comment. Can be replaced with a new one.
  • $isMinor: Boolean flag specifying if the edit was marked as minor.
  • $isWatch: Previously a watch flag. Currently unused, always null.
  • $section: Previously the section number being edited. Currently unused, always null.
  • $flags: All EDIT_… flags (including EDIT_MINOR) as an integer number. See WikiPage::doEditContent documentation for flags' definition.
  • $status: StatusValue object for the hook handlers resulting status. Either set $hookStatus->fatal() or return false to abort the save action.
  • Return value: Return false to abort saving the page.

ExamplesEdit

# Return false to cancel a save and use $status to provide an error message.
$wgHooks['PageContentSave'][] = function( $wikiPage, $user, $content, $summary, $isMinor, $isWatch, $section, $flags, $status) {
	if ( true ) {
		$status->fatal( new RawMessage( "Your Error Message Here!" ) );
	}
	return false;
}

See alsoEdit