From 144e0c2ed14c0e2cb4dd2502324bfd9b77b75b54 Mon Sep 17 00:00:00 2001 From: Jens Frank Date: Tue, 4 May 2004 20:35:37 +0000 Subject: [PATCH] moved some more functions from GlobalFunctions to Image --- includes/GlobalFunctions.php | 53 ++++++++++-------------------------- includes/Image.php | 35 ++++++++++++++++++++++-- includes/ImagePage.php | 4 +-- 3 files changed, 49 insertions(+), 43 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 03392a22aa..e52d688677 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -89,46 +89,21 @@ function wfFullUrlE( $a, $q = "" ) { } -function wfImagePath( $img ) -{ - global $wgUploadDirectory; - - $nt = Title::newFromText( $img ); - if( !$nt ) return ""; - - $name = $nt->getDBkey(); - $hash = md5( $name ); - - $path = "{$wgUploadDirectory}/" . $hash{0} . "/" . - substr( $hash, 0, 2 ) . "/{$name}"; - return $path; -} - -function wfThumbUrl( $img ) -{ - global $wgUploadPath; - - $nt = Title::newFromText( $img ); - if( !$nt ) return ""; +// orphan function wfThumbUrl( $img ) +//{ +// global $wgUploadPath; +// +// $nt = Title::newFromText( $img ); +// if( !$nt ) return ""; +// +// $name = $nt->getDBkey(); +// $hash = md5( $name ); +// +// $url = "{$wgUploadPath}/thumb/" . $hash{0} . "/" . +// substr( $hash, 0, 2 ) . "/{$name}"; +// return wfUrlencode( $url ); +//} - $name = $nt->getDBkey(); - $hash = md5( $name ); - - $url = "{$wgUploadPath}/thumb/" . $hash{0} . "/" . - substr( $hash, 0, 2 ) . "/{$name}"; - return wfUrlencode( $url ); -} - - -function wfImageThumbUrl( $name, $subdir="thumb" ) -{ - global $wgUploadPath; - - $hash = md5( $name ); - $url = "{$wgUploadPath}/{$subdir}/" . $hash{0} . "/" . - substr( $hash, 0, 2 ) . "/{$name}"; - return wfUrlencode($url); -} function wfImageArchiveUrl( $name ) { diff --git a/includes/Image.php b/includes/Image.php index ed69912a61..c183d46735 100644 --- a/includes/Image.php +++ b/includes/Image.php @@ -17,6 +17,7 @@ class Image $attr; # / + function Image( $name ) { $this->name = $name; @@ -88,15 +89,28 @@ class Image return $this->fileExists; } + function thumbUrl( $width, $subdir="thumb" ) { + global $wgUploadPath; + + $name = $this->thumbName( $width ); + $hash = md5( $name ); + $url = "{$wgUploadPath}/{$subdir}/" . $hash{0} . "/" . substr( $hash, 0, 2 ) . "/{$name}"; + + return wfUrlencode($url); + } + + function thumbName( $width ) { + return $width."px-".$this->name; + } function createThumb( $width ) { global $wgUploadDirectory; global $wgImageMagickConvertCommand; global $wgUseImageMagick; global $wgUseSquid, $wgInternalServer; - $thumbName = $width."px-".$this->name; + $thumbName = $this->thumbName( $width ); $thumbPath = wfImageThumbDir( $thumbName )."/".$thumbName; - $thumbUrl = wfImageThumbUrl( $thumbName ); + $thumbUrl = $this->thumbUrl( $width ); if ( ! $this->exists() ) { @@ -201,3 +215,20 @@ class Image } //function createThumb } //class + +// return path name of an image +// canonicalize name. +function wfImagePath( $imgname ) +{ + global $wgUploadDirectory; + + $nt = Title::newFromText( $imgname ); + if( !$nt ) return ""; + + $name = $nt->getDBkey(); + $hash = md5( $name ); + + $path = "{$wgUploadDirectory}/" . $hash{0} . "/" . + substr( $hash, 0, 2 ) . "/{$name}"; + return $path; +} diff --git a/includes/ImagePage.php b/includes/ImagePage.php index 9dcad80ebe..eb6d3374ab 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -186,7 +186,7 @@ class ImagePage extends Article { # Squid purging if ( $wgUseSquid ) { $urlArr = Array( - $wgInternalServer.wfImageUrl( $image ) + $wgInternalServer . Image::wfImageUrl( $image ) ); wfPurgeSquidServers($urlArr); } @@ -301,7 +301,7 @@ class ImagePage extends Article { if ( $wgUseSquid ) { $urlArr = Array( $wgInternalServer.wfImageArchiveUrl( $name ), - $wgInternalServer.wfImageUrl( $name ) + $wgInternalServer . Image::wfImageUrl( $name ) ); wfPurgeSquidServers($urlArr); } -- 2.20.1