Cleanup for r42022/r42023 interwiki stuff
authorBrion Vibber <brion@users.mediawiki.org>
Mon, 13 Oct 2008 18:43:55 +0000 (18:43 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Mon, 13 Oct 2008 18:43:55 +0000 (18:43 +0000)
* 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
includes/Title.php

index 33e69a1..5d27ff8 100644 (file)
@@ -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
         *
index 47e68b2..42fc685 100644 (file)
@@ -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 ) {