* using htmlspecialchars() for safe XHTML output
[lhc/web/wiklou.git] / includes / Image.php
index bbf1d42..6644084 100644 (file)
@@ -195,7 +195,7 @@ class Image
                                'metadata'   => $this->metadata,
                                'size'       => $this->size );
 
-                       $wgMemc->set( $keys[0], $cachedValues );
+                       $wgMemc->set( $keys[0], $cachedValues, 60 * 60 * 24 * 7 ); // A week
                } else {
                        // However we should clear them, so they aren't leftover
                        // if we've deleted the file.
@@ -580,7 +580,7 @@ class Image
                
                if (!$mime || $mime==='unknown' || $mime==='unknown/unknown') return false;
                
-               #if it's SVG, check if ther's a converter enabled    
+               #if it's SVG, check if there's a converter enabled    
                if ($mime === 'image/svg') {
                        global $wgSVGConverters, $wgSVGConverter;
                        
@@ -934,7 +934,11 @@ class Image
                        return null;
                }
 
-               if( $width >= $this->width && !$this->mustRender() ) {
+               global $wgSVGMaxSize;
+               $maxsize = $this->mustRender()
+                       ? max( $this->width, $wgSVGMaxSize )
+                       : $this->width - 1;
+               if( $width > $maxsize ) {
                        # Don't make an image bigger than the source
                        $thumb = new ThumbnailImage( $this->getViewURL(), $this->getWidth(), $this->getHeight() );
                        wfProfileOut( $fname );
@@ -1007,12 +1011,14 @@ class Image
                        if( isset( $wgSVGConverters[$wgSVGConverter] ) ) {
                                global $wgSVGConverterPath;
                                $cmd = str_replace(
-                                       array( '$path/', '$width', '$input', '$output' ),
-                                       array( $wgSVGConverterPath,
-                                                  $width,
+                                       array( '$path/', '$width', '$height', '$input', '$output' ),
+                                       array( $wgSVGConverterPath ? "$wgSVGConverterPath/" : "",
+                                                  intval( $width ),
+                                                  intval( $height ),
                                                   wfEscapeShellArg( $this->imagePath ),
                                                   wfEscapeShellArg( $thumbPath ) ),
                                        $wgSVGConverters[$wgSVGConverter] );
+                               wfDebug( "reallyRenderThumb SVG: $cmd\n" );
                                $conv = shell_exec( $cmd );
                        } else {
                                $conv = false;
@@ -1022,10 +1028,10 @@ class Image
                        # Specify white background color, will be used for transparent images
                        # in Internet Explorer/Windows instead of default black.
                        $cmd  =  $wgImageMagickConvertCommand .
-                               " -quality 85 -background white -geometry {$width} ".
-                               wfEscapeShellArg($this->imagePath) . " " .
+                               " -quality 85 -background white -size {$width}x{$height} ".
+                               wfEscapeShellArg($this->imagePath) . " -resize {$width}x{$height} " .
                                wfEscapeShellArg($thumbPath);                           
-                       wfDebug("reallyRenderThumb: running ImageMagick: $cmd");
+                       wfDebug("reallyRenderThumb: running ImageMagick: $cmd\n");
                        $conv = shell_exec( $cmd );
                } else {
                        # Use PHP's builtin GD library functions.
@@ -1253,7 +1259,7 @@ class Image
        /**
         * Record an image upload in the upload log and the image table
         */
-       function recordUpload( $oldver, $desc, $license, $copyStatus = '', $source = '' ) {
+       function recordUpload( $oldver, $desc, $license = '', $copyStatus = '', $source = '' ) {
                global $wgUser, $wgLang, $wgTitle, $wgDeferredUpdateList;
                global $wgUseCopyrightUpload, $wgUseSquid, $wgPostCommitUpdateList;
 
@@ -1421,6 +1427,7 @@ class Image
                        }
                }
                $db->freeResult( $res );
+               wfProfileOut( $fname );
                return $retVal;
        }
        /**
@@ -1431,30 +1438,33 @@ class Image
         *
         * @return array
         */
-       function retrieveExifData () {
-               if ( $this->getMimeType() !== "image/jpeg" ) return array ();
+       function retrieveExifData() {
+               if ( $this->getMimeType() !== "image/jpeg" ) 
+                       return array();
 
                $exif = new Exif( $this->imagePath );
                return $exif->getFilteredData();
        }
                
-       function getExifData () {
+       function getExifData() {
                global $wgRequest;
                if ( $this->metadata === '0' )
                        return array();
                
                $purge = $wgRequest->getVal( 'action' ) == 'purge';
-               $ret = unserialize ( $this->metadata );
+               $ret = unserialize( $this->metadata );
 
                $oldver = isset( $ret['MEDIAWIKI_EXIF_VERSION'] ) ? $ret['MEDIAWIKI_EXIF_VERSION'] : 0;
                $newver = Exif::version();
                
                if ( !count( $ret ) || $purge || $oldver != $newver ) {
+                       $this->purgeCache();
                        $this->updateExifData( $newver );
                }
                if ( isset( $ret['MEDIAWIKI_EXIF_VERSION'] ) )
                        unset( $ret['MEDIAWIKI_EXIF_VERSION'] );
                $format = new FormatExif( $ret );
+               
                return $format->getFormattedData();
        }
 
@@ -1484,6 +1494,16 @@ class Image
                        $fname
                );
        }
+       
+       /**
+        * Returns true if the image does not come from the shared
+        * image repository.
+        *
+        * @return bool
+        */
+       function isLocal() {
+               return !$this->fromSharedDirectory;
+       }
 
 } //class
 
@@ -1652,7 +1672,7 @@ function wfScaleSVGUnit( $length ) {
                ''   => 1.0, // "User units" pixels by default
                '%'  => 2.0, // Fake it!
                );
-       if( preg_match( '/^(\d+)(em|ex|px|pt|pc|cm|mm|in|%|)$/', $length, $matches ) ) {
+       if( preg_match( '/^(\d+(?:\.\d+)?)(em|ex|px|pt|pc|cm|mm|in|%|)$/', $length, $matches ) ) {
                $length = floatval( $matches[1] );
                $unit = $matches[2];
                return round( $length * $unitLength[$unit] );