Move checkRedirect and invalidateImageRedirect up a level from LocalRepo to FileRepo...
authorChad Horohoe <demon@users.mediawiki.org>
Fri, 13 Mar 2009 15:33:01 +0000 (15:33 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Fri, 13 Mar 2009 15:33:01 +0000 (15:33 +0000)
includes/filerepo/FileRepo.php
includes/filerepo/LocalRepo.php

index 02feb04..6332d3a 100644 (file)
@@ -518,21 +518,57 @@ abstract class FileRepo {
 
        /**
         * Checks if there is a redirect named as $title
-        * STUB
         *
         * @param Title $title Title of image
         */
        function checkRedirect( $title ) {
-               return false;
+               global $wgMemc;
+
+               if( is_string( $title ) ) {
+                       $title = Title::newFromTitle( $title );
+               }
+               if( $title instanceof Title && $title->getNamespace() == NS_MEDIA ) {
+                       $title = Title::makeTitle( NS_FILE, $title->getText() );
+               }
+
+               $memcKey = $this->getMemcKey( "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();
+               $row = $dbr->selectRow(
+                       'redirect',
+                       array( 'rd_title', 'rd_namespace' ),
+                       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 $targetTitle;
        }
 
        /**
         * Invalidates image redirect cache related to that image
-        * STUB
         *
         * @param Title $title Title of image
-        */
+        */     
        function invalidateImageRedirect( $title ) {
+               global $wgMemc;
+               $memcKey = $this->getMemcKey( "image_redirect:" . md5( $title->getPrefixedDBkey() ) );
+               $wgMemc->delete( $memcKey );
        }
        
        function findBySha1( $hash ) {
index 5eb1a11..25f9092 100644 (file)
@@ -101,50 +101,7 @@ class LocalRepo extends FSRepo {
                return $id;
        }
 
-       function checkRedirect( $title ) {
-               global $wgMemc;
 
-               if( is_string( $title ) ) {
-                       $title = Title::newFromTitle( $title );
-               }
-               if( $title instanceof Title && $title->getNamespace() == NS_MEDIA ) {
-                       $title = Title::makeTitle( NS_FILE, $title->getText() );
-               }
-
-               $memcKey = $this->getMemcKey( "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();
-               $row = $dbr->selectRow(
-                       'redirect',
-                       array( 'rd_title', 'rd_namespace' ),
-                       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 $targetTitle;
-       }
-
-       function invalidateImageRedirect( $title ) {
-               global $wgMemc;
-               $memcKey = $this->getMemcKey( "image_redirect:" . md5( $title->getPrefixedDBkey() ) );
-               $wgMemc->delete( $memcKey );
-       }
        
        function findBySha1( $hash ) {
                $dbr = $this->getSlaveDB();