Extension:DismissableSiteNotice

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manualManual:Extensions
Crystal Clear action run.png
DismissableSiteNotice

Release status:Extension status stable

ImplementationTemplate:Extension#type Skin, MyWiki
DescriptionTemplate:Extension#description Allows users to close the sitenotice
Author(s)Template:Extension#username Brion Vibber (Brion VIBBERtalk)
Latest versionTemplate:Extension#version continuous updates
Database changesTemplate:Extension#needs-updatephp No
LicenseTemplate:Extension#license GNU General Public License 2.0 or later
Download
ExampleTemplate:Extension#example Wikimedia sites
ParametersTemplate:Extension#parameters
  • $wgMajorSiteNoticeID
  • $wgDismissableSiteNoticeForAnons
Hooks usedTemplate:Extension#hook
SiteNoticeAfterManual:Hooks/SiteNoticeAfter

Translate the DismissableSiteNotice extension if it is available at translatewiki.net

Check usage and version matrix.

IssuesPhabricator

Open tasks ยท Report a bug

The DismissableSiteNotice extension allows users to close the sitenotice, using cookies.

Installation[edit]

  • Download and place the file(s) in a directory called DismissableSiteNotice in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php:
wfLoadExtension( 'DismissableSiteNotice' );
  • Configure as required.
  • YesY Done - Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

To users running MediaWiki 1.24 or earlier:

The instructions above describe the new way of installing extensions using wfLoadExtension(), since MediaWiki 1.25. If you need to install this extension in earlier versions, instead of wfLoadExtension( 'DismissableSiteNotice' );, you need to use:

require_once "$IP/extensions/DismissableSiteNotice/DismissableSiteNotice.php";

Configuration[edit]

This extension provides two configuration parameters:

$wgMajorSiteNoticeID

Integer. The value is stored inside a cookie. When a user decides to close the sitenotice, the current value of $wgMajorSiteNoticeID is saved as well and the closed notice is not shown again. $wgMajorSiteNoticeID now can be incremented when a new text is set up as sitenotice. If $wgMajorSiteNoticeID has inbetween been incremented, then the sitenotice is shown again, even if the user closed an older sitenotice before.

$wgDismissableSiteNoticeForAnons

This allows to set whether or not it should be possible for anonymous visitors of the wiki to dismiss the sitenotice shown. Defaults to "false". Available for MW 1.25 +

Usage[edit]

When you add a new sitenotice and want everyone to see it, change the number on the created page "MediaWiki:Sitenotice id" by one (e. g. if it would be 5, you'd replace the page with the number 6 and so on).

How to auto-reset dismissal after every edit to MediaWiki:Sitenotice

The default is that it will remember the dismissal by the user and only reset after the number in MediaWiki:sitenotice_id has been raised. This allows a wiki to make minor updates to a notice without causing it to show again for everybody.

Some sites may not need this additional control and may want to reset it no matter the change. The below code change will reset ("re-display") the sitenotice whenever the MediaWiki:Sitenotice message is edited. This eliminates the need for the "sitenotice_id" message entirely.

In DismissableSiteNotice.php change the one line of extension code:

$id = intval( $wgMajorSiteNoticeID ) . "." . intval( wfMsgForContent( 'sitenotice_id' ) );

to:

$id = intval( $wgMajorSiteNoticeID ) . "." . crc32( wfMsgForContent( 'sitenotice' ) );