Moved wfGetSiteNotice(), wfGetNamespaceNotice() and wfGetCachedNotice() to Skin call...
authorAlexandre Emsenhuber <ialex@users.mediawiki.org>
Sat, 12 Feb 2011 21:24:05 +0000 (21:24 +0000)
committerAlexandre Emsenhuber <ialex@users.mediawiki.org>
Sat, 12 Feb 2011 21:24:05 +0000 (21:24 +0000)
I didn't left compatibility functions since there's no other call to these functions in core or extensions.

docs/hooks.txt
includes/GlobalFunctions.php
includes/Skin.php
includes/SkinLegacy.php
includes/SkinTemplate.php
skins/CologneBlue.php
skins/Nostalgia.php

index 2f79c83..3e1d4ca 100644 (file)
@@ -1459,11 +1459,13 @@ $page: The SpecialSearch object.
 
 'SiteNoticeBefore': Before the sitenotice/anonnotice is composed
 &$siteNotice: HTML returned as the sitenotice
+$skin: Skin object
 Return true to allow the normal method of notice selection/rendering to work,
 or change the value of $siteNotice and return false to alter it.
 
 'SiteNoticeAfter': After the sitenotice/anonnotice is composed
 &$siteNotice: HTML sitenotice
+$skin: Skin object
 Alter the contents of $siteNotice to add to/alter the sitenotice/anonnotice.
 
 'SkinAfterBottomScripts': At the end of Skin::bottomScripts()
index 71847cc..e88afda 100644 (file)
@@ -1996,108 +1996,6 @@ function swap( &$x, &$y ) {
        $y = $z;
 }
 
-function wfGetCachedNotice( $name ) {
-       global $wgOut, $wgRenderHashAppend, $parserMemc;
-       $fname = 'wfGetCachedNotice';
-       wfProfileIn( $fname );
-
-       $needParse = false;
-
-       if( $name === 'default' ) {
-               // special case
-               global $wgSiteNotice;
-               $notice = $wgSiteNotice;
-               if( empty( $notice ) ) {
-                       wfProfileOut( $fname );
-                       return false;
-               }
-       } else {
-               $msg = wfMessage( $name )->inContentLanguage();
-               if( $msg->isDisabled() ) {
-                       wfProfileOut( $fname );
-                       return( false );
-               }
-               $notice = $msg->plain();
-       }
-
-       // Use the extra hash appender to let eg SSL variants separately cache.
-       $key = wfMemcKey( $name . $wgRenderHashAppend );
-       $cachedNotice = $parserMemc->get( $key );
-       if( is_array( $cachedNotice ) ) {
-               if( md5( $notice ) == $cachedNotice['hash'] ) {
-                       $notice = $cachedNotice['html'];
-               } else {
-                       $needParse = true;
-               }
-       } else {
-               $needParse = true;
-       }
-
-       if( $needParse ) {
-               if( is_object( $wgOut ) ) {
-                       $parsed = $wgOut->parse( $notice );
-                       $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
-                       $notice = $parsed;
-               } else {
-                       wfDebug( 'wfGetCachedNotice called for ' . $name . ' with no $wgOut available' . "\n" );
-                       $notice = '';
-               }
-       }
-       $notice = '<div id="localNotice">' .$notice . '</div>';
-       wfProfileOut( $fname );
-       return $notice;
-}
-
-function wfGetNamespaceNotice() {
-       global $wgTitle;
-
-       # Paranoia
-       if ( !isset( $wgTitle ) || !is_object( $wgTitle ) ) {
-               return '';
-       }
-
-       $fname = 'wfGetNamespaceNotice';
-       wfProfileIn( $fname );
-
-       $key = 'namespacenotice-' . $wgTitle->getNsText();
-       $namespaceNotice = wfGetCachedNotice( $key );
-       if ( $namespaceNotice && substr( $namespaceNotice, 0, 7 ) != '<p>&lt;' ) {
-               $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . '</div>';
-       } else {
-               $namespaceNotice = '';
-       }
-
-       wfProfileOut( $fname );
-       return $namespaceNotice;
-}
-
-function wfGetSiteNotice() {
-       global $wgUser;
-       $fname = 'wfGetSiteNotice';
-       wfProfileIn( $fname );
-       $siteNotice = '';
-
-       if( wfRunHooks( 'SiteNoticeBefore', array( &$siteNotice ) ) ) {
-               if( is_object( $wgUser ) && $wgUser->isLoggedIn() ) {
-                       $siteNotice = wfGetCachedNotice( 'sitenotice' );
-               } else {
-                       $anonNotice = wfGetCachedNotice( 'anonnotice' );
-                       if( !$anonNotice ) {
-                               $siteNotice = wfGetCachedNotice( 'sitenotice' );
-                       } else {
-                               $siteNotice = $anonNotice;
-                       }
-               }
-               if( !$siteNotice ) {
-                       $siteNotice = wfGetCachedNotice( 'default' );
-               }
-       }
-
-       wfRunHooks( 'SiteNoticeAfter', array( &$siteNotice ) );
-       wfProfileOut( $fname );
-       return $siteNotice;
-}
-
 /**
  * BC wrapper for MimeMagic::singleton()
  * @deprecated No longer needed as of 1.17 (r68836). Remove in 1.19.
index 587ac65..3a671dc 100644 (file)
@@ -1550,4 +1550,115 @@ abstract class Skin extends Linker {
 
                return $ntl;
        }
+
+       /**
+        * Get a cached notice
+        *
+        * @param $name String: message name, or 'default' for $wgSiteNotice
+        * @return String: HTML fragment
+        */
+       private function getCachedNotice( $name ) {
+               global $wgOut, $wgRenderHashAppend, $parserMemc;
+
+               wfProfileIn( __METHOD__ );
+
+               $needParse = false;
+
+               if( $name === 'default' ) {
+                       // special case
+                       global $wgSiteNotice;
+                       $notice = $wgSiteNotice;
+                       if( empty( $notice ) ) {
+                               wfProfileOut( __METHOD__ );
+                               return false;
+                       }
+               } else {
+                       $msg = wfMessage( $name )->inContentLanguage();
+                       if( $msg->isDisabled() ) {
+                               wfProfileOut( __METHOD__ );
+                               return false;
+                       }
+                       $notice = $msg->plain();
+               }
+
+               // Use the extra hash appender to let eg SSL variants separately cache.
+               $key = wfMemcKey( $name . $wgRenderHashAppend );
+               $cachedNotice = $parserMemc->get( $key );
+               if( is_array( $cachedNotice ) ) {
+                       if( md5( $notice ) == $cachedNotice['hash'] ) {
+                               $notice = $cachedNotice['html'];
+                       } else {
+                               $needParse = true;
+                       }
+               } else {
+                       $needParse = true;
+               }
+
+               if ( $needParse ) {
+                       if( is_object( $wgOut ) ) {
+                               $parsed = $wgOut->parse( $notice );
+                               $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
+                               $notice = $parsed;
+                       } else {
+                               wfDebug( 'wfGetCachedNotice called for ' . $name . ' with no $wgOut available' . "\n" );
+                               $notice = '';
+                       }
+               }
+
+               $notice = '<div id="localNotice">' .$notice . '</div>';
+               wfProfileOut( __METHOD__ );
+               return $notice;
+       }
+
+       /**
+        * Get a notice based on page's namespace
+        *
+        * @return String: HTML fragment
+        */
+       function getNamespaceNotice() {
+               wfProfileIn( __METHOD__ );
+
+               $key = 'namespacenotice-' . $this->mTitle->getNsText();
+               $namespaceNotice = wfGetCachedNotice( $key );
+               if ( $namespaceNotice && substr( $namespaceNotice, 0, 7 ) != '<p>&lt;' ) {
+                       $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . '</div>';
+               } else {
+                       $namespaceNotice = '';
+               }
+
+               wfProfileOut( $fname );
+               return $namespaceNotice;
+       }
+
+       /**
+        * Get the site notice
+        *
+        * @return String: HTML fragment
+        */
+       function getSiteNotice() {
+               global $wgUser;
+
+               wfProfileIn( __METHOD__ );
+               $siteNotice = '';
+
+               if ( wfRunHooks( 'SiteNoticeBefore', array( &$siteNotice, $this ) ) ) {
+                       if ( is_object( $wgUser ) && $wgUser->isLoggedIn() ) {
+                               $siteNotice = $this->getCachedNotice( 'sitenotice' );
+                       } else {
+                               $anonNotice = $this->getCachedNotice( 'anonnotice' );
+                               if ( !$anonNotice ) {
+                                       $siteNotice = $this->getCachedNotice( 'sitenotice' );
+                               } else {
+                                       $siteNotice = $anonNotice;
+                               }
+                       }
+                       if ( !$siteNotice ) {
+                               $siteNotice = $this->getCachedNotice( 'default' );
+                       }
+               }
+
+               wfRunHooks( 'SiteNoticeAfter', array( &$siteNotice, $this ) );
+               wfProfileOut( __METHOD__ );
+               return $siteNotice;
+}
 }
index 4f93dba..0f304a9 100644 (file)
@@ -134,7 +134,7 @@ class LegacyTemplate extends BaseTemplate {
                $s .= "</tr>\n</table>\n</div>\n";
                $s .= "\n<div id='article'>\n";
 
-               $notice = wfGetSiteNotice();
+               $notice = $this->getSkin()->getSiteNotice();
 
                if ( $notice ) {
                        $s .= "\n<div id='siteNotice'>$notice</div>\n";
index 4704a1e..d04a84c 100644 (file)
@@ -453,7 +453,7 @@ class SkinTemplate extends Skin {
                }
 
                $tpl->set( 'reporttime', wfReportTime() );
-               $tpl->set( 'sitenotice', wfGetSiteNotice() );
+               $tpl->set( 'sitenotice', $this->getSiteNotice() );
                $tpl->set( 'bottomscripts', $this->bottomScripts( $out ) );
 
                $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
index 0363072..e157ed4 100644 (file)
@@ -86,7 +86,7 @@ class CologneBlueTemplate extends LegacyTemplate {
 
                $s .= "\n</div>\n<div id='article'>";
 
-               $notice = wfGetSiteNotice();
+               $notice = $this->getSkin()->getSiteNotice();
                if( $notice ) {
                        $s .= "\n<div id='siteNotice'>$notice</div>\n";
                }
index 2df7ddf..9e89787 100644 (file)
@@ -37,7 +37,7 @@ class NostalgiaTemplate extends LegacyTemplate {
                $s .= '<div id="topbar">';
                $s .= $this->topLinks() . "\n<br />";
 
-               $notice = wfGetSiteNotice();
+               $notice = $this->getSkin()->getSiteNotice();
                if( $notice ) {
                        $s .= "\n<div id='siteNotice'>$notice</div>\n";
                }