Index: trunk/phase3/skins/CologneBlue.php |
— | — | @@ -86,7 +86,7 @@ |
87 | 87 | |
88 | 88 | $s .= "\n</div>\n<div id='article'>"; |
89 | 89 | |
90 | | - $notice = wfGetSiteNotice(); |
| 90 | + $notice = $this->getSkin()->getSiteNotice(); |
91 | 91 | if( $notice ) { |
92 | 92 | $s .= "\n<div id='siteNotice'>$notice</div>\n"; |
93 | 93 | } |
Index: trunk/phase3/skins/Nostalgia.php |
— | — | @@ -37,7 +37,7 @@ |
38 | 38 | $s .= '<div id="topbar">'; |
39 | 39 | $s .= $this->topLinks() . "\n<br />"; |
40 | 40 | |
41 | | - $notice = wfGetSiteNotice(); |
| 41 | + $notice = $this->getSkin()->getSiteNotice(); |
42 | 42 | if( $notice ) { |
43 | 43 | $s .= "\n<div id='siteNotice'>$notice</div>\n"; |
44 | 44 | } |
Index: trunk/phase3/docs/hooks.txt |
— | — | @@ -1459,11 +1459,13 @@ |
1460 | 1460 | |
1461 | 1461 | 'SiteNoticeBefore': Before the sitenotice/anonnotice is composed |
1462 | 1462 | &$siteNotice: HTML returned as the sitenotice |
| 1463 | +$skin: Skin object |
1463 | 1464 | Return true to allow the normal method of notice selection/rendering to work, |
1464 | 1465 | or change the value of $siteNotice and return false to alter it. |
1465 | 1466 | |
1466 | 1467 | 'SiteNoticeAfter': After the sitenotice/anonnotice is composed |
1467 | 1468 | &$siteNotice: HTML sitenotice |
| 1469 | +$skin: Skin object |
1468 | 1470 | Alter the contents of $siteNotice to add to/alter the sitenotice/anonnotice. |
1469 | 1471 | |
1470 | 1472 | 'SkinAfterBottomScripts': At the end of Skin::bottomScripts() |
Index: trunk/phase3/includes/GlobalFunctions.php |
— | — | @@ -1996,108 +1996,6 @@ |
1997 | 1997 | $y = $z; |
1998 | 1998 | } |
1999 | 1999 | |
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><' ) { |
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 | | - |
2102 | 2000 | /** |
2103 | 2001 | * BC wrapper for MimeMagic::singleton() |
2104 | 2002 | * @deprecated No longer needed as of 1.17 (r68836). Remove in 1.19. |
Index: trunk/phase3/includes/SkinLegacy.php |
— | — | @@ -134,7 +134,7 @@ |
135 | 135 | $s .= "</tr>\n</table>\n</div>\n"; |
136 | 136 | $s .= "\n<div id='article'>\n"; |
137 | 137 | |
138 | | - $notice = wfGetSiteNotice(); |
| 138 | + $notice = $this->getSkin()->getSiteNotice(); |
139 | 139 | |
140 | 140 | if ( $notice ) { |
141 | 141 | $s .= "\n<div id='siteNotice'>$notice</div>\n"; |
Index: trunk/phase3/includes/SkinTemplate.php |
— | — | @@ -453,7 +453,7 @@ |
454 | 454 | } |
455 | 455 | |
456 | 456 | $tpl->set( 'reporttime', wfReportTime() ); |
457 | | - $tpl->set( 'sitenotice', wfGetSiteNotice() ); |
| 457 | + $tpl->set( 'sitenotice', $this->getSiteNotice() ); |
458 | 458 | $tpl->set( 'bottomscripts', $this->bottomScripts( $out ) ); |
459 | 459 | |
460 | 460 | $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n"; |
Index: trunk/phase3/includes/Skin.php |
— | — | @@ -1550,4 +1550,115 @@ |
1551 | 1551 | |
1552 | 1552 | return $ntl; |
1553 | 1553 | } |
| 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><' ) { |
| 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; |
1554 | 1664 | } |
| 1665 | +} |