Manual:Hooks/SiteNoticeBefore

From Linux Web Expert

SiteNoticeBefore
<translate> Available from <tvar name=1><translate> version <tvar </tvar></translate>
Used to modify the sitenotice before it has been created from $wgSiteNotice. Return false to suppress or modify default site notice.
<translate> Define function:</translate>
public static function onSiteNoticeBefore( &$siteNotice, $skin ) { ... }
<translate> Attach hook:</translate> <translate> In <tvar name=1>extension.json</tvar>:</translate>
{
	"Hooks": {
		"SiteNoticeBefore": "MediaWiki\\Extension\\MyExtension\\Hooks::onSiteNoticeBefore"
	}
}
<translate> Called from:</translate> <translate> File(s):</translate> Skin.php
<translate> Interface:</translate> SiteNoticeBeforeHook.php

<translate> For more information about attaching hooks, see <tvar name=1>Manual:Hooks </tvar>.</translate>
<translate> For examples of extensions using this hook, see <tvar name=cat>Category:SiteNoticeBefore extensions</tvar>.</translate>


Details

  • $siteNotice: Empty string, ignored if the hook returns true.
  • $skin: Skin object MW 1.18+

If the function returns false, no attempt will be done to load the sitenotice from interface messages or $wgSiteNotice , and the contents of $siteNotice will be used instead. If the function returns true, there will be no change in behavior of the sitenotice.

Example

If the database is read only ($wgReadOnly ) and there's a sitenotice in MediaWiki:Sitenotice you want to override, you can use this hook for that purpose:

$wgHooks['SiteNoticeBefore'][] = function ( &$siteNotice, $skin ) {
	$siteNotice = "There's ongoing maintenance to the site. We'll open editing shortly.";
	return false;
};

See also