* Add cache-safe alternate sitenotice for anonymous users. (MediaWiki:Anonnotice
authorRob Church <robchurch@users.mediawiki.org>
Mon, 16 Jan 2006 01:58:57 +0000 (01:58 +0000)
committerRob Church <robchurch@users.mediawiki.org>
Mon, 16 Jan 2006 01:58:57 +0000 (01:58 +0000)
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
includes/GlobalFunctions.php
languages/Language.php

index 16b80bd..58514c3 100644 (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 ===
 
index 26b013a..85b3b91 100644 (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 == '&lt;sitenotice&gt;' || $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 == '&lt;'. $name . ';&gt' || $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.
index f11940a..24201b0 100644 (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',