Merge "Introduce InterwikiLookupAdapter on top of SiteLookup"
[lhc/web/wiklou.git] / includes / filerepo / file / ForeignDBFile.php
index f38248b..c041dea 100644 (file)
@@ -57,7 +57,7 @@ class ForeignDBFile extends LocalFile {
         * @param string $srcPath
         * @param int $flags
         * @param array $options
-        * @return FileRepoStatus
+        * @return Status
         * @throws MWException
         */
        function publish( $srcPath, $flags = 0, array $options = [] ) {
@@ -84,7 +84,7 @@ class ForeignDBFile extends LocalFile {
        /**
         * @param array $versions
         * @param bool $unsuppress
-        * @return FileRepoStatus
+        * @return Status
         * @throws MWException
         */
        function restore( $versions = [], $unsuppress = false ) {
@@ -95,7 +95,7 @@ class ForeignDBFile extends LocalFile {
         * @param string $reason
         * @param bool $suppress
         * @param User|null $user
-        * @return FileRepoStatus
+        * @return Status
         * @throws MWException
         */
        function delete( $reason, $suppress = false, $user = null ) {
@@ -104,7 +104,7 @@ class ForeignDBFile extends LocalFile {
 
        /**
         * @param Title $target
-        * @return FileRepoStatus
+        * @return Status
         * @throws MWException
         */
        function move( $target ) {
@@ -124,8 +124,51 @@ class ForeignDBFile extends LocalFile {
         * @return string
         */
        function getDescriptionText( $lang = false ) {
-               // Restore remote behavior
-               return File::getDescriptionText( $lang );
+               global $wgLang;
+
+               if ( !$this->repo->fetchDescription ) {
+                       return false;
+               }
+
+               $lang = $lang ?: $wgLang;
+               $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName(), $lang->getCode() );
+               if ( !$renderUrl ) {
+                       return false;
+               }
+
+               $touched = $this->repo->getSlaveDB()->selectField(
+                       'page',
+                       'page_touched',
+                       [
+                               'page_namespace' => NS_FILE,
+                               'page_title' => $this->title->getDBkey()
+                       ]
+               );
+               if ( $touched === false ) {
+                       return false; // no description page
+               }
+
+               $cache = ObjectCache::getMainWANInstance();
+
+               return $cache->getWithSetCallback(
+                       $this->repo->getLocalCacheKey(
+                               'RemoteFileDescription',
+                               'url',
+                               $lang->getCode(),
+                               $this->getName(),
+                               $touched
+                       ),
+                       $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;
+                       }
+               );
        }
 
        /**
@@ -137,10 +180,14 @@ class ForeignDBFile extends LocalFile {
         */
        public function getDescriptionShortUrl() {
                $dbr = $this->repo->getSlaveDB();
-               $pageId = $dbr->selectField( 'page', 'page_id', [
-                       'page_namespace' => NS_FILE,
-                       'page_title' => $this->title->getDBkey()
-               ] );
+               $pageId = $dbr->selectField(
+                       'page',
+                       'page_id',
+                       [
+                               'page_namespace' => NS_FILE,
+                               'page_title' => $this->title->getDBkey()
+                       ]
+               );
 
                if ( $pageId !== false ) {
                        $url = $this->repo->makeUrl( [ 'curid' => $pageId ] );