From 6effda76b55887762b2268562e3eca3787dcdc7f Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 13 Oct 2008 18:43:55 +0000 Subject: [PATCH] Cleanup for r42022/r42023 interwiki stuff * Remove duplicate code in Interwiki::isValidInterwiki(), which should help avoid future drift between the two copies * Early return on prefix = '', we know it won't be valid :) * Dump extra isValidInterwikiCached function -- just go through the regular fetch() path, it doesn't do much more processing. * Simplify Title codepath in full URL generation to ensure we never call an invalid object --- includes/Interwiki.php | 37 +++++-------------------------------- includes/Title.php | 5 +++-- 2 files changed, 8 insertions(+), 34 deletions(-) diff --git a/includes/Interwiki.php b/includes/Interwiki.php index 33e69a189e..5d27ff8a6c 100644 --- a/includes/Interwiki.php +++ b/includes/Interwiki.php @@ -32,25 +32,8 @@ class Interwiki { * @param $prefix string Interwiki prefix to use */ static public function isValidInterwiki( $prefix ){ - global $wgContLang; - $prefix = $wgContLang->lc( $prefix ); - if( isset( self::$smCache[$prefix] ) ){ - return true; - } - global $wgInterwikiCache; - if ($wgInterwikiCache) { - return Interwiki::isValidInterwikiCached( $key ); - } - $iw = Interwiki::load( $prefix ); - if( !$iw ){ - $iw = false; - } - if( self::CACHE_LIMIT && count( self::$smCache ) >= self::CACHE_LIMIT ){ - reset( self::$smCache ); - unset( self::$smCache[ key( self::$smCache ) ] ); - } - self::$smCache[$prefix] = $iw; - return ($iw != false); + $result = self::fetch( $prefix ); + return (bool)$result; } /** @@ -61,6 +44,9 @@ class Interwiki { */ static public function fetch( $prefix ) { global $wgContLang; + if( $prefix == '' ) { + return null; + } $prefix = $wgContLang->lc( $prefix ); if( isset( self::$smCache[$prefix] ) ){ return self::$smCache[$prefix]; @@ -109,19 +95,6 @@ class Interwiki { return $s; } - /** - * Check whether an interwiki is in the cache - * - * @note More logic is explained in DefaultSettings. - * - * @param $key \type{\string} Database key - * @return \type{\bool} Whether it exists - */ - protected static function isValidInterwikiCached( $key ) { - $value = getInterwikiCacheEntry( $key ); - return $value != ''; - } - /** * Get entry from interwiki cache * diff --git a/includes/Title.php b/includes/Title.php index 47e68b21bb..42fc685c80 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -675,7 +675,8 @@ class Title { $query = wfArrayToCGI( $query ); } - if ( '' == $this->mInterwiki || !Interwiki::isValidInterwiki( $this->mInterwiki ) ) { + $interwiki = Interwiki::fetch( $this->mInterwiki ); + if ( !$interwiki ) { $url = $this->getLocalUrl( $query, $variant ); // Ugly quick hack to avoid duplicate prefixes (bug 4571 etc) @@ -684,7 +685,7 @@ class Title { $url = $wgServer . $url; } } else { - $baseUrl = Interwiki::fetch( $this->mInterwiki )->getURL( ); + $baseUrl = $interwiki->getURL( ); $namespace = wfUrlencode( $this->getNsText() ); if ( '' != $namespace ) { -- 2.20.1