From 251b345151a1ce517d9f06f9bfa18d520a6c7e5a Mon Sep 17 00:00:00 2001 From: Kevin Israel Date: Tue, 31 Mar 2015 13:42:32 -0400 Subject: [PATCH] Allow setting anonnotice to "" to prevent fallback to sitenotice Previously we only used Message::isDisabled (non-existent, empty string, or "-") to decide whether to show a notice. If 'anonnotice' was disabled 'sitenotice' was shown instead. When addressing logged-in users only, wikis typically use 'sitenotice' and then put invisible content in 'anonnotice' (so that it shadows the 'sitenotice'). Now that the DismissableSiteNotice extension supports closing of the notice for anonymous users (as of I87df3301c), this becomes problematic as it has no way of knowing the notice was meant to be invisible (and thus renders bogus "[close]" to all users). This supersedes hacks such as

or . Instead, the empty string can now be used to have no anonnotice content, but also don't show the 'sitenotice'. Disabling with '-' (default) can still used to fallback to 'sitenotice'. Also changed the code to, for consistency, allow hiding $wgSiteNotice for all users by setting the sitenotice message to "-". Bug: T94536 Change-Id: I11b8b883d480d0e07d8b395dd92360cb15de7c5b --- RELEASE-NOTES-1.25 | 3 +++ includes/skins/Skin.php | 11 +++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/RELEASE-NOTES-1.25 b/RELEASE-NOTES-1.25 index 1ec8b930b4..7fc13bd2a3 100644 --- a/RELEASE-NOTES-1.25 +++ b/RELEASE-NOTES-1.25 @@ -119,6 +119,9 @@ production. proper, published library, which is now tagged as v1.0.0. * A new message (defaulting to blank), 'editnotice-notext', can be shown to users when they are editing if no edit notices apply to the page being edited. +* (T94536) You can now make the sitenotice appear to logged-in users only by + editing MediaWiki:Anonnotice and replacing its content with "". Setting it to + "-" (default) will continue disable it and fallback to MediaWiki:Sitenotice. ==== External libraries ==== * MediaWiki now requires certain external libraries to be installed. In the past diff --git a/includes/skins/Skin.php b/includes/skins/Skin.php index dc25c6cdc8..ac7a85ba44 100644 --- a/includes/skins/Skin.php +++ b/includes/skins/Skin.php @@ -1477,7 +1477,8 @@ abstract class Skin extends ContextSource { * Get a cached notice * * @param string $name Message name, or 'default' for $wgSiteNotice - * @return string HTML fragment + * @return string|bool HTML fragment, or false to indicate that the caller + * should fall back to the next notice in its sequence */ private function getCachedNotice( $name ) { global $wgRenderHashAppend, $parserMemc, $wgContLang; @@ -1493,7 +1494,9 @@ abstract class Skin extends ContextSource { } } else { $msg = $this->msg( $name )->inContentLanguage(); - if ( $msg->isDisabled() ) { + if ( $msg->isBlank() ) { + return ''; + } elseif ( $msg->isDisabled() ) { return false; } $notice = $msg->plain(); @@ -1554,13 +1557,13 @@ abstract class Skin extends ContextSource { $siteNotice = $this->getCachedNotice( 'sitenotice' ); } else { $anonNotice = $this->getCachedNotice( 'anonnotice' ); - if ( !$anonNotice ) { + if ( $anonNotice === false ) { $siteNotice = $this->getCachedNotice( 'sitenotice' ); } else { $siteNotice = $anonNotice; } } - if ( !$siteNotice ) { + if ( $siteNotice === false ) { $siteNotice = $this->getCachedNotice( 'default' ); } } -- 2.20.1