Merge "Move MediaHandler defaults out of global scope"
[lhc/web/wiklou.git] / includes / filerepo / file / File.php
index 433e395..425a08c 100644 (file)
@@ -393,10 +393,10 @@ abstract class File implements IDBAccessObject {
                                wfDebug( __METHOD__ . ': supposed to render ' . $this->getName() .
                                        ' (' . $this->getMimeType() . "), but can't!\n" );
 
-                               return $this->getURL(); # hm... return NULL?
+                               return $this->getUrl(); # hm... return NULL?
                        }
                } else {
-                       return $this->getURL();
+                       return $this->getUrl();
                }
        }
 
@@ -1028,7 +1028,7 @@ abstract class File implements IDBAccessObject {
         * @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;
@@ -1065,7 +1065,6 @@ abstract class File implements IDBAccessObject {
                        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.
@@ -1325,7 +1324,7 @@ abstract class File implements IDBAccessObject {
        /**
         * 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 );
@@ -2046,34 +2045,29 @@ abstract class File implements IDBAccessObject {
                $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;
        }
 
        /**