* Remove code duplication for UploadStash: Move all thumbName generation code to...
authorBryan Tong Minh <btongminh@users.mediawiki.org>
Fri, 11 Feb 2011 19:10:31 +0000 (19:10 +0000)
committerBryan Tong Minh <btongminh@users.mediawiki.org>
Fri, 11 Feb 2011 19:10:31 +0000 (19:10 +0000)
* Add a small url encoding fix

includes/filerepo/File.php
includes/specials/SpecialUploadStash.php
includes/upload/UploadStash.php

index ae4d2fe..809fa83 100644 (file)
@@ -476,12 +476,22 @@ abstract class File {
         * @private -ish
         */
        function thumbName( $params ) {
+               return $this->getNamedThumbName( $this->getName(), $params );
+       }
+       
+       /**
+        * Generate a thumbnail file name from a name and specified parameters
+        *
+        * @param string $name
+        * @param array $params Parameters which will be passed to MediaHandler::makeParamString
+        */
+       function generateThumbName( $name, $params ) {
                if ( !$this->getHandler() ) {
                        return null;
                }
                $extension = $this->getExtension();
                list( $thumbExt, $thumbMime ) = $this->handler->getThumbType( $extension, $this->getMimeType(), $params );
-               $thumbName = $this->handler->makeParamString( $params ) . '-' . $this->getName();
+               $thumbName = $this->handler->makeParamString( $params ) . '-' . $name;
                if ( $thumbExt != $extension ) {
                        $thumbName .= ".$thumbExt";
                }
index 0c6d0d6..c3c1bdc 100644 (file)
@@ -215,8 +215,12 @@ class SpecialUploadStash extends UnlistedSpecialPage {
                // do not use trailing slash
                global $wgUploadStashScalerBaseUrl;
 
-               $scalerThumbName = $file->getParamThumbName( $file->name, $params );
-               $scalerThumbUrl = $wgUploadStashScalerBaseUrl . '/' . $file->getRel() . '/' . $scalerThumbName;
+               // We need to use generateThumbName() instead of thumbName(), because 
+               // the suffix needs to match the file name for the remote thumbnailer 
+               // to work
+               $scalerThumbName = $file->generateThumbName( $file->getName(), $params );
+               $scalerThumbUrl = $wgUploadStashScalerBaseUrl . '/' . $file->getUrlRel() . 
+                       '/' . rawurlencode( $scalerThumbName );
                
                // make a curl call to the scaler to create a thumbnail
                $httpOptions = array( 
@@ -226,7 +230,7 @@ class SpecialUploadStash extends UnlistedSpecialPage {
                $req = MWHttpRequest::factory( $scalerThumbUrl, $httpOptions );
                $status = $req->execute();
                if ( ! $status->isOK() ) {
-                       $errors = $status->getErrorsArray();    
+                       $errors = $status->getWikiTextArray( $status->getErrorsArray() );
                        throw new MWException( "Fetching thumbnail failed: " . join( ", ", $errors ) );
                }
                $contentType = $req->getResponseHeader( "content-type" );
index ece13ea..ce73b8b 100644 (file)
@@ -301,36 +301,15 @@ class UploadStashFile extends UnregisteredLocalFile {
        }
 
        /**
-        * Return the file/url base name of a thumbnail with the specified parameters
+        * Return the file/url base name of a thumbnail with the specified parameters. 
+        * We override this because we want to use the pretty url name instead of the 
+        * ugly file name.
         *
         * @param $params Array: handler-specific parameters
         * @return String: base name for URL, like '120px-12345.jpg', or null if there is no handler
         */
        function thumbName( $params ) {
-               return $this->getParamThumbName( $this->getUrlName(), $params );
-       }
-
-
-       /**
-        * Given the name of the original, i.e. Foo.jpg, and scaling parameters, returns filename with appropriate extension
-        * This is abstracted from getThumbName because we also use it to calculate the thumbname the file should have on 
-        * remote image scalers 
-        *
-        * @param String $urlName: A filename, like MyMovie.ogx
-        * @param Array $parameters: scaling parameters, like array( 'width' => '120' );
-        * @return String|null parameterized thumb name, like 120px-MyMovie.ogx.jpg, or null if no handler found
-        */
-       function getParamThumbName( $urlName, $params ) {
-               if ( !$this->getHandler() ) {
-                       return null;
-               }
-               $extension = $this->getExtension();
-               list( $thumbExt, ) = $this->handler->getThumbType( $extension, $this->getMimeType(), $params );
-               $thumbName = $this->getHandler()->makeParamString( $params ) . '-' . $urlName;
-               if ( $thumbExt != $extension ) {
-                       $thumbName .= ".$thumbExt";
-               }
-               return $thumbName;
+               return $this->generateThumbName( $this->getUrlName(), $params );
        }
 
        /**