TheDJ has submitted this change and it was merged.

Change subject: ForeignAPIRepo: Fetch thumb error from foreign repo
......................................................................


ForeignAPIRepo: Fetch thumb error from foreign repo

When the api of the foreign repo gives a thumb error, this is now
reported to the user.

This can produce an extra request to the api, when the language of the
user does not match the content language of the client. In that case an
extra request is used to get a localized error message.

Change-Id: I6bda81899d0f11a0091b973ab49fd8e0f976ee09
---
M includes/filerepo/ForeignAPIRepo.php
M includes/filerepo/file/ForeignAPIFile.php
M languages/messages/MessagesEn.php
M languages/messages/MessagesQqq.php
M maintenance/language/messages.inc
5 files changed, 60 insertions(+), 4 deletions(-)

Approvals:
  Siebrand: Looks good to me, but someone else must approve
  Raimond Spekking: Looks good to me, but someone else must approve
  TheDJ: Verified; Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/filerepo/ForeignAPIRepo.php 
b/includes/filerepo/ForeignAPIRepo.php
index ba574da..85d3e7e 100644
--- a/includes/filerepo/ForeignAPIRepo.php
+++ b/includes/filerepo/ForeignAPIRepo.php
@@ -143,7 +143,7 @@
         * @return string
         */
        function fetchImageQuery( $query ) {
-               global $wgMemc;
+               global $wgMemc, $wgLanguageCode;
 
                $query = array_merge( $query,
                        array(
@@ -151,6 +151,9 @@
                                'action'    => 'query',
                                'redirects' => 'true'
                        ) );
+               if ( !isset( $query['uselang'] ) ) { // uselang is unset or null
+                       $query['uselang'] = $wgLanguageCode;
+               }
                if ( $this->mApiBase ) {
                        $url = wfAppendQuery( $this->mApiBase, $query );
                } else {
@@ -242,6 +245,40 @@
        }
 
        /**
+        * @param $name string
+        * @param $width int
+        * @param $height int
+        * @param $otherParams string
+        * @return bool|MediaTransformError
+        * @since 1.22
+        */
+       function getThumbError( $name, $width = -1, $height = -1, $otherParams 
= '', $lang = null ) {
+               $data = $this->fetchImageQuery( array(
+                       'titles' => 'File:' . $name,
+                       'iiprop' => 'url|timestamp',
+                       'iiurlwidth' => $width,
+                       'iiurlheight' => $height,
+                       'iiurlparam' => $otherParams,
+                       'prop' => 'imageinfo',
+                       'uselang' => $lang,
+               ) );
+               $info = $this->getImageInfo( $data );
+
+               if( $data && $info && isset( $info['thumberror'] ) ) {
+                       wfDebug( __METHOD__ . " got remote thumb error " . 
$info['thumberror'] . "\n" );
+                       return new MediaTransformError(
+                               'thumbnail_error_remote',
+                               $width,
+                               $height,
+                               $this->getDisplayName(),
+                               $info['thumberror'] // already parsed message 
from foreign repo
+                       );
+               } else {
+                       return false;
+               }
+       }
+
+       /**
         * Return the imageurl from cache if possible
         *
         * If the url has been requested today, get it from cache
diff --git a/includes/filerepo/file/ForeignAPIFile.php 
b/includes/filerepo/file/ForeignAPIFile.php
index edf623e..f551fd0 100644
--- a/includes/filerepo/file/ForeignAPIFile.php
+++ b/includes/filerepo/file/ForeignAPIFile.php
@@ -119,12 +119,25 @@
                // Note, the this->canRender() check above implies
                // that we have a handler, and it can do makeParamString.
                $otherParams = $this->handler->makeParamString( $params );
+               $width = isset( $params['width'] ) ? $params['width'] : -1;
+               $height = isset( $params['height'] ) ? $params['height'] : -1;
 
                $thumbUrl = $this->repo->getThumbUrlFromCache(
                        $this->getName(),
-                       isset( $params['width'] ) ? $params['width'] : -1,
-                       isset( $params['height'] ) ? $params['height'] : -1,
-                       $otherParams );
+                       $width,
+                       $height,
+                       $otherParams
+               );
+               if ( $thumbUrl === false ) {
+                       global $wgLang;
+                       return $this->repo->getThumbError(
+                               $this->getName(),
+                               $width,
+                               $height,
+                               $otherParams,
+                               $wgLang->getCode()
+                       );
+               }
                return $this->handler->getTransform( $this, 'bogus', $thumbUrl, 
$params );
        }
 
diff --git a/languages/messages/MessagesEn.php 
b/languages/messages/MessagesEn.php
index 44b6cc9..2c184ac 100644
--- a/languages/messages/MessagesEn.php
+++ b/languages/messages/MessagesEn.php
@@ -3466,6 +3466,8 @@
 'thumbnail-more'           => 'Enlarge',
 'filemissing'              => 'File missing',
 'thumbnail_error'          => 'Error creating thumbnail: $1',
+'thumbnail_error_remote'   => 'Error message from $1:
+$2',
 'djvu_page_error'          => 'DjVu page out of range',
 'djvu_no_xml'              => 'Unable to fetch XML for DjVu file',
 'thumbnail-temp-create'    => 'Unable to create temporary thumbnail file',
diff --git a/languages/messages/MessagesQqq.php 
b/languages/messages/MessagesQqq.php
index d481aea..b00005f 100644
--- a/languages/messages/MessagesQqq.php
+++ b/languages/messages/MessagesQqq.php
@@ -5932,6 +5932,9 @@
 * {{msg-mw|Djvu page error}}
 * {{msg-mw|Svg-long-error}}
 * other custom string',
+'thumbnail_error_remote' => 'Message shown in a thumbnail frame when creation 
of the thumbnail fails. Parameters:
+* $1 - is the name of the shared repository, see {{msg-mw|shardupload}}
+* $2 - the reason, see {{msg-mw|thumbnail_error}}',
 'djvu_page_error' => 'Used as error message.
 
 See also:
diff --git a/maintenance/language/messages.inc 
b/maintenance/language/messages.inc
index 9c883bf..e4570d9 100644
--- a/maintenance/language/messages.inc
+++ b/maintenance/language/messages.inc
@@ -2405,6 +2405,7 @@
                'thumbnail-more',
                'filemissing',
                'thumbnail_error',
+               'thumbnail_error_remote',
                'djvu_page_error',
                'djvu_no_xml',
                'thumbnail-temp-create',

-- 
To view, visit https://gerrit.wikimedia.org/r/47225
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I6bda81899d0f11a0091b973ab49fd8e0f976ee09
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Umherirrender <[email protected]>
Gerrit-Reviewer: Brian Wolff <[email protected]>
Gerrit-Reviewer: Demon <[email protected]>
Gerrit-Reviewer: Nemo bis <[email protected]>
Gerrit-Reviewer: Raimond Spekking <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: TheDJ <[email protected]>
Gerrit-Reviewer: Umherirrender <[email protected]>
Gerrit-Reviewer: btongminh <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to