r82034 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82033‎ | r82034 | r82035 >
Date:21:24, 12 February 2011
Author:ialex
Status:ok (Comments)
Tags:
Comment:
Moved wfGetSiteNotice(), wfGetNamespaceNotice() and wfGetCachedNotice() to Skin call to allow passing the Skin object to the SiteNoticeBefore and SiteNoticeAfter hooks.
I didn't left compatibility functions since there's no other call to these functions in core or extensions.
Modified paths:
  • /trunk/phase3/docs/hooks.txt (modified) (history)
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/includes/Skin.php (modified) (history)
  • /trunk/phase3/includes/SkinLegacy.php (modified) (history)
  • /trunk/phase3/includes/SkinTemplate.php (modified) (history)
  • /trunk/phase3/skins/CologneBlue.php (modified) (history)
  • /trunk/phase3/skins/Nostalgia.php (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/CologneBlue.php
@@ -86,7 +86,7 @@
8787
8888 $s .= "\n</div>\n<div id='article'>";
8989
90 - $notice = wfGetSiteNotice();
 90+ $notice = $this->getSkin()->getSiteNotice();
9191 if( $notice ) {
9292 $s .= "\n<div id='siteNotice'>$notice</div>\n";
9393 }
Index: trunk/phase3/skins/Nostalgia.php
@@ -37,7 +37,7 @@
3838 $s .= '<div id="topbar">';
3939 $s .= $this->topLinks() . "\n<br />";
4040
41 - $notice = wfGetSiteNotice();
 41+ $notice = $this->getSkin()->getSiteNotice();
4242 if( $notice ) {
4343 $s .= "\n<div id='siteNotice'>$notice</div>\n";
4444 }
Index: trunk/phase3/docs/hooks.txt
@@ -1459,11 +1459,13 @@
14601460
14611461 'SiteNoticeBefore': Before the sitenotice/anonnotice is composed
14621462 &$siteNotice: HTML returned as the sitenotice
 1463+$skin: Skin object
14631464 Return true to allow the normal method of notice selection/rendering to work,
14641465 or change the value of $siteNotice and return false to alter it.
14651466
14661467 'SiteNoticeAfter': After the sitenotice/anonnotice is composed
14671468 &$siteNotice: HTML sitenotice
 1469+$skin: Skin object
14681470 Alter the contents of $siteNotice to add to/alter the sitenotice/anonnotice.
14691471
14701472 'SkinAfterBottomScripts': At the end of Skin::bottomScripts()
Index: trunk/phase3/includes/GlobalFunctions.php
@@ -1996,108 +1996,6 @@
19971997 $y = $z;
19981998 }
19991999
2000 -function wfGetCachedNotice( $name ) {
2001 - global $wgOut, $wgRenderHashAppend, $parserMemc;
2002 - $fname = 'wfGetCachedNotice';
2003 - wfProfileIn( $fname );
2004 -
2005 - $needParse = false;
2006 -
2007 - if( $name === 'default' ) {
2008 - // special case
2009 - global $wgSiteNotice;
2010 - $notice = $wgSiteNotice;
2011 - if( empty( $notice ) ) {
2012 - wfProfileOut( $fname );
2013 - return false;
2014 - }
2015 - } else {
2016 - $msg = wfMessage( $name )->inContentLanguage();
2017 - if( $msg->isDisabled() ) {
2018 - wfProfileOut( $fname );
2019 - return( false );
2020 - }
2021 - $notice = $msg->plain();
2022 - }
2023 -
2024 - // Use the extra hash appender to let eg SSL variants separately cache.
2025 - $key = wfMemcKey( $name . $wgRenderHashAppend );
2026 - $cachedNotice = $parserMemc->get( $key );
2027 - if( is_array( $cachedNotice ) ) {
2028 - if( md5( $notice ) == $cachedNotice['hash'] ) {
2029 - $notice = $cachedNotice['html'];
2030 - } else {
2031 - $needParse = true;
2032 - }
2033 - } else {
2034 - $needParse = true;
2035 - }
2036 -
2037 - if( $needParse ) {
2038 - if( is_object( $wgOut ) ) {
2039 - $parsed = $wgOut->parse( $notice );
2040 - $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
2041 - $notice = $parsed;
2042 - } else {
2043 - wfDebug( 'wfGetCachedNotice called for ' . $name . ' with no $wgOut available' . "\n" );
2044 - $notice = '';
2045 - }
2046 - }
2047 - $notice = '<div id="localNotice">' .$notice . '</div>';
2048 - wfProfileOut( $fname );
2049 - return $notice;
2050 -}
2051 -
2052 -function wfGetNamespaceNotice() {
2053 - global $wgTitle;
2054 -
2055 - # Paranoia
2056 - if ( !isset( $wgTitle ) || !is_object( $wgTitle ) ) {
2057 - return '';
2058 - }
2059 -
2060 - $fname = 'wfGetNamespaceNotice';
2061 - wfProfileIn( $fname );
2062 -
2063 - $key = 'namespacenotice-' . $wgTitle->getNsText();
2064 - $namespaceNotice = wfGetCachedNotice( $key );
2065 - if ( $namespaceNotice && substr( $namespaceNotice, 0, 7 ) != '<p>&lt;' ) {
2066 - $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . '</div>';
2067 - } else {
2068 - $namespaceNotice = '';
2069 - }
2070 -
2071 - wfProfileOut( $fname );
2072 - return $namespaceNotice;
2073 -}
2074 -
2075 -function wfGetSiteNotice() {
2076 - global $wgUser;
2077 - $fname = 'wfGetSiteNotice';
2078 - wfProfileIn( $fname );
2079 - $siteNotice = '';
2080 -
2081 - if( wfRunHooks( 'SiteNoticeBefore', array( &$siteNotice ) ) ) {
2082 - if( is_object( $wgUser ) && $wgUser->isLoggedIn() ) {
2083 - $siteNotice = wfGetCachedNotice( 'sitenotice' );
2084 - } else {
2085 - $anonNotice = wfGetCachedNotice( 'anonnotice' );
2086 - if( !$anonNotice ) {
2087 - $siteNotice = wfGetCachedNotice( 'sitenotice' );
2088 - } else {
2089 - $siteNotice = $anonNotice;
2090 - }
2091 - }
2092 - if( !$siteNotice ) {
2093 - $siteNotice = wfGetCachedNotice( 'default' );
2094 - }
2095 - }
2096 -
2097 - wfRunHooks( 'SiteNoticeAfter', array( &$siteNotice ) );
2098 - wfProfileOut( $fname );
2099 - return $siteNotice;
2100 -}
2101 -
21022000 /**
21032001 * BC wrapper for MimeMagic::singleton()
21042002 * @deprecated No longer needed as of 1.17 (r68836). Remove in 1.19.
Index: trunk/phase3/includes/SkinLegacy.php
@@ -134,7 +134,7 @@
135135 $s .= "</tr>\n</table>\n</div>\n";
136136 $s .= "\n<div id='article'>\n";
137137
138 - $notice = wfGetSiteNotice();
 138+ $notice = $this->getSkin()->getSiteNotice();
139139
140140 if ( $notice ) {
141141 $s .= "\n<div id='siteNotice'>$notice</div>\n";
Index: trunk/phase3/includes/SkinTemplate.php
@@ -453,7 +453,7 @@
454454 }
455455
456456 $tpl->set( 'reporttime', wfReportTime() );
457 - $tpl->set( 'sitenotice', wfGetSiteNotice() );
 457+ $tpl->set( 'sitenotice', $this->getSiteNotice() );
458458 $tpl->set( 'bottomscripts', $this->bottomScripts( $out ) );
459459
460460 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
Index: trunk/phase3/includes/Skin.php
@@ -1550,4 +1550,115 @@
15511551
15521552 return $ntl;
15531553 }
 1554+
 1555+ /**
 1556+ * Get a cached notice
 1557+ *
 1558+ * @param $name String: message name, or 'default' for $wgSiteNotice
 1559+ * @return String: HTML fragment
 1560+ */
 1561+ private function getCachedNotice( $name ) {
 1562+ global $wgOut, $wgRenderHashAppend, $parserMemc;
 1563+
 1564+ wfProfileIn( __METHOD__ );
 1565+
 1566+ $needParse = false;
 1567+
 1568+ if( $name === 'default' ) {
 1569+ // special case
 1570+ global $wgSiteNotice;
 1571+ $notice = $wgSiteNotice;
 1572+ if( empty( $notice ) ) {
 1573+ wfProfileOut( __METHOD__ );
 1574+ return false;
 1575+ }
 1576+ } else {
 1577+ $msg = wfMessage( $name )->inContentLanguage();
 1578+ if( $msg->isDisabled() ) {
 1579+ wfProfileOut( __METHOD__ );
 1580+ return false;
 1581+ }
 1582+ $notice = $msg->plain();
 1583+ }
 1584+
 1585+ // Use the extra hash appender to let eg SSL variants separately cache.
 1586+ $key = wfMemcKey( $name . $wgRenderHashAppend );
 1587+ $cachedNotice = $parserMemc->get( $key );
 1588+ if( is_array( $cachedNotice ) ) {
 1589+ if( md5( $notice ) == $cachedNotice['hash'] ) {
 1590+ $notice = $cachedNotice['html'];
 1591+ } else {
 1592+ $needParse = true;
 1593+ }
 1594+ } else {
 1595+ $needParse = true;
 1596+ }
 1597+
 1598+ if ( $needParse ) {
 1599+ if( is_object( $wgOut ) ) {
 1600+ $parsed = $wgOut->parse( $notice );
 1601+ $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
 1602+ $notice = $parsed;
 1603+ } else {
 1604+ wfDebug( 'wfGetCachedNotice called for ' . $name . ' with no $wgOut available' . "\n" );
 1605+ $notice = '';
 1606+ }
 1607+ }
 1608+
 1609+ $notice = '<div id="localNotice">' .$notice . '</div>';
 1610+ wfProfileOut( __METHOD__ );
 1611+ return $notice;
 1612+ }
 1613+
 1614+ /**
 1615+ * Get a notice based on page's namespace
 1616+ *
 1617+ * @return String: HTML fragment
 1618+ */
 1619+ function getNamespaceNotice() {
 1620+ wfProfileIn( __METHOD__ );
 1621+
 1622+ $key = 'namespacenotice-' . $this->mTitle->getNsText();
 1623+ $namespaceNotice = wfGetCachedNotice( $key );
 1624+ if ( $namespaceNotice && substr( $namespaceNotice, 0, 7 ) != '<p>&lt;' ) {
 1625+ $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . '</div>';
 1626+ } else {
 1627+ $namespaceNotice = '';
 1628+ }
 1629+
 1630+ wfProfileOut( $fname );
 1631+ return $namespaceNotice;
 1632+ }
 1633+
 1634+ /**
 1635+ * Get the site notice
 1636+ *
 1637+ * @return String: HTML fragment
 1638+ */
 1639+ function getSiteNotice() {
 1640+ global $wgUser;
 1641+
 1642+ wfProfileIn( __METHOD__ );
 1643+ $siteNotice = '';
 1644+
 1645+ if ( wfRunHooks( 'SiteNoticeBefore', array( &$siteNotice, $this ) ) ) {
 1646+ if ( is_object( $wgUser ) && $wgUser->isLoggedIn() ) {
 1647+ $siteNotice = $this->getCachedNotice( 'sitenotice' );
 1648+ } else {
 1649+ $anonNotice = $this->getCachedNotice( 'anonnotice' );
 1650+ if ( !$anonNotice ) {
 1651+ $siteNotice = $this->getCachedNotice( 'sitenotice' );
 1652+ } else {
 1653+ $siteNotice = $anonNotice;
 1654+ }
 1655+ }
 1656+ if ( !$siteNotice ) {
 1657+ $siteNotice = $this->getCachedNotice( 'default' );
 1658+ }
 1659+ }
 1660+
 1661+ wfRunHooks( 'SiteNoticeAfter', array( &$siteNotice, $this ) );
 1662+ wfProfileOut( __METHOD__ );
 1663+ return $siteNotice;
15541664 }
 1665+}

Follow-up revisions

RevisionCommit summaryAuthorDate
r83008Per Reedy, fix for r82034: forgot to change a wfGetCacheNotice() call (and al...ialex08:52, 1 March 2011

Comments

#Comment by Reedy (talk | contribs)   00:27, 27 February 2011

There still seems to be a call to wfGetCachedNotice() on line 1589 of Skin.php...

Status & tagging log