$dbw->delete( 'redirect', $where, __METHOD__);
}
+ if( $this->getTitle()->getNamespace() == NS_IMAGE )
+ RepoGroup::singleton()->getLocalRepo()->invalidateImageRedirect( $this->getTitle() );
wfProfileOut( __METHOD__ );
return ( $dbw->affectedRows() != 0 );
}
}
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();
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 );
}
}