* 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.
This commit is contained in:
Rob Church 2006-01-16 01:58:57 +00:00
parent 05c9960bc9
commit 5e75e987bf
3 changed files with 55 additions and 34 deletions

View file

@ -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 ===

View file

@ -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 = '';
$needParse = false;
$notice = wfMsgForContent( $name );
if( $notice == '<'. $name . ';&gt' || $notice == '-' ) {
wfProfileOut( $fname );
return( false );
}
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;
}
$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.

View file

@ -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',