* Cache image redirects (and enable them)
authorVictor Vasiliev <vasilievvv@users.mediawiki.org>
Sat, 12 Apr 2008 18:04:46 +0000 (18:04 +0000)
committerVictor Vasiliev <vasilievvv@users.mediawiki.org>
Sat, 12 Apr 2008 18:04:46 +0000 (18:04 +0000)
includes/Article.php
includes/DefaultSettings.php
includes/filerepo/FileRepo.php
includes/filerepo/LocalRepo.php

index dbb668a..f49c1c4 100644 (file)
@@ -1160,6 +1160,8 @@ class Article {
                                $dbw->delete( 'redirect', $where, __METHOD__);
                        }
 
+                       if( $this->getTitle()->getNamespace() == NS_IMAGE )
+                               RepoGroup::singleton()->getLocalRepo()->invalidateImageRedirect( $this->getTitle() );
                        wfProfileOut( __METHOD__ );
                        return ( $dbw->affectedRows() != 0 );
                }
index aa16f51..386253b 100644 (file)
@@ -461,12 +461,6 @@ $wgHashedSharedUploadDirectory = true;
  */
 $wgRepositoryBaseUrl = "http://commons.wikimedia.org/wiki/Image:";
 
-/**
- * File redirects
- * If enabled, MediaWiki checks redirects in Image: namespace.
- */
-$wgFileRedirects = false;
-
 #
 # Email settings
 #
index a5ef5e5..666dc7b 100644 (file)
@@ -435,5 +435,14 @@ abstract class FileRepo {
        function checkRedirect( $title ) {
                return false;
        }
+
+       /**
+        * Invalidates image redirect cache related to that image
+        * STUB
+        *
+        * @param Title $title Title of image
+        */
+       function invalidateImageRedirect( $title ) {
+       }
 }
 
index f71cf70..a59da29 100644 (file)
@@ -95,17 +95,29 @@ class LocalRepo extends FSRepo {
        }
 
        function checkRedirect( $title ) {
-               global $wgFileRedirects;
+               global $wgFileRedirects, $wgMemc;
                if( !$wgFileRedirects ) {
                        return false;
                }
 
+               if( is_string( $title ) ) {
+                       $title = Title::newFromTitle( $title );
+               }
                if( $title instanceof Title && $title->getNamespace() == NS_MEDIA ) {
                        $title = Title::makeTitle( NS_IMAGE, $title->getText() );
                }
-               
+
+               $memcKey = wfMemcKey( "image_redirect:" . md5( $title->getPrefixedDBkey() ) );
+               $cachedValue = $wgMemc->get( $memcKey );
+               if( $cachedValue ) {
+                       return Title::newFromDbKey( $cachedValue );
+               } elseif( $cachedValue == ' ' ) { # FIXME: ugly hack, but BagOStuff caching seems to be weird and return false if !cachedValue, not only if it doesn't exist
+                       return false;
+               }
+
                $id = $this->getArticleID( $title );
                if( !$id ) {
+                       $wgMemc->set( $memcKey, " ", 9000 );
                        return false;
                }
                $dbr = $this->getSlaveDB();
@@ -115,9 +127,18 @@ class LocalRepo extends FSRepo {
                        array( 'rd_from' => $id ),
                        __METHOD__
                );
+
+               if( $row ) $targetTitle = Title::makeTitle( $row->rd_namespace, $row->rd_title );
+               $wgMemc->set( $memcKey, ($row ? $targetTitle->getPrefixedDBkey() : " "), 9000 );
                if( !$row ) {
                        return false;
                }
-               return Title::makeTitle( $row->rd_namespace, $row->rd_title );
+               return $targetTitle;
+       }
+
+       function invalidateImageRedirect( $title ) {
+               global $wgMemc;
+               $memcKey = wfMemcKey( "image_redirect:" . md5( $title->getPrefixedDBkey() ) );
+               $wgMemc->delete( $memcKey );
        }
 }