* @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";
}
// 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(
$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" );
}
/**
- * 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 );
}
/**