Merge "mw.Upload.BookletLayout: Don't explode when the API call fails with 'exception'"
[lhc/web/wiklou.git] / includes / filerepo / file / ForeignAPIFile.php
index e51f381..43cb5a5 100644 (file)
@@ -218,6 +218,25 @@ class ForeignAPIFile extends File {
                return isset( $this->mInfo['url'] ) ? strval( $this->mInfo['url'] ) : null;
        }
 
+       /**
+        * Get short description URL for a file based on the foreign API response,
+        * or if unavailable, the short URL is constructed from the foreign page ID.
+        *
+        * @return null|string
+        * @since 1.27
+        */
+       public function getDescriptionShortUrl() {
+               if ( isset( $this->mInfo['descriptionshorturl'] ) ) {
+                       return $this->mInfo['descriptionshorturl'];
+               } elseif ( isset( $this->mInfo['pageid'] ) ) {
+                       $url = $this->repo->makeUrl( array( 'curid' => $this->mInfo['pageid'] ) );
+                       if ( $url !== false ) {
+                               return $url;
+                       }
+               }
+               return null;
+       }
+
        /**
         * @param string $type
         * @return int|null|string
@@ -244,7 +263,7 @@ class ForeignAPIFile extends File {
         */
        function getSha1() {
                return isset( $this->mInfo['sha1'] )
-                       ? wfBaseConvert( strval( $this->mInfo['sha1'] ), 16, 36, 31 )
+                       ? Wikimedia\base_convert( strval( $this->mInfo['sha1'] ), 16, 36, 31 )
                        : null;
        }
 
@@ -334,22 +353,20 @@ class ForeignAPIFile extends File {
        }
 
        function purgeDescriptionPage() {
-               global $wgMemc, $wgContLang;
+               global $wgContLang;
 
                $url = $this->repo->getDescriptionRenderUrl( $this->getName(), $wgContLang->getCode() );
                $key = $this->repo->getLocalCacheKey( 'RemoteFileDescription', 'url', md5( $url ) );
 
-               $wgMemc->delete( $key );
+               ObjectCache::getMainWANInstance()->delete( $key );
        }
 
        /**
         * @param array $options
         */
        function purgeThumbnails( $options = array() ) {
-               global $wgMemc;
-
                $key = $this->repo->getLocalCacheKey( 'ForeignAPIRepo', 'ThumbUrl', $this->getName() );
-               $wgMemc->delete( $key );
+               ObjectCache::getMainWANInstance()->delete( $key );
 
                $files = $this->getThumbnails();
                // Give media handler a chance to filter the purge list
@@ -369,4 +386,13 @@ class ForeignAPIFile extends File {
                # Clear out the thumbnail directory if empty
                $this->repo->quickCleanDir( $dir );
        }
+
+       /**
+        * The thumbnail is created on the foreign server and fetched over internet
+        * @since 1.25
+        * @return bool
+        */
+       public function isTransformedLocally() {
+               return false;
+       }
 }