From bc7d8a88275981a2ab72f645849ed1b8cacc0e51 Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Tue, 27 Jan 2009 19:34:21 +0000 Subject: [PATCH] Remote file descriptions are now fetched using the uselang= parameter with $wgContLang. --- RELEASE-NOTES | 2 ++ includes/filerepo/File.php | 11 +++++++---- includes/filerepo/FileRepo.php | 12 +++++++++--- includes/filerepo/ForeignAPIFile.php | 4 ++-- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index fdf9b693b1..375c99d588 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -65,6 +65,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 13040) Gender switch in user preferences * (bug 13040) {{GENDER:}} magic word for interface messages * (bug 3301) Optionally sort user list according to account creation time +* Remote description pages for foreign file repos are now fetched in the + content language. === Bug fixes in 1.15 === * (bug 16968) Special:Upload no longer throws useless warnings. diff --git a/includes/filerepo/File.php b/includes/filerepo/File.php index 4f0990afe7..1b0fb71d2d 100644 --- a/includes/filerepo/File.php +++ b/includes/filerepo/File.php @@ -1068,15 +1068,16 @@ abstract class File { * Get the HTML text of the description page, if available */ function getDescriptionText() { - global $wgMemc; + global $wgMemc, $wgLang; if ( !$this->repo->fetchDescription ) { return false; } - $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName() ); + $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName(), $wgContLang->getCode() ); if ( $renderUrl ) { if ( $this->repo->descriptionCacheExpiry > 0 ) { wfDebug("Attempting to get the description from cache..."); - $key = wfMemcKey( 'RemoteFileDescription', 'url', md5($renderUrl) ); + $key = wfMemcKey( 'RemoteFileDescription', 'url', $wgContLang->getCode(), + $this->getName() ); $obj = $wgMemc->get($key); if ($obj) { wfDebug("success!\n"); @@ -1086,7 +1087,9 @@ abstract class File { } wfDebug( "Fetching shared description from $renderUrl\n" ); $res = Http::get( $renderUrl ); - if ( $res && $this->repo->descriptionCacheExpiry > 0 ) $wgMemc->set( $key, $res, $this->repo->descriptionCacheExpiry ); + if ( $res && $this->repo->descriptionCacheExpiry > 0 ) { + $wgMemc->set( $key, $res, $this->repo->descriptionCacheExpiry ); + } return $res; } else { return false; diff --git a/includes/filerepo/FileRepo.php b/includes/filerepo/FileRepo.php index 5beac7329c..44f909f482 100644 --- a/includes/filerepo/FileRepo.php +++ b/includes/filerepo/FileRepo.php @@ -294,16 +294,22 @@ abstract class FileRepo { * MediaWiki this means action=render. This should only be called by the * repository's file class, since it may return invalid results. User code * should use File::getDescriptionText(). + * @param string $name Name of image to fetch + * @param string $lang Language to fetch it in, if any. */ - function getDescriptionRenderUrl( $name ) { + function getDescriptionRenderUrl( $name, $lang = null ) { + $query = 'action=render'; + if ( !is_null( $lang ) ) { + $query .= '&uselang=' . $lang; + } if ( isset( $this->scriptDirUrl ) ) { return $this->scriptDirUrl . '/index.php?title=' . wfUrlencode( 'Image:' . $name ) . - '&action=render'; + "&$query"; } else { $descUrl = $this->getDescriptionUrl( $name ); if ( $descUrl ) { - return wfAppendQuery( $descUrl, 'action=render' ); + return wfAppendQuery( $descUrl, $query ); } else { return false; } diff --git a/includes/filerepo/ForeignAPIFile.php b/includes/filerepo/ForeignAPIFile.php index d9fb85d069..965981f179 100644 --- a/includes/filerepo/ForeignAPIFile.php +++ b/includes/filerepo/ForeignAPIFile.php @@ -146,8 +146,8 @@ class ForeignAPIFile extends File { } function purgeDescriptionPage() { - global $wgMemc; - $url = $this->repo->getDescriptionRenderUrl( $this->getName() ); + global $wgMemc, $wgContLang; + $url = $this->repo->getDescriptionRenderUrl( $this->getName(), $wgContLang->getCode() ); $key = wfMemcKey( 'RemoteFileDescription', 'url', md5($url) ); $wgMemc->delete( $key ); } -- 2.20.1