ForeignAPIRepo: Fetch thumb error from foreign repo
authorumherirrender <umherirrender_de.wp@web.de>
Sat, 13 Apr 2013 14:28:02 +0000 (16:28 +0200)
committerumherirrender <umherirrender_de.wp@web.de>
Sat, 13 Apr 2013 14:28:02 +0000 (16:28 +0200)
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

includes/filerepo/ForeignAPIRepo.php
includes/filerepo/file/ForeignAPIFile.php
languages/messages/MessagesEn.php
languages/messages/MessagesQqq.php
maintenance/language/messages.inc

index ba574da..85d3e7e 100644 (file)
@@ -143,7 +143,7 @@ class ForeignAPIRepo extends FileRepo {
         * @return string
         */
        function fetchImageQuery( $query ) {
-               global $wgMemc;
+               global $wgMemc, $wgLanguageCode;
 
                $query = array_merge( $query,
                        array(
@@ -151,6 +151,9 @@ class ForeignAPIRepo extends FileRepo {
                                '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 {
@@ -241,6 +244,40 @@ class ForeignAPIRepo extends FileRepo {
                }
        }
 
+       /**
+        * @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
         *
index edf623e..f551fd0 100644 (file)
@@ -119,12 +119,25 @@ class ForeignAPIFile extends File {
                // 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 );
        }
 
index 44b6cc9..2c184ac 100644 (file)
@@ -3466,6 +3466,8 @@ Please visit [//www.mediawiki.org/wiki/Localisation MediaWiki Localisation] and
 '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',
index d481aea..b00005f 100644 (file)
@@ -5932,6 +5932,9 @@ The reason $1 is one of the following messages:
 * {{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:
index 9c883bf..e4570d9 100644 (file)
@@ -2405,6 +2405,7 @@ $wgMessageStructure = array(
                'thumbnail-more',
                'filemissing',
                'thumbnail_error',
+               'thumbnail_error_remote',
                'djvu_page_error',
                'djvu_no_xml',
                'thumbnail-temp-create',