From ba9ae792125f3e5dc4add3a3dbf1bf08f8e0553a Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Sun, 27 Mar 2005 16:56:11 +0000 Subject: [PATCH] Fixed efficiency problem with $wgSiteNotice. Introduced wfSiteNotice(), which allows the script to load it on demand instead of on every invocation --- includes/Database.php | 4 ++-- includes/GlobalFunctions.php | 33 +++++++++++++++++++++++++++++++++ includes/Setup.php | 23 ----------------------- includes/Skin.php | 7 ++++--- includes/SkinTemplate.php | 5 ++--- skins/CologneBlue.php | 7 ++++--- skins/Nostalgia.php | 8 +++++--- 7 files changed, 50 insertions(+), 37 deletions(-) diff --git a/includes/Database.php b/includes/Database.php index a43f5b0a12..9eb8ab3ed4 100644 --- a/includes/Database.php +++ b/includes/Database.php @@ -1459,7 +1459,7 @@ class ResultWrapper { * Displays the file cache if possible */ function wfEmergencyAbort( &$conn, $error ) { - global $wgTitle, $wgUseFileCache, $title, $wgInputEncoding, $wgSiteNotice, $wgOutputEncoding; + global $wgTitle, $wgUseFileCache, $title, $wgInputEncoding, $wgOutputEncoding; global $wgSitename, $wgServer; # I give up, Brion is right. Getting the message cache to work when there is no DB is tricky. @@ -1502,7 +1502,7 @@ border=\"0\" ALT=\"Google\"> header( 'Cache-control: none' ); header( 'Pragma: nocache' ); } - $msg = $wgSiteNotice; + $msg = wfGetSiteNotice(); if($msg == '') { $msg = str_replace( '$1', $error, $noconnect ); } diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index ea209c92eb..c758cc803c 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -1051,4 +1051,37 @@ function wfIsWindows() { } } +/** + * Swap two variables + */ +function swap( &$x, &$y ) { + $z = $x; + $x = $y; + $y = $z; +} + +function wfGetSiteNotice() { + global $wgSiteNotice; + $fname = 'wfGetSiteNotice'; + wfProfileIn( $fname ); + + $notice = wfMsg( 'sitenotice' ); + if($notice == '<sitenotice>') $notice = ''; + # Allow individual wikis to turn it off + if ( $notice == '-' ) { + $notice = ''; + } else { + if ($notice == '') { + $notice = $wgSiteNotice; + } + if($notice != '-' && $notice != '') { + $specialparser = new Parser(); + $parserOutput = $specialparser->parse( $notice, $wgTitle, $wgOut->mParserOptions, false ); + $notice = $parserOutput->getText(); + } + } + wfProfileOut( $fname ); + return $notice; +} + ?> diff --git a/includes/Setup.php b/includes/Setup.php index a43cfc3263..c615667358 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -384,29 +384,6 @@ wfSeedRandom(); $wgTitle = Title::makeTitle( NS_SPECIAL, 'Error' ); $wgArticle = new Article($wgTitle); -# Site notice -# FIXME: This is an ugly hack, which wastes runtime on cache hits -# and raw page views by forcing initialization of the message cache. -# Try to fake around it for raw at least: -if( !isset( $_REQUEST['action'] ) || $_REQUEST['action'] != 'raw' ) { - $notice = wfMsg( 'sitenotice' ); - if($notice == '<sitenotice>') $notice = ''; - # Allow individual wikis to turn it off - if ( $notice == '-' ) { - $wgSiteNotice = ''; - } else { - # if($wgSiteNotice) $notice .= $wgSiteNotice; - if ($notice == '') { - $notice = $wgSiteNotice; - } - if($notice != '-' && $notice != '') { - $specialparser = new Parser(); - $parserOutput = $specialparser->parse( $notice, $wgTitle, $wgOut->mParserOptions, false ); - $wgSiteNotice = $parserOutput->getText(); - } - } -} - wfProfileOut( $fname.'-misc2' ); wfProfileIn( $fname.'-extensions' ); diff --git a/includes/Skin.php b/includes/Skin.php index de7777d919..daf3ba4248 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -356,7 +356,7 @@ END; } function doBeforeContent() { - global $wgOut, $wgTitle, $wgContLang, $wgSiteNotice; + global $wgOut, $wgTitle, $wgContLang; $fname = 'Skin::doBeforeContent'; wfProfileIn( $fname ); @@ -406,8 +406,9 @@ END; $s .= "\n\n\n"; $s .= "\n
\n"; - if( $wgSiteNotice ) { - $s .= "\n
$wgSiteNotice
\n"; + $notice = wfGetSiteNotice(); + if( $notice ) { + $s .= "\n
$notice
\n"; } $s .= $this->pageTitle(); $s .= $this->pageSubtitle() ; diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index 84ada028fb..87c8135b08 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -146,7 +146,7 @@ class SkinTemplate extends Skin { global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut; global $wgScript, $wgStylePath, $wgLanguageCode, $wgContLanguageCode, $wgUseNewInterlanguage; global $wgMimeType, $wgOutputEncoding, $wgUseDatabaseMessages, $wgRequest; - global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgSiteNotice; + global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses; global $wgMaxCredits, $wgShowCreditsIfMax; global $wgPageShowWatchingUsers; @@ -344,8 +344,7 @@ class SkinTemplate extends Skin { $tpl->setRef( 'debug', $out->mDebugtext ); $tpl->set( 'reporttime', $out->reportTime() ); - $tpl->set( 'sitenotice', $wgSiteNotice ); - $tpl->set( 'tagline', wfMsg('tagline') ); + $tpl->set( 'sitenotice', wfGetSiteNotice() ); $printfooter = "
\n" . $this->printSource() . "
\n"; $out->mBodytext .= $printfooter ; diff --git a/skins/CologneBlue.php b/skins/CologneBlue.php index 06e5d46612..8571b4beed 100644 --- a/skins/CologneBlue.php +++ b/skins/CologneBlue.php @@ -25,7 +25,7 @@ class SkinCologneBlue extends Skin { } function doBeforeContent() { - global $wgOut, $wgTitle, $wgSiteNotice; + global $wgOut, $wgTitle; $s = ""; $qb = $this->qbSetting(); @@ -57,8 +57,9 @@ class SkinCologneBlue extends Skin { $s .= "\n
\n
"; - if( $wgSiteNotice ) { - $s .= "\n
$wgSiteNotice
\n"; + $notice = wfGetSiteNotice(); + if( $notice ) { + $s .= "\n
$notice
\n"; } $s .= $this->pageTitle(); $s .= $this->pageSubtitle() . "\n"; diff --git a/skins/Nostalgia.php b/skins/Nostalgia.php index 02b5d8b2c1..4bf4bf6bde 100644 --- a/skins/Nostalgia.php +++ b/skins/Nostalgia.php @@ -29,7 +29,7 @@ class SkinNostalgia extends Skin { } function doBeforeContent() { - global $wgUser, $wgOut, $wgTitle, $wgSiteNotice; + global $wgUser, $wgOut, $wgTitle; $s = "\n
\n
"; $s .= $this->logoText( "right" ); @@ -38,8 +38,10 @@ class SkinNostalgia extends Skin { $s .= $this->pageSubtitle() . "\n"; $s .= $this->topLinks() . "\n
"; - if( $wgSiteNotice ) { - $s .= "\n
$wgSiteNotice
\n"; + + $notice = wfGetSiteNotice(); + if( $notice ) { + $s .= "\n
$notice
\n"; } $s .= $this->pageTitleLinks(); -- 2.20.1