(bug 16265) Enabling apiThumbCacheExpiry produced invalid thumbs for things like...
authorChad Horohoe <demon@users.mediawiki.org>
Sat, 8 Nov 2008 17:33:52 +0000 (17:33 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Sat, 8 Nov 2008 17:33:52 +0000 (17:33 +0000)
RELEASE-NOTES
includes/filerepo/ForeignAPIRepo.php

index 65173e3..ba64820 100644 (file)
@@ -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 ===
 
index 36a2f81..e9bec9b 100644 (file)
@@ -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;