$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
* @access public
*/
function getInterwikiLink( $key ) {
- global $wgMemc, $wgDBname, $wgInterwikiExpiry, $wgTitleInterwikiCache;
+ global $wgMemc, $wgDBname, $wgInterwikiExpiry, $wgInterwikiCache;
$fname = 'Title::getInterwikiLink';
wfProfileIn( $fname );
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)) {
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.