r42530 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r42529‎ | r42530 | r42531 >
Date:05:45, 25 October 2008
Author:tstarling
Status:old
Tags:
Comment:
Fixed totally broken and obviously untested Interwiki::getInterwikiCached().
Modified paths:
  • /trunk/phase3/includes/Interwiki.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Interwiki.php
@@ -53,12 +53,13 @@
5454 }
5555 global $wgInterwikiCache;
5656 if ($wgInterwikiCache) {
57 - return Interwiki::getInterwikiCached( $key );
 57+ $iw = Interwiki::getInterwikiCached( $prefix );
 58+ } else {
 59+ $iw = Interwiki::load( $prefix );
 60+ if( !$iw ){
 61+ $iw = false;
 62+ }
5863 }
59 - $iw = Interwiki::load( $prefix );
60 - if( !$iw ){
61 - $iw = false;
62 - }
6364 if( self::CACHE_LIMIT && count( self::$smCache ) >= self::CACHE_LIMIT ){
6465 reset( self::$smCache );
6566 unset( self::$smCache[ key( self::$smCache ) ] );
@@ -72,13 +73,13 @@
7374 *
7475 * @note More logic is explained in DefaultSettings.
7576 *
76 - * @param $key \type{\string} Database key
 77+ * @param $prefix \type{\string} Interwiki prefix
7778 * @return \type{\Interwiki} An interwiki object
7879 */
79 - protected static function getInterwikiCached( $key ) {
80 - $value = self::getInterwikiCacheEntry( $key );
 80+ protected static function getInterwikiCached( $prefix ) {
 81+ $value = self::getInterwikiCacheEntry( $prefix );
8182
82 - $s = new Interwiki( $key );
 83+ $s = new Interwiki( $prefix );
8384 if ( $value != '' ) {
8485 // Split values
8586 list( $local, $url ) = explode( ' ', $value, 2 );
@@ -87,11 +88,6 @@
8889 }else{
8990 $s = false;
9091 }
91 - if( self::CACHE_LIMIT && count( self::$smCache ) >= self::CACHE_LIMIT ){
92 - reset( self::$smCache );
93 - unset( self::$smCache[ key( self::$smCache ) ] );
94 - }
95 - self::$smCache[$prefix] = $s;
9692 return $s;
9793 }
9894
@@ -100,13 +96,14 @@
10197 *
10298 * @note More logic is explained in DefaultSettings.
10399 *
104 - * @param $key \type{\string} Database key
 100+ * @param $prefix \type{\string} Database key
105101 * @return \type{\string) The entry
106102 */
107 - protected static function getInterwikiCacheEntry( $key ){
 103+ protected static function getInterwikiCacheEntry( $prefix ){
108104 global $wgInterwikiCache, $wgInterwikiScopes, $wgInterwikiFallbackSite;
109105 static $db, $site;
110106
 107+ wfDebug( __METHOD__ . "( $prefix )\n" );
111108 if( !$db ){
112109 $db = dba_open( $wgInterwikiCache, 'r', 'cdb' );
113110 }
@@ -118,14 +115,14 @@
119116 }
120117 }
121118
122 - $value = dba_fetch( wfMemcKey( $key ), $db );
 119+ $value = dba_fetch( wfMemcKey( $prefix ), $db );
123120 // Site level
124121 if ( $value == '' && $wgInterwikiScopes >= 3 ) {
125 - $value = dba_fetch( "_{$site}:{$key}", $db );
 122+ $value = dba_fetch( "_{$site}:{$prefix}", $db );
126123 }
127124 // Global Level
128125 if ( $value == '' && $wgInterwikiScopes >= 2 ) {
129 - $value = dba_fetch( "__global:{$key}", $db );
 126+ $value = dba_fetch( "__global:{$prefix}", $db );
130127 }
131128 if ( $value == 'undef' )
132129 $value = '';

Status & tagging log