*/
/**
- *$wgInterwikiCache specifies path to constant database file.
+ * Interwiki cache, either as an associative array or a path to a constant
+ * database (.cdb) file.
+ *
+ * This data structure database is generated by the `dumpInterwiki` maintenance
+ * script (which lives in the WikimediaMaintenance repository) and has key
+ * formats such as the following:
*
- * This cdb database is generated by dumpInterwiki from maintenance and has
- * such key formats:
* - dbname:key - a simple key (e.g. enwiki:meta)
* - _sitename:key - site-scope key (e.g. wiktionary:meta)
* - __global:key - global-scope key (e.g. __global:meta)
*
* Sites mapping just specifies site name, other keys provide "local url"
* data layout.
+ *
+ * @var bool|array|string
*/
$wgInterwikiCache = false;
$value = self::getInterwikiCacheEntry( $prefix );
$s = new Interwiki( $prefix );
- if ( $value != '' ) {
+ if ( $value ) {
// Split values
list( $local, $url ) = explode( ' ', $value, 2 );
$s->mURL = $url;
* @note More logic is explained in DefaultSettings.
*
* @param string $prefix Database key
- * @return string The interwiki entry
+ * @return bool|string The interwiki entry or false if not found
*/
protected static function getInterwikiCacheEntry( $prefix ) {
- global $wgInterwikiCache, $wgInterwikiScopes, $wgInterwikiFallbackSite;
- static $db, $site;
+ global $wgInterwikiScopes, $wgInterwikiFallbackSite;
+ static $site;
wfDebug( __METHOD__ . "( $prefix )\n" );
$value = false;
try {
- if ( !$db ) {
- $db = CdbReader::open( $wgInterwikiCache );
- }
- /* Resolve site name */
+ // Resolve site name
if ( $wgInterwikiScopes >= 3 && !$site ) {
- $site = $db->get( '__sites:' . wfWikiID() );
+ $site = self::getCacheValue( '__sites:' . wfWikiID() );
if ( $site == '' ) {
$site = $wgInterwikiFallbackSite;
}
}
- $value = $db->get( wfMemcKey( $prefix ) );
+ $value = self::getCacheValue( wfMemcKey( $prefix ) );
// Site level
if ( $value == '' && $wgInterwikiScopes >= 3 ) {
- $value = $db->get( "_{$site}:{$prefix}" );
+ $value = self::getCacheValue( "_{$site}:{$prefix}" );
}
// Global Level
if ( $value == '' && $wgInterwikiScopes >= 2 ) {
- $value = $db->get( "__global:{$prefix}" );
+ $value = self::getCacheValue( "__global:{$prefix}" );
}
if ( $value == 'undef' ) {
$value = '';
return $value;
}
+ private static function getCacheValue( $key ) {
+ global $wgInterwikiCache;
+ static $reader;
+ if ( $reader === null ) {
+ $reader = is_array( $wgInterwikiCache ) ? false : CdbReader::open( $wgInterwikiCache );
+ }
+ if ( $reader ) {
+ return $reader->get( $key );
+ } else {
+ return isset( $wgInterwikiCache[$key] ) ? $wgInterwikiCache[$key] : false;
+ }
+ }
+
/**
* Load the interwiki, trying first memcached then the DB
*