/** * @param $filename String * @param $expected String Serialized array * @dataProvider dataGetMetadata */ public function testGetMetadata($filename, $expected) { $file = UnregisteredLocalFile::newFromPath($this->filePath . $filename, 'image/png'); $actual = $this->handler->getMetadata($file, $this->filePath . $filename); // $this->assertEquals( unserialize( $expected ), unserialize( $actual ) ); $this->assertEquals($expected, $actual); }
public function testInvalidDate() { global $wgShowEXIF; if (!$wgShowEXIF) { $this->markTestIncomplete("This test needs the exif extension."); } $file = UnregisteredLocalFile::newFromPath(dirname(__FILE__) . '/../../data/media/broken_exif_date.jpg', 'image/jpeg'); // Throws an error if bug hit $meta = $file->formatMetadata(); $this->assertNotEquals(false, $meta, 'Valid metadata extracted'); // Find date exif entry $this->assertArrayHasKey('visible', $meta); $dateIndex = null; foreach ($meta['visible'] as $i => $data) { if ($data['id'] == 'exif-datetimeoriginal') { $dateIndex = $i; } } $this->assertNotNull($dateIndex, 'Date entry exists in metadata'); $this->assertEquals('0000:01:00 00:02:27', $meta['visible'][$dateIndex]['value'], 'File with invalid date metadata (bug 29471)'); }
public function execute() { $handler = new PagedTiffHandler(); $path = $this->mArgs[0]; $file = UnregisteredLocalFile::newFromPath($path, "image/tiff"); $metadata = $handler->getMetadata( $file, $path ); if ( !$metadata ) { print "FAILED! \n"; return; } $metadata = unserialize( $metadata ); if ( !$metadata ) { print "BROKEN! \n"; return; } print_r($metadata); }
function imageInfo($filename) { $info = array('width' => 0, 'height' => 0, 'bits' => 0, 'media' => '', 'major' => '', 'minor' => ''); $magic = MimeMagic::singleton(); $mime = $magic->guessMimeType($filename, true); list($info['major'], $info['minor']) = explode('/', $mime); $info['media'] = $magic->getMediaType($filename, $mime); $image = UnregisteredLocalFile::newFromPath($filename, $mime); $info['width'] = $image->getWidth(); $info['height'] = $image->getHeight(); $gis = $image->getImageSize($filename); if (isset($gis['bits'])) { $info['bits'] = $gis['bits']; } return $info; }
/** * Same as before, but with auto-rotation disabled. * @dataProvider providerFilesNoAutoRotate */ function testMetadataNoAutoRotate($name, $type, $info) { global $wgEnableAutoRotation; $wgEnableAutoRotation = false; $file = UnregisteredLocalFile::newFromPath($this->filePath . $name, $type); $this->assertEquals($info['width'], $file->getWidth(), "{$name}: width check"); $this->assertEquals($info['height'], $file->getHeight(), "{$name}: height check"); $wgEnableAutoRotation = true; }
function execute() { global $wgRequest, $wgContLanguageCode; if ( !$this->scalerAccessRanges ) { $this->htmlError( 403, 'inplace_access_disabled' ); return false; } /** * Run access checks against REMOTE_ADDR rather than wfGetIP(), since we're not * giving access even to trusted proxies, only direct clients. */ $allowed = false; foreach ( $this->scalerAccessRanges as $range ) { if ( IP::isInRange( $_SERVER['REMOTE_ADDR'], $range ) ) { $allowed = true; break; } } if ( !$allowed ) { $this->htmlError( 403, 'inplace_access_denied' ); return false; } if ( !$wgRequest->wasPosted() ) { echo $this->dtd(); ?> <html> <head><title>inplace-scaler.php Test Interface</title></head> <body> <form method="post" action="inplace-scaler.php" enctype="multipart/form-data" > <p>File: <input type="file" name="data" /></p> <p>Width: <input type="text" name="width" /></p> <p>Page: <input type="page" name="page" /></p> <p><input type="submit" value="OK" /></p> </form> </body> </html> <?php return true; } $tempDir = $this->tmpDir . '/' . gmdate( self::$tempDirFormat ); if ( !is_dir( $tempDir ) ) { if ( !wfMkdirParents( $tempDir, null, __METHOD__ ) ) { $this->htmlError( 500, 'inplace_scaler_no_temp' ); return false; } } $name = $wgRequest->getFileName( 'data' ); $srcTemp = $wgRequest->getFileTempname( 'data' ); $params = $_REQUEST; unset( $params['file'] ); if ( get_magic_quotes_gpc() ) { $params = array_map( 'stripslashes', $params ); } $i = strrpos( $name, '.' ); $ext = File::normalizeExtension( $i ? substr( $name, $i + 1 ) : '' ); $magic = MimeMagic::singleton(); $mime = $magic->guessTypesForExtension( $ext ); $image = UnregisteredLocalFile::newFromPath( $srcTemp, $mime ); $handler = $image->getHandler(); if ( !$handler ) { $this->htmlError( 400, 'inplace_scaler_no_handler' ); return false; } if ( !isset( $params['page'] ) ) { $params['page'] = 1; } $srcWidth = $image->getWidth( $params['page'] ); $srcHeight = $image->getHeight( $params['page'] ); if ( $srcWidth <= 0 || $srcHeight <= 0 ) { $this->htmlError( 400, 'inplace_scaler_invalid_image' ); return false; } list( $dstExt, $dstMime ) = $handler->getThumbType( $ext, $mime ); if ( preg_match( '/[ \\n;=]/', $name ) ) { $dstName = "thumb.$ext"; } else { $dstName = $name; } if ( $dstExt != $ext ) { $dstName = "$dstName.$dstExt"; } $dstTemp = tempnam( $tempDir, 'mwimg' ); $thumb = $handler->doTransform( $image, $dstTemp, false, $params ); if ( !$thumb || $thumb->isError() ) { $error = $thumb ? $thumb->getHtmlMsg() : ''; $this->htmlErrorReal( 500, 'inplace_scaler_failed', array(''), $error ); unlink( $dstTemp ); return false; } $stat = stat( $dstTemp ); if ( !$stat ) { $this->htmlError( 500, 'inplace_scaler_no_output' ); return false; } if ( $stat['size'] == 0 ) { $this->htmlError( 500, 'inplace_scaler_no_output' ); unlink( $dstTemp ); return false; } wfDebug( __METHOD__.": transformation completed successfully, streaming output...\n" ); header( "Content-Type: $dstMime" ); header( "Content-Disposition: inline;filename*=utf-8'$wgContLanguageCode'" . urlencode( $dstName ) ); readfile( $dstTemp ); unlink( $dstTemp ); }
function execute() { global $wgRequest; if ( !$wgRequest->wasPosted() ) { echo $this->dtd(); ?> <html> <head><title>metadata.php Test interface</title> <body> <form method="post" action="metadata.php"> <p>Zone: <select name="zone" value="public"> <option>public</option> <option>temp</option> <option>deleted</option> </select> </p> <p>Relative path: <input type="text" name="path"></p> <p><input type="submit" value="OK" /></p> </form> </body></html> <?php return true; } $zone = $wgRequest->getVal( 'zone' ); $root = $this->getZoneRoot( $zone ); if ( strval( $root ) == '' ) { $this->error( 400, 'webstore_invalid_zone', $zone ); return false; } $rel = $wgRequest->getVal( 'path' ); if ( !$this->validateFilename( $rel ) ) { $this->error( 400, 'webstore_path_invalid' ); return false; } $fullPath = $root . '/' . $rel; $name = basename( $fullPath ); $i = strrpos( $name, '.' ); $ext = File::normalizeExtension( $i ? substr( $name, $i + 1 ) : '' ); $magic = MimeMagic::singleton(); $mime = $magic->guessTypesForExtension( $ext ); $type = $magic->getMediaType( $fullPath, $mime); $stat = stat( $fullPath ); if ( !$stat ) { $this->error( 400, 'webstore_metadata_not_found', $fullPath ); return false; } $image = UnregisteredLocalFile::newFromPath( $fullPath, $mime ); if ( !$image->getHandler() ) { $this->error( 400, 'webstore_no_handler' ); return false; } $gis = $image->getImageSize(); $handlerMeta = $image->getMetadata(); $stat = stat( $fullPath ); $metadata = array( 'width' => $gis[0], 'height' => $gis[1], 'bits' => isset( $gis['bits'] ) ? $gis['bits'] : '', 'type' => $type, 'mime' => $mime, 'metadata' => $handlerMeta, 'size' => $stat['size'], ); header( 'Content-Type: text/xml' ); echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<response><status>success</status><metadata>\n"; foreach ( $metadata as $field => $value ) { if ( is_bool( $value ) ) { $value = $value ? 1 : 0; } echo "<item name=\"$field\">" . htmlspecialchars( $value ) . "</item>\n"; } echo "</metadata></response>\n"; }