* @param array $params An associative array of handler-specific parameters.
* Typical keys are width, height and page.
* @param int $flags A bitfield, may contain self::RENDER_NOW to force rendering
- * @return MediaTransformOutput|bool False on failure
+ * @return ThumbnailImage|MediaTransformOutput|bool False on failure
*/
function transform( $params, $flags = 0 ) {
global $wgThumbnailEpoch;
if ( $this->repo ) {
// Defer rendering if a 404 handler is set up...
if ( $this->repo->canTransformVia404() && !( $flags & self::RENDER_NOW ) ) {
- wfDebug( __METHOD__ . " transformation deferred.\n" );
// XXX: Pass in the storage path even though we are not rendering anything
// and the path is supposed to be an FS path. This is due to getScalerType()
// getting called on the path and clobbering $thumb->getUrl() if it's false.
/**
* Creates a temp FS file with the same extension and the thumbnail
* @param string $thumbPath Thumbnail path
- * @return TempFSFile
+ * @return TempFSFile|null
*/
protected function makeTransformTmpFile( $thumbPath ) {
$thumbExt = FileBackend::extensionFromPath( $thumbPath );
$renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName(), $lang->getCode() );
if ( $renderUrl ) {
$cache = ObjectCache::getMainWANInstance();
+ $key = $this->repo->getLocalCacheKey(
+ 'RemoteFileDescription',
+ 'url',
+ $lang->getCode(),
+ $this->getName()
+ );
- $key = null;
- if ( $this->repo->descriptionCacheExpiry > 0 ) {
- wfDebug( "Attempting to get the description from cache..." );
- $key = $this->repo->getLocalCacheKey(
- 'RemoteFileDescription',
- 'url',
- $lang->getCode(),
- $this->getName()
- );
- $obj = $cache->get( $key );
- if ( $obj ) {
- wfDebug( "success!\n" );
-
- return $obj;
- }
- wfDebug( "miss\n" );
- }
- wfDebug( "Fetching shared description from $renderUrl\n" );
- $res = Http::get( $renderUrl, [], __METHOD__ );
- if ( $res && $key ) {
- $cache->set( $key, $res, $this->repo->descriptionCacheExpiry );
- }
+ return $cache->getWithSetCallback(
+ $key,
+ $this->repo->descriptionCacheExpiry ?: $cache::TTL_UNCACHEABLE,
+ function ( $oldValue, &$ttl, array &$setOpts ) use ( $renderUrl ) {
+ wfDebug( "Fetching shared description from $renderUrl\n" );
+ $res = Http::get( $renderUrl, [], __METHOD__ );
+ if ( !$res ) {
+ $ttl = WANObjectCache::TTL_UNCACHEABLE;
+ }
- return $res;
- } else {
- return false;
+ return $res;
+ }
+ );
}
+
+ return false;
}
/**