From 9ae9869d9715b3ebea6b9006a8b29475ebb684aa Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Sat, 8 Nov 2008 17:33:52 +0000 Subject: [PATCH] (bug 16265) Enabling apiThumbCacheExpiry produced invalid thumbs for things like svg that get turned to png. --- RELEASE-NOTES | 2 ++ includes/filerepo/ForeignAPIRepo.php | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 65173e3617..ba64820d3d 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -323,6 +323,8 @@ The following extensions are migrated into MediaWiki 1.14: * (bug 5101) Image from Commons doesn't show up when searched in Wikipedia search box * (bug 4362) [[MediaWiki:History copyright]] no more used with most recent revision when passing oldid parameter in the url +* (bug 16265) When caching thumbs with the ForeignApiRepo, we now use the same filename + as the remote site. === API changes in 1.14 === diff --git a/includes/filerepo/ForeignAPIRepo.php b/includes/filerepo/ForeignAPIRepo.php index 36a2f8197a..e9bec9b24a 100644 --- a/includes/filerepo/ForeignAPIRepo.php +++ b/includes/filerepo/ForeignAPIRepo.php @@ -124,15 +124,21 @@ class ForeignAPIRepo extends FileRepo { } else { $foreignUrl = $this->getThumbUrl( $name, $width, $height ); - $path = $this->apiThumbCacheDir . '/' . $this->name . '/' . + + // We need the same filename as the remote one :) + $fileName = ltrim( substr( $foreignUrl, strrpos( $foreignUrl, '/' ), + strlen ( $foreignUrl ) ), '/' ); + //die( var_dump( $fileName ) ); + $path = $this->apiThumbCacheDir . '/' . $name . '/'; if ( !is_dir($wgUploadDirectory . '/' . $path) ) { wfMkdirParents($wgUploadDirectory . '/' . $path); } - $localUrl = $wgServer . $wgUploadPath . '/' . $path . $width . 'px-' . $name; + + $localUrl = $wgServer . $wgUploadPath . '/' . $path . $fileName; $thumb = Http::get( $foreignUrl ); # FIXME: Delete old thumbs that aren't being used. Maintenance script? - file_put_contents($wgUploadDirectory . '/' . $path . $width . 'px-' . $name, $thumb ); + file_put_contents($wgUploadDirectory . '/' . $path . $fileName, $thumb ); $wgMemc->set( $key, $localUrl, $this->apiThumbCacheExpiry ); wfDebug( __METHOD__ . " got local thumb $localUrl, saving to cache \n" ); return $localUrl; -- 2.20.1