Merge "Improve docs for Title::getInternalURL/getCanonicalURL"
[lhc/web/wiklou.git] / includes / filerepo / ForeignAPIRepo.php
index c20df76..346ec8e 100644 (file)
@@ -22,7 +22,6 @@
  */
 
 use MediaWiki\Logger\LoggerFactory;
-use MediaWiki\MediaWikiServices;
 
 /**
  * A foreign repository with a remote MediaWiki with an API thingy
@@ -333,7 +332,6 @@ class ForeignAPIRepo extends FileRepo {
         * @return bool|string
         */
        function getThumbUrlFromCache( $name, $width, $height, $params = "" ) {
-               $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                // We can't check the local cache using FileRepo functions because
                // we override fileExistsBatch(). We have to use the FileBackend directly.
                $backend = $this->getBackend(); // convenience
@@ -346,18 +344,15 @@ class ForeignAPIRepo extends FileRepo {
                $sizekey = "$width:$height:$params";
 
                /* Get the array of urls that we already know */
-               $knownThumbUrls = $cache->get( $key );
+               $knownThumbUrls = $this->wanCache->get( $key );
                if ( !$knownThumbUrls ) {
                        /* No knownThumbUrls for this file */
                        $knownThumbUrls = [];
-               } else {
-                       if ( isset( $knownThumbUrls[$sizekey] ) ) {
-                               wfDebug( __METHOD__ . ': Got thumburl from local cache: ' .
-                                       "{$knownThumbUrls[$sizekey]} \n" );
+               } elseif ( isset( $knownThumbUrls[$sizekey] ) ) {
+                       wfDebug( __METHOD__ . ': Got thumburl from local cache: ' .
+                               "{$knownThumbUrls[$sizekey]} \n" );
 
-                               return $knownThumbUrls[$sizekey];
-                       }
-                       /* This size is not yet known */
+                       return $knownThumbUrls[$sizekey];
                }
 
                $metadata = null;
@@ -392,7 +387,7 @@ class ForeignAPIRepo extends FileRepo {
                        if ( $remoteModified < $modified && $diff < $this->fileCacheExpiry ) {
                                /* Use our current and already downloaded thumbnail */
                                $knownThumbUrls[$sizekey] = $localUrl;
-                               $cache->set( $key, $knownThumbUrls, $this->apiThumbCacheExpiry );
+                               $this->wanCache->set( $key, $knownThumbUrls, $this->apiThumbCacheExpiry );
 
                                return $localUrl;
                        }
@@ -417,9 +412,9 @@ class ForeignAPIRepo extends FileRepo {
                $knownThumbUrls[$sizekey] = $localUrl;
 
                $ttl = $mtime
-                       ? $cache->adaptiveTTL( $mtime, $this->apiThumbCacheExpiry )
+                       ? $this->wanCache->adaptiveTTL( $mtime, $this->apiThumbCacheExpiry )
                        : $this->apiThumbCacheExpiry;
-               $cache->set( $key, $knownThumbUrls, $ttl );
+               $this->wanCache->set( $key, $knownThumbUrls, $ttl );
                wfDebug( __METHOD__ . " got local thumb $localUrl, saving to cache \n" );
 
                return $localUrl;
@@ -570,22 +565,21 @@ class ForeignAPIRepo extends FileRepo {
                        $url = $this->makeUrl( $query, 'api' );
                }
 
-               $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
-               return $cache->getWithSetCallback(
+               return $this->wanCache->getWithSetCallback(
                        $this->getLocalCacheKey( static::class, $target, md5( $url ) ),
                        $cacheTTL,
-                       function ( $curValue, &$ttl ) use ( $url, $cache ) {
+                       function ( $curValue, &$ttl ) use ( $url ) {
                                $html = self::httpGet( $url, 'default', [], $mtime );
                                if ( $html !== false ) {
-                                       $ttl = $mtime ? $cache->adaptiveTTL( $mtime, $ttl ) : $ttl;
+                                       $ttl = $mtime ? $this->wanCache->adaptiveTTL( $mtime, $ttl ) : $ttl;
                                } else {
-                                       $ttl = $cache->adaptiveTTL( $mtime, $ttl );
+                                       $ttl = $this->wanCache->adaptiveTTL( $mtime, $ttl );
                                        $html = null; // caches negatives
                                }
 
                                return $html;
                        },
-                       [ 'pcTTL' => $cache::TTL_PROC_LONG ]
+                       [ 'pcTTL' => WANObjectCache::TTL_PROC_LONG ]
                );
        }