}
function Image( $title ) {
- global $wgShowEXIF;
-
if( !is_object( $title ) ) {
wfDebugDieBacktrace( 'Image constructor given bogus title.' );
}
'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.
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;
function renderThumb( $width, $useScript = true ) {
global $wgUseSquid, $wgInternalServer;
global $wgThumbnailScriptPath, $wgSharedThumbnailScriptPath;
+
+ $fname = 'Image::renderThumb';
+ wfProfileIn( $fname );
- $width = IntVal( $width );
+ $width = intval( $width );
$this->load();
if ( ! $this->exists() )
{
# If there is no image, there will be no thumbnail
+ wfProfileOut( $fname );
return null;
}
# Sanity check $width
if( $width <= 0 || $this->width <= 0) {
# BZZZT
+ wfProfileOut( $fname );
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
- return new ThumbnailImage( $this->getViewURL(), $this->getWidth(), $this->getHeight() );
+ $thumb = new ThumbnailImage( $this->getViewURL(), $this->getWidth(), $this->getHeight() );
+ wfProfileOut( $fname );
+ return $thumb;
}
$height = floor( $this->height * ( $width/$this->width ) );
list( $isScriptUrl, $url ) = $this->thumbUrl( $width );
if ( $isScriptUrl && $useScript ) {
// Use thumb.php to render the image
- return new ThumbnailImage( $url, $width, $height );
+ $thumb = new ThumbnailImage( $url, $width, $height );
+ wfProfileOut( $fname );
+ return $thumb;
}
$thumbName = $this->thumbName( $width, $this->fromSharedDirectory );
}
}
- return new ThumbnailImage( $url, $width, $height, $thumbPath );
+ $thumb = new ThumbnailImage( $url, $width, $height, $thumbPath );
+ wfProfileOut( $fname );
+ return $thumb;
} // END OF function renderThumb
/**
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;
# 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.
/**
* Record an image upload in the upload log and the image table
*/
- function recordUpload( $oldver, $desc, $copyStatus = '', $source = '' ) {
+ function recordUpload( $oldver, $desc, $license = '', $copyStatus = '', $source = '' ) {
global $wgUser, $wgLang, $wgTitle, $wgDeferredUpdateList;
global $wgUseCopyrightUpload, $wgUseSquid, $wgPostCommitUpdateList;
}
if ( $wgUseCopyrightUpload ) {
+ if ( $license != '' ) {
+ $licensetxt = '== ' . wfMsg( 'license' ) . " ==\n" . '{{' . $license . '}}' . "\n";
+ }
$textdesc = '== ' . wfMsg ( 'filedesc' ) . " ==\n" . $desc . "\n" .
'== ' . wfMsg ( 'filestatus' ) . " ==\n" . $copyStatus . "\n" .
+ "$licensetxt" .
'== ' . wfMsg ( 'filesource' ) . " ==\n" . $source ;
} else {
- $textdesc = $desc;
+ if ( $license != '' ) {
+ $filedesc = $desc == '' ? '' : '== ' . wfMsg ( 'filedesc' ) . " ==\n" . $desc . "\n";
+ $textdesc = $filedesc .
+ '== ' . wfMsg ( 'license' ) . " ==\n" . '{{' . $license . '}}' . "\n";
+ } else {
+ $textdesc = $desc;
+ }
}
$now = $dbw->timestamp();
array(
'img_name' => $this->name,
'img_size'=> $this->size,
- 'img_width' => IntVal( $this->width ),
- 'img_height' => IntVal( $this->height ),
+ 'img_width' => intval( $this->width ),
+ 'img_height' => intval( $this->height ),
'img_bits' => $this->bits,
'img_media_type' => $this->type,
'img_major_mime' => $major,
}
}
$db->freeResult( $res );
+ wfProfileOut( $fname );
return $retVal;
}
/**
*
* @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();
}
$fname
);
}
+
+ /**
+ * Returns true if the image does not come from the shared
+ * image repository.
+ *
+ * @return bool
+ */
+ function isLocal() {
+ return !$this->fromSharedDirectory;
+ }
} //class
'' => 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 ) ) {
- $length = FloatVal( $matches[1] );
+ 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] );
} else {
// Assume pixels
- return round( FloatVal( $length ) );
+ return round( floatval( $length ) );
}
}