moved some more functions from GlobalFunctions to Image
authorJens Frank <jeluf@users.mediawiki.org>
Tue, 4 May 2004 20:35:37 +0000 (20:35 +0000)
committerJens Frank <jeluf@users.mediawiki.org>
Tue, 4 May 2004 20:35:37 +0000 (20:35 +0000)
includes/GlobalFunctions.php
includes/Image.php
includes/ImagePage.php

index 03392a2..e52d688 100644 (file)
@@ -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 )
 {
index ed69912..c183d46 100644 (file)
@@ -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;
+}
index 9dcad80..eb6d337 100644 (file)
@@ -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);
                }