From 6b55d68996f3340dc78982e4d87e0a206efdd2d7 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Mon, 20 Apr 2009 03:06:49 +0000 Subject: [PATCH] Move checkRedirect() from FileRepo to LocalRepo, leaving only a stub behind. It's inappropriate for FileRepo to be accessing the database or memcached, this is exclusively a job for a subclass. Avoids error "Call to undefined method ::getArticleID()" whenever anyone uses a repo which is not derived from LocalRepo, such as FSRepo or ForeignAPIRepo. --- includes/filerepo/FileRepo.php | 41 +++--------------------------- includes/filerepo/LocalRepo.php | 45 +++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 37 deletions(-) diff --git a/includes/filerepo/FileRepo.php b/includes/filerepo/FileRepo.php index aaf548677e..4176d3a257 100644 --- a/includes/filerepo/FileRepo.php +++ b/includes/filerepo/FileRepo.php @@ -518,47 +518,14 @@ abstract class FileRepo { function cleanupDeletedBatch( $storageKeys ) {} /** - * Checks if there is a redirect named as $title + * Checks if there is a redirect named as $title. If there is, return the + * title object. If not, return false. + * STUB * * @param Title $title Title of image */ 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; + return false; } /** diff --git a/includes/filerepo/LocalRepo.php b/includes/filerepo/LocalRepo.php index 4014699fb8..c679dd98cd 100644 --- a/includes/filerepo/LocalRepo.php +++ b/includes/filerepo/LocalRepo.php @@ -67,6 +67,51 @@ class LocalRepo extends FSRepo { } return $status; } + + /** + * Checks if there is a redirect named as $title + * + * @param Title $title Title of image + */ + 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 link Title::getArticleID(). -- 2.20.1