From 033896c0f90c1227e93770642290c92da951a672 Mon Sep 17 00:00:00 2001 From: Domas Mituzas Date: Sat, 21 Jan 2006 16:23:45 +0000 Subject: [PATCH] local cdb-based interwiki cache --- RELEASE-NOTES | 1 + includes/DefaultSettings.php | 20 ++++++++++++++ includes/Title.php | 52 ++++++++++++++++++++++++++++++++++-- 3 files changed, 71 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 3a2a5d847c..2e87260e62 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -550,6 +550,7 @@ fully support the editing toolbar, but was found to be too confusing. wfBaseName() doesn't suffer this bug, and understands backslash on both Unix and Windows. * (bug 3603) headscripts variable not hooked up to MonoBook skin +* Allow local cdb-based interwiki cache === Caveats === diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 8c232d6a40..f4217b2907 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -639,6 +639,26 @@ $wgMetaNamespaceTalk = false; $wgLocalInterwiki = 'w'; $wgInterwikiExpiry = 10800; # Expiry time for cache of interwiki table +/** Interwiki caching settings. + $wgInterwikiCache specifies path to constant database file + 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:dbname - site mapping (e.g. __sites:enwiki) + Sites mapping just specifies site name, other keys provide + "local url" data layout. + $wgInterwikiScopes specify number of domains to check for messages: + 1 - Just wiki(db)-level + 2 - wiki and global levels + 3 - site levels + $wgInterwikiFallbackSite - if unable to resolve from cache +*/ +$wgInterwikiCache = false; +$wgInterwikiScopes = 3; +$wgInterwikiFallbackSite = 'wiki'; + /** * If local interwikis are set up which allow redirects, * set this regexp to restrict URLs which will be displayed diff --git a/includes/Title.php b/includes/Title.php index cfe4d7b32a..c921831147 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -379,7 +379,7 @@ class Title { * @access public */ function getInterwikiLink( $key ) { - global $wgMemc, $wgDBname, $wgInterwikiExpiry, $wgTitleInterwikiCache; + global $wgMemc, $wgDBname, $wgInterwikiExpiry, $wgInterwikiCache; $fname = 'Title::getInterwikiLink'; wfProfileIn( $fname ); @@ -392,6 +392,11 @@ class Title { return $wgTitleInterwikiCache[$k]->iw_url; } + if ($wgInterwikiCache) { + wfProfileOut( $fname ); + return getInterwikiCached( $key ); + } + $s = $wgMemc->get( $k ); # Ignore old keys with no iw_local if( $s && isset( $s->iw_local ) && isset($s->iw_trans)) { @@ -423,7 +428,50 @@ class Title { wfProfileOut( $fname ); return $s->iw_url; } - + + /** + * Fetch interwiki prefix data from local cache in constant database + * + * More logic is explained in DefaultSettings + * + * @return string URL of interwiki site + * @access public + */ + function getInterwikiCached( $key ) { + global $wgDBname, $wgInterwikiCache, $wgInterwikiScopes, $wgInterwikiFallbackSite; + global $wgTitleInterwikiCache; + static $db, $site; + if (!db) + $db=dba_open($wgInterwikiCache,'r','cdb'); + /* Resolve site name */ + if ($wgInterwikiScopes>=3 and !$site) { + $site = dba_fetch("__sites:{$wgDBname}", $db); + if ($site=="") + $site = $wgInterwikiFallbackSite; + } + $value = dba_fetch("{$wgDBname}:{$key}", $db); + if ($value=='' and $wgInterwikiScopes>=3) { + /* try site-level */ + $value = dba_fetch("_{$site}:{$key}", $db); + } + if ($value=='' and $wgInterwikiScopes>=2) { + /* try globals */ + $value = dba_fetch("__globals:{$key}", $db); + } + if ($value=='undef') + $value=''; + $s = (object)false; + $s->iw_url = ''; + $s->iw_local = 0; + $s->iw_trans = 0; + if ($value!='') { + list($local,$url)=explode(' ',$value,2); + $s->iw_url=$url; + $s->iw_local=$local; + } + $wgTitleInterwikiCache[$wgDBname.':interwiki:'.$key] = $s; + return $s->iw_url; + } /** * Determine whether the object refers to a page within * this project. -- 2.20.1