Manual:Hooks/PageContentSave
Appearance
Deprecated: This feature is deprecated and should no longer be used, however it is still available for reasons of backwards compatibility .
|
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": "MediaWiki\\Extension\\MyExtension\\Hooks::onPageContentSave"
}
}
|
Called from: | File(s): Storage/PageUpdater.php |
Interface: | PageContentSaveHook.php |
For more information about attaching hooks, see Manual:Hooks .
For examples of extensions using this hook, see Category:PageContentSave extensions.
Details
[edit]$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.
Earlier versions of MediaWiki (somewhat unintentionally) allowed changing parameters other than $summary
. Since 1.32 that does not work anymore; there is currently no exact replacement. If you own the content type, you can use a pre-save transform to change the content.
Examples
[edit]# 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 also
[edit]- ArticleSave: legacy hook, deprecated in favor of this one
- PageContentSaveComplete
- EditPage::attemptSave