From e7404af422901822a4a6f78e02d184564989ab16 Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Tue, 26 Nov 2013 13:20:30 -0800 Subject: [PATCH] Improved CdbException handling in Interwiki Change-Id: I6461b64dc77b3ecc641db39da1e9be306100fda3 --- includes/interwiki/Interwiki.php | 130 +++++++++++++++++-------------- 1 file changed, 70 insertions(+), 60 deletions(-) diff --git a/includes/interwiki/Interwiki.php b/includes/interwiki/Interwiki.php index 4003fa885f..3c237bff11 100644 --- a/includes/interwiki/Interwiki.php +++ b/includes/interwiki/Interwiki.php @@ -123,28 +123,34 @@ class Interwiki { static $db, $site; wfDebug( __METHOD__ . "( $prefix )\n" ); - if ( !$db ) { - $db = CdbReader::open( $wgInterwikiCache ); - } - /* Resolve site name */ - if ( $wgInterwikiScopes >= 3 && !$site ) { - $site = $db->get( '__sites:' . wfWikiID() ); - if ( $site == '' ) { - $site = $wgInterwikiFallbackSite; + $value = false; + try { + if ( !$db ) { + $db = CdbReader::open( $wgInterwikiCache ); + } + /* Resolve site name */ + if ( $wgInterwikiScopes >= 3 && !$site ) { + $site = $db->get( '__sites:' . wfWikiID() ); + if ( $site == '' ) { + $site = $wgInterwikiFallbackSite; + } } - } - $value = $db->get( wfMemcKey( $prefix ) ); - // Site level - if ( $value == '' && $wgInterwikiScopes >= 3 ) { - $value = $db->get( "_{$site}:{$prefix}" ); - } - // Global Level - if ( $value == '' && $wgInterwikiScopes >= 2 ) { - $value = $db->get( "__global:{$prefix}" ); - } - if ( $value == 'undef' ) { - $value = ''; + $value = $db->get( wfMemcKey( $prefix ) ); + // Site level + if ( $value == '' && $wgInterwikiScopes >= 3 ) { + $value = $db->get( "_{$site}:{$prefix}" ); + } + // Global Level + if ( $value == '' && $wgInterwikiScopes >= 2 ) { + $value = $db->get( "__global:{$prefix}" ); + } + if ( $value == 'undef' ) { + $value = ''; + } + } catch ( CdbException $e ) { + wfDebug( __METHOD__ . ": CdbException caught, error message was " + . $e->getMessage() ); } return $value; @@ -232,51 +238,55 @@ class Interwiki { static $db, $site; wfDebug( __METHOD__ . "()\n" ); - if ( !$db ) { - $db = CdbReader::open( $wgInterwikiCache ); - } - /* Resolve site name */ - if ( $wgInterwikiScopes >= 3 && !$site ) { - $site = $db->get( '__sites:' . wfWikiID() ); - if ( $site == '' ) { - $site = $wgInterwikiFallbackSite; - } - } - - // List of interwiki sources - $sources = array(); - // Global Level - if ( $wgInterwikiScopes >= 2 ) { - $sources[] = '__global'; - } - // Site level - if ( $wgInterwikiScopes >= 3 ) { - $sources[] = '_' . $site; - } - $sources[] = wfWikiID(); - $data = array(); - - foreach ( $sources as $source ) { - $list = $db->get( "__list:{$source}" ); - foreach ( explode( ' ', $list ) as $iw_prefix ) { - $row = $db->get( "{$source}:{$iw_prefix}" ); - if ( !$row ) { - continue; + try { + if ( !$db ) { + $db = CdbReader::open( $wgInterwikiCache ); + } + /* Resolve site name */ + if ( $wgInterwikiScopes >= 3 && !$site ) { + $site = $db->get( '__sites:' . wfWikiID() ); + if ( $site == '' ) { + $site = $wgInterwikiFallbackSite; } + } - list( $iw_local, $iw_url ) = explode( ' ', $row ); - - if ( $local !== null && $local != $iw_local ) { - continue; + // List of interwiki sources + $sources = array(); + // Global Level + if ( $wgInterwikiScopes >= 2 ) { + $sources[] = '__global'; + } + // Site level + if ( $wgInterwikiScopes >= 3 ) { + $sources[] = '_' . $site; + } + $sources[] = wfWikiID(); + + foreach ( $sources as $source ) { + $list = $db->get( "__list:{$source}" ); + foreach ( explode( ' ', $list ) as $iw_prefix ) { + $row = $db->get( "{$source}:{$iw_prefix}" ); + if ( !$row ) { + continue; + } + + list( $iw_local, $iw_url ) = explode( ' ', $row ); + + if ( $local !== null && $local != $iw_local ) { + continue; + } + + $data[$iw_prefix] = array( + 'iw_prefix' => $iw_prefix, + 'iw_url' => $iw_url, + 'iw_local' => $iw_local, + ); } - - $data[$iw_prefix] = array( - 'iw_prefix' => $iw_prefix, - 'iw_url' => $iw_url, - 'iw_local' => $iw_local, - ); } + } catch ( CdbException $e ) { + wfDebug( __METHOD__ . ": CdbException caught, error message was " + . $e->getMessage() ); } ksort( $data ); -- 2.20.1