local cdb-based interwiki cache
authorDomas Mituzas <midom@users.mediawiki.org>
Sat, 21 Jan 2006 16:23:45 +0000 (16:23 +0000)
committerDomas Mituzas <midom@users.mediawiki.org>
Sat, 21 Jan 2006 16:23:45 +0000 (16:23 +0000)
RELEASE-NOTES
includes/DefaultSettings.php
includes/Title.php

index 3a2a5d8..2e87260 100644 (file)
@@ -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 ===
index 8c232d6..f4217b2 100644 (file)
@@ -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
index cfe4d7b..c921831 100644 (file)
@@ -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.