From ea56a5acffcffeaa6f9bc1807299e83511b9db08 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sat, 27 Nov 2004 13:40:58 +0000 Subject: [PATCH] Have the skin cache the highlightbroken and hover options to avoid asking the user object on every link format. This can save a chunk of time on pages with obscenely many links (~50ms on my test box with [[List of Royal Navy ship names]]) --- includes/Skin.php | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/includes/Skin.php b/includes/Skin.php index 7c067730ad..186a883d36 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -84,6 +84,13 @@ class Skin { function Skin() { $this->linktrail = wfMsgForContent('linktrail'); + + # Cache option lookups done very frequently + $options = array( 'highlightbroken', 'hover' ); + foreach( $options as $opt ) { + global $wgUser; + $this->mOptions[$opt] = $wgUser->getOption( $opt ); + } } function getSkinNames() { @@ -255,7 +262,7 @@ class Skin { # Force no underline $s .= "a { text-decoration: none; }\n"; } - if ( 1 == $wgUser->getOption( 'highlightbroken' ) ) { + if ( 1 == $this->mOptions['highlightbroken'] ) { $s .= "a.new, #quickbar a.new { color: #CC2200; }\n"; } if ( 1 == $wgUser->getOption( 'justify' ) ) { @@ -293,7 +300,7 @@ class Skin { } function getExternalLinkAttributes( $link, $text, $class='' ) { - global $wgUser, $wgOut, $wgContLang; + global $wgContLang; $same = ($link == $text); $link = urldecode( $link ); @@ -303,20 +310,18 @@ class Skin { $r = ($class != '') ? " class='$class'" : " class='external'"; - if ( !$same && $wgUser->getOption( 'hover' ) ) { + if( !$same && $this->mOptions['hover'] ) { $r .= " title=\"{$link}\""; } return $r; } function getInternalLinkAttributes( $link, $text, $broken = false ) { - global $wgUser, $wgOut; - $link = urldecode( $link ); $link = str_replace( '_', ' ', $link ); $link = htmlspecialchars( $link ); - if ( $broken == 'stub' ) { + if( $broken == 'stub' ) { $r = ' class="stub"'; } else if ( $broken == 'yes' ) { $r = ' class="new"'; @@ -324,7 +329,7 @@ class Skin { $r = ''; } - if ( 1 == $wgUser->getOption( 'hover' ) ) { + if( $this->mOptions['hover'] ) { $r .= " title=\"{$link}\""; } return $r; @@ -334,9 +339,7 @@ class Skin { * @param bool $broken */ function getInternalLinkAttributesObj( &$nt, $text, $broken = false ) { - global $wgUser, $wgOut; - - if ( $broken == 'stub' ) { + if( $broken == 'stub' ) { $r = ' class="stub"'; } else if ( $broken == 'yes' ) { $r = ' class="new"'; @@ -344,7 +347,7 @@ class Skin { $r = ''; } - if ( 1 == $wgUser->getOption( 'hover' ) ) { + if( $this->mOptions['hover'] ) { $r .= ' title="' . $nt->getEscapedText() . '"'; } return $r; @@ -1468,8 +1471,6 @@ class Skin { * Pass a title object, not a title string */ function makeBrokenLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) { - global $wgOut, $wgUser; - # Fail gracefully if ( ! isset($nt) ) { # wfDebugDieBacktrace(); @@ -1498,7 +1499,7 @@ class Skin { $trail = $m[2]; } } - if ( $wgUser->getOption( 'highlightbroken' ) ) { + if ( $this->mOptions['highlightbroken'] ) { $s = "{$prefix}{$text}{$inside}{$trail}"; } else { $s = "{$prefix}{$text}{$inside}?{$trail}"; @@ -1512,8 +1513,6 @@ class Skin { * Pass a title object, not a title string */ function makeStubLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) { - global $wgOut, $wgUser; - $link = $nt->getPrefixedURL(); $u = $nt->escapeLocalURL( $query ); @@ -1530,7 +1529,7 @@ class Skin { $trail = $m[2]; } } - if ( $wgUser->getOption( 'highlightbroken' ) ) { + if ( $this->mOptions['highlightbroken'] ) { $s = "{$prefix}{$text}{$inside}{$trail}"; } else { $s = "{$prefix}{$text}{$inside}!{$trail}"; -- 2.20.1