MediaWiki r12805 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r12804‎ | r12805 (on ViewVC)‎ | r12806 >
Date:16:23, 21 January 2006
Author:midom
Status:old
Tags:
Comment:
local cdb-based interwiki cache
Modified paths:

Diff [purge]

Index: trunk/phase3/includes/Title.php
===================================================================
--- trunk/phase3/includes/Title.php	(revision 12804)
+++ trunk/phase3/includes/Title.php	(revision 12805)
@@ -379,7 +379,7 @@
 	 * @access public
 	 */
 	function getInterwikiLink( $key )  {
-		global $wgMemc, $wgDBname, $wgInterwikiExpiry, $wgTitleInterwikiCache;
+		global $wgMemc, $wgDBname, $wgInterwikiExpiry, $wgInterwikiCache;
 		$fname = 'Title::getInterwikiLink';
 
 		wfProfileIn( $fname );
@@ -392,6 +392,11 @@
 			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,8 +428,51 @@
 		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.
 	 *
Index: trunk/phase3/includes/DefaultSettings.php
===================================================================
--- trunk/phase3/includes/DefaultSettings.php	(revision 12804)
+++ trunk/phase3/includes/DefaultSettings.php	(revision 12805)
@@ -639,6 +639,26 @@
 $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: trunk/phase3/RELEASE-NOTES
===================================================================
--- trunk/phase3/RELEASE-NOTES	(revision 12804)
+++ trunk/phase3/RELEASE-NOTES	(revision 12805)
@@ -550,6 +550,7 @@
   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 ===

Status & tagging log

  • 01:58, 13 October 2010 ^demon (Talk | contribs) changed the status of r12805 [removed: new added: old]
Personal tools
Namespaces
Variants
Views
Actions
Site
Support
Download
Development
Communication
Toolbox