From 1e4ad78a721a97b68884ec342da489ec48000c55 Mon Sep 17 00:00:00 2001 From: Erik Moeller Date: Sat, 30 Oct 2004 08:40:08 +0000 Subject: [PATCH] if the shared repository is utf-8, and the local wiki is latin1, encode filenames --- includes/DefaultSettings.php | 2 ++ includes/Image.php | 40 +++++++++++++++++++++++++----------- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 88041dc04b..ee8495f5ab 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -138,6 +138,8 @@ $wgSharedUploadDirectory = "/var/www/wiki3/images"; # accessible by all wikis, and you do not want to use the hash (path/a/aa/) # directory layout. $wgHashedSharedUploadDirectory = true; +# set true if the repository uses latin1 filenames +$wgSharedLatin1=false; # Email settings # diff --git a/includes/Image.php b/includes/Image.php index ae1653eee8..e5704d6d24 100644 --- a/includes/Image.php +++ b/includes/Image.php @@ -43,12 +43,12 @@ class Image { global $wgUploadDirectory,$wgHashedUploadDirectory, $wgUseSharedUploads, $wgSharedUploadDirectory, - $wgHashedSharedUploadDirectory; + $wgHashedSharedUploadDirectory,$wgUseLatin1, + $wgSharedLatin1; $this->name = $name; $this->title = Title::makeTitleSafe( NS_IMAGE, $this->name ); - $this->fromSharedDirectory = false; - + $this->fromSharedDirectory = false; if ($wgHashedUploadDirectory) { $hash = md5( $this->title->getDBkey() ); $this->imagePath = $wgUploadDirectory . '/' . $hash{0} . '/' . @@ -63,9 +63,14 @@ class Image if (!$this->fileExists && $wgUseSharedUploads) { # in case we're running a capitallinks=false wiki $sharedname=ucfirst($name); + $sharedtitle=$this->title->getDBkey(); + if($wgUseLatin1 && !$wgSharedLatin1) { + $sharedname=utf8_encode($sharedname); + $sharedtitle=utf8_encode($sharedtitle); + } if($wgHashedSharedUploadDirectory) { - $hash = md5( $this->title->getDBkey() ); + $hash = md5( $sharedtitle ); $this->imagePath = $wgSharedUploadDirectory . '/' . $hash{0} . '/' . substr( $hash, 0, 2 ) . "/".$sharedname; } else { @@ -73,7 +78,7 @@ class Image } $this->fileExists = file_exists( $this->imagePath); $this->fromSharedDirectory = true; - #wfDebug ("File from shared directory: ".$this->imagePath."\n"); + #wfDebug ("File from shared directory: ".$this->imagePath."\n"); } if($this->fileExists) { $this->url = $this->wfImageUrl( $name, $this->fromSharedDirectory ); @@ -241,11 +246,15 @@ class Image function wfImageUrl( $name, $fromSharedDirectory = false ) { global $wgUploadPath,$wgUploadBaseUrl,$wgHashedUploadDirectory, - $wgHashedSharedUploadDirectory,$wgSharedUploadPath; + $wgHashedSharedUploadDirectory,$wgSharedUploadPath, + $wgUseLatin1, $wgSharedLatin1; if($fromSharedDirectory) { $hash = $wgHashedSharedUploadDirectory; $base = ''; $path = $wgSharedUploadPath; + if($wgUseLatin1 && !$wgSharedLatin1) { + $name=utf8_encode($name); + } } else { $hash = $wgHashedUploadDirectory; $base = $wgUploadBaseUrl; @@ -278,12 +287,15 @@ class Image function thumbUrl( $width, $subdir='thumb') { global $wgUploadPath,$wgHashedUploadDirectory, $wgUploadBaseUrl, $wgSharedUploadPath,$wgSharedUploadDirectory, - $wgHashedSharedUploadDirectory; - $name = $this->thumbName( $width ); + $wgHashedSharedUploadDirectory,$wgUseLatin1,$wgSharedLatin1; + $name = $this->thumbName( $width ); if($this->fromSharedDirectory) { $hashdir = $wgHashedSharedUploadDirectory; $base = ''; $path = $wgSharedUploadPath; + if($wgUseLatin1 && !$wgSharedLatin1) { + $name=utf8_encode($name); + } } else { $hashdir = $wgHashedUploadDirectory; $base = $wgUploadBaseUrl; @@ -304,14 +316,19 @@ class Image * Return the file name of a thumbnail of the specified width * * @param integer $width Width of the thumbnail image + * @param boolean $shared Does the thumbnail come from the shared repository? * @access private */ - function thumbName( $width ) { + function thumbName( $width, $shared=false ) { + global $wgUseLatin1,$wgSharedLatin1; $thumb = $width."px-".$this->name; if( $this->extension == 'svg' ) { # Rasterize SVG vector images to PNG $thumb .= '.png'; } + if( $shared && $wgUseLatin1 && !$wgSharedLatin1) { + $thumb=utf8_encode($thumb); + } return $thumb; } @@ -366,7 +383,7 @@ class Image $width = IntVal( $width ); - $thumbName = $this->thumbName( $width ); + $thumbName = $this->thumbName( $width, $this->fromSharedDirectory ); $thumbPath = wfImageThumbDir( $thumbName, 'thumb', $this->fromSharedDirectory ).'/'.$thumbName; $thumbUrl = $this->thumbUrl( $width ); #wfDebug ( "Render name: $thumbName path: $thumbPath url: $thumbUrl\n"); @@ -608,9 +625,8 @@ function wfImageArchiveDir( $fname , $subdir='archive', $shared=false ) global $wgUploadDirectory, $wgHashedUploadDirectory, $wgSharedUploadDirectory, $wgHashedSharedUploadDirectory; $dir = $shared ? $wgSharedUploadDirectory : $wgUploadDirectory; - $hashdir = $shared ? $wgHashedSharedUploadDirectory : $wgHashedUploadDirectory; + $hashdir = $shared ? $wgHashedSharedUploadDirectory : $wgHashedUploadDirectory; if (!$hashdir) { return $dir.'/'.$subdir; } - $hash = md5( $fname ); $oldumask = umask(0); # Suppress warning messages here; if the file itself can't -- 2.20.1