From 5e75e987bffc7ecea6b30cd15e2b6efee89fb2a8 Mon Sep 17 00:00:00 2001 From: Rob Church Date: Mon, 16 Jan 2006 01:58:57 +0000 Subject: [PATCH] * Add cache-safe alternate sitenotice for anonymous users. (MediaWiki:Anonnotice This is displayed instead of the regular sitenotice, if it exists. If not, the regular sitenotice shows. If that doesn't exist, the value of $wgSiteNotice is used, and if that's null, then nothing is shown. --- RELEASE-NOTES | 5 ++- includes/GlobalFunctions.php | 85 +++++++++++++++++++++--------------- languages/Language.php | 1 + 3 files changed, 56 insertions(+), 35 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 16b80bdc2f..58514c383f 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -502,7 +502,10 @@ fully support the editing toolbar, but was found to be too confusing. * (bug 3990) Use existing session name if session.auto_start is on Fixes checks for open sessions, such as the cookie warning on login. Patch by Zbigniew Braniecki. - +* Add cache-safe alternate sitenotice for anonymous users. (MediaWiki:Anonnotice) + This is displayed instead of the regular sitenotice, if it exists. If not, the + regular sitenotice shows. If that doesn't exist, the value of $wgSiteNotice is used, + and if that's null, then nothing is shown. === Caveats === diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 26b013a624..85b3b916a3 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -1351,49 +1351,66 @@ function swap( &$x, &$y ) { $y = $z; } -function wfGetSiteNotice() { - global $wgSiteNotice, $wgTitle, $wgOut, $parserMemc, $wgDBname; - $fname = 'wfGetSiteNotice'; +function wfGetCachedNotice( $name ) { + global $wgOut, $parserMemc, $wgDBname; + $fname = 'wfGetCachedNotice'; wfProfileIn( $fname ); - - $shouldParse=false; - - $notice = wfMsgForContent( 'sitenotice' ); - if( $notice == '<sitenotice>' || $notice == '-' ) { - $notice = ''; - } - if( $notice == '' ) { - # We may also need to override a message with eg downtime info - # FIXME: make this work! - $notice = $wgSiteNotice; - } - if($notice != '-' && $notice != '') { - $cachednotice=$parserMemc->get("{$wgDBname}:sitenotice"); - if (is_array($cachednotice)) { - if (md5($notice)==$cachednotice['hash']) { - $notice = $cachednotice['html']; - } else { - $shouldParse=true; - } + + $needParse = false; + $notice = wfMsgForContent( $name ); + if( $notice == '<'. $name . ';>' || $notice == '-' ) { + wfProfileOut( $fname ); + return( false ); + } + + $cachedNotice = $parserMemc->get( $wgDBname . ':' . $name ); + if( is_array( $cachedNotice ) ) { + if( md5( $notice ) == $cachedNotice['hash'] ) { + $notice = $cachedNotice['html']; } else { - $shouldParse=true; + $needParse = true; } - if ($shouldParse) { - if( is_object( $wgOut ) ) { - $parsed = $wgOut->parse( $notice ); - $parserMemc->set("{$wgDBname}:sitenotice", - array('html' => $parsed, 'hash' => md5($notice)), 600); - $notice = $parsed; - } else { - wfDebug( "wfGetSiteNotice called with no \$wgOut available" ); - $notice = ''; - } + } else { + $needParse = true; + } + + if( $needParse ) { + if( is_object( $wgOut ) ) { + $parsed = $wgOut->parse( $notice ); + $parserMemc->set( $wgDBname . ':' . $name, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 ); + $notice = $parsed; + } else { + wfDebug( 'wfGetCachedNotice called for ' . $name . ' with no $wgOut available' ); + $notice = ''; } } + wfProfileOut( $fname ); return $notice; } +function wfGetSiteNotice() { + global $wgUser, $wgSiteNotice; + $fname = 'wfGetSiteNotice'; + wfProfileIn( $fname ); + + if( $wgUser->isLoggedIn() ) { + $siteNotice = wfGetCachedNotice( 'sitenotice' ); + $siteNotice = !$siteNotice ? $wgSiteNotice : $siteNotice; + } else { + $anonNotice = wfGetCachedNotice( 'anonnotice' ); + if( !$anonNotice ) { + $siteNotice = wfGetCachedNotice( 'sitenotice' ); + $siteNotice = !$siteNotice ? $wgSiteNotice : $siteNotice; + } else { + $siteNotice = $anonNotice; + } + } + + wfProfileOut( $fname ); + return( $siteNotice ); +} + /** * Format an XML element with given attributes and, optionally, text content. * Element and attribute names are assumed to be ready for literal inclusion. diff --git a/languages/Language.php b/languages/Language.php index f11940abe7..24201b0d63 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -505,6 +505,7 @@ See $1.', 'restorelink' => '$1 deleted edits', 'feedlinks' => 'Feed:', 'sitenotice' => '-', # the equivalent to wgSiteNotice +'anonnotice' => '-'; # Short words for each namespace, by default used in the 'article' tab in monobook 'nstab-main' => 'Article', -- 2.20.1