* Fix image redirect caching so it doesn't break image redirects on shared repositories
authorVictor Vasiliev <vasilievvv@users.mediawiki.org>
Sat, 10 May 2008 19:22:14 +0000 (19:22 +0000)
committerVictor Vasiliev <vasilievvv@users.mediawiki.org>
Sat, 10 May 2008 19:22:14 +0000 (19:22 +0000)
includes/Database.php
includes/GlobalFunctions.php
includes/filerepo/LocalFile.php
includes/filerepo/LocalRepo.php

index 001b044..9efc395 100644 (file)
@@ -226,6 +226,14 @@ class Database {
                return $this->$name;
        }
 
+       function getWikiID() {
+               if( $this->mTablePrefix ) {
+                       return "{$this->mDBname}-{$this->mTablePrefix}";
+               } else {
+                       return $this->mDBname;
+               }
+       }
+
 #------------------------------------------------------------------------------
 # Other functions
 #------------------------------------------------------------------------------
index e84e82c..8aac928 100644 (file)
@@ -2337,13 +2337,8 @@ function wfFormatStackFrame($frame) {
  * Get a cache key
  */
 function wfMemcKey( /*... */ ) {
-       global $wgDBprefix, $wgDBname;
        $args = func_get_args();
-       if ( $wgDBprefix ) {
-               $key = "$wgDBname-$wgDBprefix:" . implode( ':', $args );
-       } else {
-               $key = $wgDBname . ':' . implode( ':', $args );
-       }
+       $key = wfWikiID() . ':' . implode( ':', $args );
        return $key;
 }
 
@@ -2364,12 +2359,16 @@ function wfForeignMemcKey( $db, $prefix /*, ... */ ) {
  * Get an ASCII string identifying this wiki
  * This is used as a prefix in memcached keys
  */
-function wfWikiID() {
-       global $wgDBprefix, $wgDBname;
-       if ( $wgDBprefix ) {
-               return "$wgDBname-$wgDBprefix";
+function wfWikiID( $db = null ) {
+       if( $db instanceof Database ) {
+               return $db->getWikiID();
        } else {
-               return $wgDBname;
+       global $wgDBprefix, $wgDBname;
+               if ( $wgDBprefix ) {
+                       return "$wgDBname-$wgDBprefix";
+               } else {
+                       return $wgDBname;
+               }
        }
 }
 
index 29a6389..1f1c84d 100644 (file)
@@ -5,7 +5,7 @@
 /**
  * Bump this number when serialized cache records may be incompatible.
  */
-define( 'MW_FILE_VERSION', 7 );
+define( 'MW_FILE_VERSION', 8 );
 
 /**
  * Class to represent a local file in the wiki's own database
index 1e08268..e123a52 100644 (file)
@@ -15,6 +15,10 @@ class LocalRepo extends FSRepo {
                return wfGetDB( DB_MASTER );
        }
 
+       function getMemcKey( $key ) {
+               return wfWikiID( $this->getSlaveDB() ) . ":{$key}";
+       }
+
        function newFileFromRow( $row ) {
                if ( isset( $row->img_name ) ) {
                        return LocalFile::newFromRow( $row, $this );
@@ -104,7 +108,7 @@ class LocalRepo extends FSRepo {
                        $title = Title::makeTitle( NS_IMAGE, $title->getText() );
                }
 
-               $memcKey = wfMemcKey( "image_redirect:" . md5( $title->getPrefixedDBkey() ) );
+               $memcKey = $this->getMemcKey( "image_redirect:" . md5( $title->getPrefixedDBkey() ) );
                $cachedValue = $wgMemc->get( $memcKey );
                if( $cachedValue ) {
                        return Title::newFromDbKey( $cachedValue );
@@ -135,7 +139,7 @@ class LocalRepo extends FSRepo {
 
        function invalidateImageRedirect( $title ) {
                global $wgMemc;
-               $memcKey = wfMemcKey( "image_redirect:" . md5( $title->getPrefixedDBkey() ) );
+               $memcKey = $this->getMemcKey( "image_redirect:" . md5( $title->getPrefixedDBkey() ) );
                $wgMemc->delete( $memcKey );
        }
 }