From: umherirrender Date: Sat, 13 Apr 2013 14:28:02 +0000 (+0200) Subject: ForeignAPIRepo: Fetch thumb error from foreign repo X-Git-Tag: 1.31.0-rc.0~19634^2 X-Git-Url: http://git.cyclocoop.org/%22.%24h.%22?a=commitdiff_plain;h=bc59c4fc32a31f8815419cf7f832ef4a2ea91232;p=lhc%2Fweb%2Fwiklou.git 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 --- diff --git a/includes/filerepo/ForeignAPIRepo.php b/includes/filerepo/ForeignAPIRepo.php index ba574da177..85d3e7ed3f 100644 --- a/includes/filerepo/ForeignAPIRepo.php +++ b/includes/filerepo/ForeignAPIRepo.php @@ -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 * diff --git a/includes/filerepo/file/ForeignAPIFile.php b/includes/filerepo/file/ForeignAPIFile.php index edf623e281..f551fd011c 100644 --- a/includes/filerepo/file/ForeignAPIFile.php +++ b/includes/filerepo/file/ForeignAPIFile.php @@ -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 ); } diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 44b6cc9477..2c184ac7ce 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -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', diff --git a/languages/messages/MessagesQqq.php b/languages/messages/MessagesQqq.php index d481aeafe1..b00005f3e5 100644 --- a/languages/messages/MessagesQqq.php +++ b/languages/messages/MessagesQqq.php @@ -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: diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index 9c883bf11e..e4570d9619 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -2405,6 +2405,7 @@ $wgMessageStructure = array( 'thumbnail-more', 'filemissing', 'thumbnail_error', + 'thumbnail_error_remote', 'djvu_page_error', 'djvu_no_xml', 'thumbnail-temp-create',