From 255fd3d629c1326e7a1e6b68502cb4cf86da0b28 Mon Sep 17 00:00:00 2001 From: Domas Mituzas Date: Tue, 28 Sep 2004 19:54:51 +0000 Subject: [PATCH] allow turning off image path hashing. there was a feature request for that somewhere. --- includes/DefaultSettings.php | 1 + includes/Image.php | 58 ++++++++++++++++++++++++------------ 2 files changed, 40 insertions(+), 19 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 14072774ab..a07faa1213 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -111,6 +111,7 @@ $wgStyleSheetDirectory = &$wgStyleDirectory; $wgArticlePath = "{$wgScript}?title=$1"; $wgUploadPath = "{$wgScriptPath}/upload"; $wgUploadDirectory = "{$IP}/upload"; +$wgHashedUploadDirectory = true; $wgLogo = "{$wgUploadPath}/wiki.png"; $wgMathPath = "{$wgUploadPath}/math"; $wgMathDirectory = "{$wgUploadDirectory}/math"; diff --git a/includes/Image.php b/includes/Image.php index 7f6b83971b..036c1e76da 100644 --- a/includes/Image.php +++ b/includes/Image.php @@ -31,13 +31,18 @@ class Image function Image( $name ) { - global $wgUploadDirectory; + global $wgUploadDirectory,$wgHashedUploadDirectory; $this->name = $name; $this->title = Title::makeTitleSafe( NS_IMAGE, $this->name ); //$this->imagePath = wfImagePath( $name ); - $hash = md5( $this->title->getDBkey() ); - $this->imagePath = $wgUploadDirectory . '/' . $hash{0} . '/' .substr( $hash, 0, 2 ) . "/{$name}"; + if ($wgHashedUploadDirectory) { + $hash = md5( $this->title->getDBkey() ); + $this->imagePath = $wgUploadDirectory . '/' . $hash{0} . '/' . + substr( $hash, 0, 2 ) . "/{$name}"; + } else { + $this->imagePath = $wgUploadDirectory . '/' . $name; + } $this->url = $this->wfImageUrl( $name ); @@ -114,11 +119,14 @@ class Image function wfImageUrl( $name ) { - global $wgUploadPath,$wgUploadBaseUrl; - $hash = md5( $name ); - - $url = "{$wgUploadBaseUrl}{$wgUploadPath}/" . $hash{0} . "/" . - substr( $hash, 0, 2 ) . "/{$name}"; + global $wgUploadPath,$wgUploadBaseUrl,$wgHashedUploadDirectory; + if ($wgHashedUploadDirectory) { + $hash = md5( $name ); + $url = "{$wgUploadBaseUrl}{$wgUploadPath}/" . $hash{0} . "/" . + substr( $hash, 0, 2 ) . "/{$name}"; + } else { + $url = "{$wgUploadBaseUrl}{$wgUploadPath}/{$name}"; + } return wfUrlencode( $url ); } @@ -128,11 +136,15 @@ class Image } function thumbUrl( $width, $subdir='thumb' ) { - global $wgUploadPath; - + global $wgUploadPath,$wgHashedUploadDirectory; $name = $this->thumbName( $width ); - $hash = md5( $name ); - $url = "{$wgUploadPath}/{$subdir}/" . $hash{0} . "/" . substr( $hash, 0, 2 ) . "/{$name}"; + if ($wgHashedUploadDirectory) { + $hash = md5( $name ); + $url = "{$wgUploadPath}/{$subdir}/" . $hash{0} . "/" . + substr( $hash, 0, 2 ) . "/{$name}"; + } else { + $url = "{$wgUploadPath}/{$subdir}/{$name}"; + } return wfUrlencode($url); } @@ -335,7 +347,9 @@ class Image function wfImageDir( $fname ) { - global $wgUploadDirectory; + global $wgUploadDirectory, $wgHashedUploadDirectory; + + if (!$wgHashedUploadDirectory) { return $wgUploadDirectory; } $hash = md5( $fname ); $oldumask = umask(0); @@ -355,7 +369,9 @@ function wfImageThumbDir( $fname , $subdir='thumb') function wfImageArchiveDir( $fname , $subdir='archive') { - global $wgUploadDirectory; + global $wgUploadDirectory, $wgHashedUploadDirectory; + + if (!$wgHashedUploadDirectory) { return $wgUploadDirectory.'/'.$subdir; } $hash = md5( $fname ); $oldumask = umask(0); @@ -485,13 +501,17 @@ function wfRecordUpload( $name, $oldver, $size, $desc, $copyStatus = "", $source $log->addEntry( 'upload', $descTitle, $desc ); } -function wfImageArchiveUrl( $name ) +function wfImageArchiveUrl( $name, $subdir='archive' ) { - global $wgUploadPath; + global $wgUploadPath, $wgHashedUploadDirectory; - $hash = md5( substr( $name, 15) ); - $url = $wgUploadPath.'/archive/' . $hash{0} . '/' . - substr( $hash, 0, 2 ) . '/'.$name; + if ($wgHashedUploadDirectory) { + $hash = md5( substr( $name, 15) ); + $url = $wgUploadPath.'/'.$subdir.'/' . $hash{0} . '/' . + substr( $hash, 0, 2 ) . '/'.$name; + } else { + $url = $wgUploadPath.'/'.$subdir.'/'.$name; + } return wfUrlencode($url); } -- 2.20.1