Example #1
0
 protected function setUp()
 {
     parent::setUp();
     if (!wfDl('xml')) {
         $this->markTestSkipped('Requires libxml to do XMP parsing');
     }
 }
Example #2
0
 public function testIsOldBroken()
 {
     if (!wfDl('exif')) {
         $this->markTestIncomplete("This test needs the exif extension.");
     }
     $res = $this->handler->isMetadataValid(null, ExifBitmapHandler::OLD_BROKEN_FILE);
     $this->assertEquals(ExifBitmapHandler::METADATA_COMPATIBLE, $res);
 }
 protected function setUp()
 {
     parent::setUp();
     $this->setMwGlobals('wgShowEXIF', true);
     $this->handler = new ExifBitmapHandler();
     if (!wfDl('exif')) {
         $this->markTestSkipped("This test needs the exif extension.");
     }
 }
Example #4
0
 protected function setUp()
 {
     parent::setUp();
     $this->mediaPath = __DIR__ . '/../../data/media/';
     if (!wfDl('exif')) {
         $this->markTestSkipped("This test needs the exif extension.");
     }
     $this->setMwGlobals('wgShowEXIF', true);
 }
Example #5
0
 public function setUp()
 {
     global $wgShowEXIF;
     $this->showExif = $wgShowEXIF;
     $wgShowEXIF = true;
     $this->handler = new ExifBitmapHandler();
     if (!wfDl('exif')) {
         $this->markTestSkipped("This test needs the exif extension.");
     }
 }
Example #6
0
 public function setUp()
 {
     $this->mediaPath = __DIR__ . '/../../data/media/';
     if (!wfDl('exif')) {
         $this->markTestSkipped("This test needs the exif extension.");
     }
     global $wgShowEXIF;
     $this->showExif = $wgShowEXIF;
     $wgShowEXIF = true;
 }
Example #7
0
 public function setUp()
 {
     $this->filePath = dirname(__FILE__) . '/../../data/media/';
     if (!wfDl('exif')) {
         $this->markTestSkipped("This test needs the exif extension.");
     }
     global $wgShowEXIF;
     $this->show = $wgShowEXIF;
     $wgShowEXIF = true;
 }
Example #8
0
 protected function setUp()
 {
     parent::setUp();
     if (!wfDl('exif')) {
         $this->markTestSkipped("This test needs the exif extension.");
     }
     $filePath = __DIR__ . '/../../data/media';
     $this->backend = new FSFileBackend(array('name' => 'localtesting', 'lockManager' => 'nullLockManager', 'containerPaths' => array('data' => $filePath)));
     $this->repo = new FSRepo(array('name' => 'temp', 'url' => 'http://localhost/thumbtest', 'backend' => $this->backend));
     $this->setMwGlobals('wgShowEXIF', true);
 }
Example #9
0
 public function testTiffMetadataExtraction()
 {
     if (!wfDl('exif')) {
         $this->markTestIncomplete("This test needs the exif extension.");
     }
     $res = $this->handler->getMetadata(null, $this->filePath . 'test.tiff');
     $expected = 'a:16:{s:10:"ImageWidth";i:20;s:11:"ImageLength";i:20;s:13:"BitsPerSample";a:3:{i:0;i:8;i:1;i:8;i:2;i:8;}s:11:"Compression";i:5;s:25:"PhotometricInterpretation";i:2;s:16:"ImageDescription";s:17:"Created with GIMP";s:12:"StripOffsets";i:8;s:11:"Orientation";i:1;s:15:"SamplesPerPixel";i:3;s:12:"RowsPerStrip";i:64;s:15:"StripByteCounts";i:238;s:11:"XResolution";s:19:"1207959552/16777216";s:11:"YResolution";s:19:"1207959552/16777216";s:19:"PlanarConfiguration";i:1;s:14:"ResolutionUnit";i:2;s:22:"MEDIAWIKI_EXIF_VERSION";i:2;}';
     // Re-unserialize in case there are subtle differences between how versions
     // of php serialize stuff.
     $this->assertEquals(unserialize($expected), unserialize($res));
 }
Example #10
0
 public function setUp()
 {
     if (!wfDl('exif')) {
         $this->markTestSkipped("This test needs the exif extension.");
     }
     $filePath = dirname(__FILE__) . '/../../data/media';
     $this->backend = new FSFileBackend(array('name' => 'localtesting', 'lockManager' => 'nullLockManager', 'containerPaths' => array('data' => $filePath)));
     $this->repo = new FSRepo(array('name' => 'temp', 'url' => 'http://localhost/thumbtest', 'backend' => $this->backend));
     global $wgShowEXIF;
     $this->show = $wgShowEXIF;
     $wgShowEXIF = true;
 }
Example #11
0
 public function testUnicodeUserComment()
 {
     if (!wfDl('exif')) {
         $this->markTestIncomplete("This test needs the exif extension.");
     }
     $filename = $this->mediaPath . 'exif-user-comment.jpg';
     $seg = JpegMetadataExtractor::segmentSplitter($filename);
     $exif = new Exif($filename, $seg['byteOrder']);
     $data = $exif->getFilteredData();
     $expected = array('UserComment' => 'test⁔comment');
     $this->assertEquals($expected, $data);
 }
Example #12
0
 function setUp()
 {
     parent::setUp();
     $this->filePath = dirname(__FILE__) . '/../../data/media/';
     $this->handler = new BitmapHandler();
     $this->repo = new FSRepo(array('name' => 'temp', 'directory' => wfTempDir() . '/exif-test-' . time() . '-' . mt_rand(), 'url' => 'http://localhost/thumbtest'));
     if (!wfDl('exif')) {
         $this->markTestSkipped("This test needs the exif extension.");
     }
     global $wgShowEXIF;
     $this->show = $wgShowEXIF;
     $wgShowEXIF = true;
     global $wgEnableAutoRotation;
     $this->oldAuto = $wgEnableAutoRotation;
     $wgEnableAutoRotation = true;
 }
 function setUp()
 {
     parent::setUp();
     $this->handler = new BitmapHandler();
     $filePath = __DIR__ . '/../../data/media';
     $tmpDir = $this->getNewTempDirectory();
     $this->repo = new FSRepo(array('name' => 'temp', 'url' => 'http://localhost/thumbtest', 'backend' => new FSFileBackend(array('name' => 'localtesting', 'lockManager' => 'nullLockManager', 'containerPaths' => array('temp-thumb' => $tmpDir, 'data' => $filePath)))));
     if (!wfDl('exif')) {
         $this->markTestSkipped("This test needs the exif extension.");
     }
     global $wgShowEXIF;
     $this->show = $wgShowEXIF;
     $wgShowEXIF = true;
     global $wgEnableAutoRotation;
     $this->oldAuto = $wgEnableAutoRotation;
     $wgEnableAutoRotation = true;
 }
Example #14
0
 /**
  * Make sure the proper modules are loaded before we try to
  * make the diff
  */
 private function initDiffEngines()
 {
     global $wgExternalDiffEngine;
     if ($wgExternalDiffEngine == 'wikidiff' && !function_exists('wikidiff_do_diff')) {
         wfProfileIn(__METHOD__ . '-php_wikidiff.so');
         wfDl('php_wikidiff');
         wfProfileOut(__METHOD__ . '-php_wikidiff.so');
     } elseif ($wgExternalDiffEngine == 'wikidiff2' && !function_exists('wikidiff2_do_diff')) {
         wfProfileIn(__METHOD__ . '-php_wikidiff2.so');
         wfDl('wikidiff2');
         wfProfileOut(__METHOD__ . '-php_wikidiff2.so');
     }
 }
Example #15
0
 /** Initializes the MimeMagic object. This is called by MimeMagic::singleton().
  *
  * This constructor parses the mime.types and mime.info files and build internal mappings.
  */
 function __construct()
 {
     /**
      *   --- load mime.types ---
      */
     global $wgMimeTypeFile, $IP, $wgLoadFileinfoExtension;
     $types = MM_WELL_KNOWN_MIME_TYPES;
     if ($wgMimeTypeFile == 'includes/mime.types') {
         $wgMimeTypeFile = "{$IP}/{$wgMimeTypeFile}";
     }
     if ($wgLoadFileinfoExtension && !self::$extensionLoaded) {
         self::$extensionLoaded = true;
         wfDl('fileinfo');
     }
     if ($wgMimeTypeFile) {
         if (is_file($wgMimeTypeFile) and is_readable($wgMimeTypeFile)) {
             wfDebug(__METHOD__ . ": loading mime types from {$wgMimeTypeFile}\n");
             $types .= "\n";
             $types .= file_get_contents($wgMimeTypeFile);
         } else {
             wfDebug(__METHOD__ . ": can't load mime types from {$wgMimeTypeFile}\n");
         }
     } else {
         wfDebug(__METHOD__ . ": no mime types file defined, using build-ins only.\n");
     }
     $types = str_replace(array("\r\n", "\n\r", "\n\n", "\r\r", "\r"), "\n", $types);
     $types = str_replace("\t", " ", $types);
     $this->mMimeToExt = array();
     $this->mToMime = array();
     $lines = explode("\n", $types);
     foreach ($lines as $s) {
         $s = trim($s);
         if (empty($s)) {
             continue;
         }
         if (strpos($s, '#') === 0) {
             continue;
         }
         $s = strtolower($s);
         $i = strpos($s, ' ');
         if ($i === false) {
             continue;
         }
         $mime = substr($s, 0, $i);
         $ext = trim(substr($s, $i + 1));
         if (empty($ext)) {
             continue;
         }
         if (!empty($this->mMimeToExt[$mime])) {
             $this->mMimeToExt[$mime] .= ' ' . $ext;
         } else {
             $this->mMimeToExt[$mime] = $ext;
         }
         $extensions = explode(' ', $ext);
         foreach ($extensions as $e) {
             $e = trim($e);
             if (empty($e)) {
                 continue;
             }
             if (!empty($this->mExtToMime[$e])) {
                 $this->mExtToMime[$e] .= ' ' . $mime;
             } else {
                 $this->mExtToMime[$e] = $mime;
             }
         }
     }
     /**
      *   --- load mime.info ---
      */
     global $wgMimeInfoFile;
     if ($wgMimeInfoFile == 'includes/mime.info') {
         $wgMimeInfoFile = "{$IP}/{$wgMimeInfoFile}";
     }
     $info = MM_WELL_KNOWN_MIME_INFO;
     if ($wgMimeInfoFile) {
         if (is_file($wgMimeInfoFile) and is_readable($wgMimeInfoFile)) {
             wfDebug(__METHOD__ . ": loading mime info from {$wgMimeInfoFile}\n");
             $info .= "\n";
             $info .= file_get_contents($wgMimeInfoFile);
         } else {
             wfDebug(__METHOD__ . ": can't load mime info from {$wgMimeInfoFile}\n");
         }
     } else {
         wfDebug(__METHOD__ . ": no mime info file defined, using build-ins only.\n");
     }
     $info = str_replace(array("\r\n", "\n\r", "\n\n", "\r\r", "\r"), "\n", $info);
     $info = str_replace("\t", " ", $info);
     $this->mMimeTypeAliases = array();
     $this->mMediaTypes = array();
     $lines = explode("\n", $info);
     foreach ($lines as $s) {
         $s = trim($s);
         if (empty($s)) {
             continue;
         }
         if (strpos($s, '#') === 0) {
             continue;
         }
         $s = strtolower($s);
         $i = strpos($s, ' ');
         if ($i === false) {
             continue;
         }
         #print "processing MIME INFO line $s<br>";
         $match = array();
         if (preg_match('!\\[\\s*(\\w+)\\s*\\]!', $s, $match)) {
             $s = preg_replace('!\\[\\s*(\\w+)\\s*\\]!', '', $s);
             $mtype = trim(strtoupper($match[1]));
         } else {
             $mtype = MEDIATYPE_UNKNOWN;
         }
         $m = explode(' ', $s);
         if (!isset($this->mMediaTypes[$mtype])) {
             $this->mMediaTypes[$mtype] = array();
         }
         foreach ($m as $mime) {
             $mime = trim($mime);
             if (empty($mime)) {
                 continue;
             }
             $this->mMediaTypes[$mtype][] = $mime;
         }
         if (sizeof($m) > 1) {
             $main = $m[0];
             for ($i = 1; $i < sizeof($m); $i += 1) {
                 $mime = $m[$i];
                 $this->mMimeTypeAliases[$mime] = $main;
             }
         }
     }
 }
 /**
  * Convenience function.
  * Check if a named extension is present.
  *
  * @see wfDl
  * @param $name
  * @return bool
  */
 protected static function checkExtension($name)
 {
     wfSuppressWarnings();
     $compiled = wfDl($name);
     wfRestoreWarnings();
     return $compiled;
 }
 /**
  * Opens a database connection and returns it
  * Closes any existing connection
  *
  * @param $server String: hostname
  * @param $user String
  * @param $password String
  * @param $dbName String: database name
  * @throws DBConnectionError
  * @return DatabaseBase a fresh connection
  */
 public function open($server, $user, $password, $dbName)
 {
     wfProfileIn(__METHOD__);
     # Load IBM DB2 driver if missing
     wfDl('ibm_db2');
     # Test for IBM DB2 support, to avoid suppressed fatal error
     if (!function_exists('db2_connect')) {
         throw new DBConnectionError($this, "DB2 functions missing, have you enabled the ibm_db2 extension for PHP?");
     }
     global $wgDBport;
     // Close existing connection
     $this->close();
     // Cache conn info
     $this->mServer = $server;
     $this->mPort = $port = $wgDBport;
     $this->mUser = $user;
     $this->mPassword = $password;
     $this->mDBname = $dbName;
     $this->openUncataloged($dbName, $user, $password, $server, $port);
     if (!$this->mConn) {
         $this->installPrint("DB connection error\n");
         $this->installPrint("Server: {$server}, Database: {$dbName}, User: {$user}, Password: "******"...\n");
         $this->installPrint($this->lastError() . "\n");
         wfProfileOut(__METHOD__);
         wfDebug("DB connection error\n");
         wfDebug("Server: {$server}, Database: {$dbName}, User: {$user}, Password: "******"...\n");
         wfDebug($this->lastError() . "\n");
         throw new DBConnectionError($this, $this->lastError());
     }
     // Some MediaWiki code is still transaction-less (?).
     // The strategy is to keep AutoCommit on for that code
     //  but switch it off whenever a transaction is begun.
     db2_autocommit($this->mConn, DB2_AUTOCOMMIT_ON);
     $this->mOpened = true;
     $this->applySchema();
     wfProfileOut(__METHOD__);
     return $this->mConn;
 }
 public function testPNGXMP()
 {
     if (!wfDl('xml')) {
         $this->markTestSkipped("This test needs the xml extension.");
     }
     $handler = new BitmapMetadataHandler();
     $result = $handler->png($this->filePath . 'xmp.png');
     $expected = array('frameCount' => 0, 'loopCount' => 1, 'duration' => 0, 'bitDepth' => 1, 'colorType' => 'index-coloured', 'metadata' => array('SerialNumber' => '123456789', '_MW_PNG_VERSION' => 1));
     $this->assertEquals($expected, $result);
 }
Example #19
0
 function open($server, $user, $password, $dbName)
 {
     global $wgAllDBsAreLocalhost;
     wfProfileIn(__METHOD__);
     # Load mysql.so if we don't have it
     wfDl('mysql');
     # Fail now
     # Otherwise we get a suppressed fatal error, which is very hard to track down
     if (!function_exists('mysql_connect')) {
         throw new DBConnectionError($this, "MySQL functions missing, have you compiled PHP with the --with-mysql option?\n");
     }
     # Debugging hack -- fake cluster
     if ($wgAllDBsAreLocalhost) {
         $realServer = 'localhost';
     } else {
         $realServer = $server;
     }
     $this->close();
     $this->mServer = $server;
     $this->mUser = $user;
     $this->mPassword = $password;
     $this->mDBname = $dbName;
     wfProfileIn("dbconnect-{$server}");
     # The kernel's default SYN retransmission period is far too slow for us,
     # so we use a short timeout plus a manual retry. Retrying means that a small
     # but finite rate of SYN packet loss won't cause user-visible errors.
     $this->mConn = false;
     if (ini_get('mysql.connect_timeout') <= 3) {
         $numAttempts = 2;
     } else {
         $numAttempts = 1;
     }
     $this->installErrorHandler();
     for ($i = 0; $i < $numAttempts && !$this->mConn; $i++) {
         if ($i > 1) {
             usleep(1000);
         }
         if ($this->mFlags & DBO_PERSISTENT) {
             $this->mConn = mysql_pconnect($realServer, $user, $password);
         } else {
             # Create a new connection...
             $this->mConn = mysql_connect($realServer, $user, $password, true);
         }
         #if ( $this->mConn === false ) {
         #$iplus = $i + 1;
         #wfLogDBError("Connect loop error $iplus of $max ($server): " . mysql_errno() . " - " . mysql_error()."\n");
         #}
     }
     $phpError = $this->restoreErrorHandler();
     # Always log connection errors
     if (!$this->mConn) {
         $error = $this->lastError();
         if (!$error) {
             $error = $phpError;
         }
         wfLogDBError("Error connecting to {$this->mServer}: {$error}\n");
         wfDebug("DB connection error\n");
         wfDebug("Server: {$server}, User: {$user}, Password: "******"..., error: " . mysql_error() . "\n");
     }
     wfProfileOut("dbconnect-{$server}");
     if ($dbName != '' && $this->mConn !== false) {
         wfSuppressWarnings();
         $success = mysql_select_db($dbName, $this->mConn);
         wfRestoreWarnings();
         if (!$success) {
             $error = "Error selecting database {$dbName} on server {$this->mServer} " . "from client host " . wfHostname() . "\n";
             wfLogDBError(" Error selecting database {$dbName} on server {$this->mServer} \n");
             wfDebug($error);
         }
     } else {
         # Delay USE query
         $success = (bool) $this->mConn;
     }
     if ($success) {
         $version = $this->getServerVersion();
         if (version_compare($version, '4.1') >= 0) {
             // Tell the server we're communicating with it in UTF-8.
             // This may engage various charset conversions.
             global $wgDBmysql5;
             if ($wgDBmysql5) {
                 $this->query('SET NAMES utf8', __METHOD__);
             } else {
                 $this->query('SET NAMES binary', __METHOD__);
             }
             // Set SQL mode, default is turning them all off, can be overridden or skipped with null
             global $wgSQLMode;
             if (is_string($wgSQLMode)) {
                 $mode = $this->addQuotes($wgSQLMode);
                 $this->query("SET sql_mode = {$mode}", __METHOD__);
             }
         }
         // Turn off strict mode if it is on
     } else {
         $this->reportConnectionError($phpError);
     }
     $this->mOpened = $success;
     wfProfileOut(__METHOD__);
     return $success;
 }
Example #20
0
image/tiff [BITMAP]
image/vnd.djvu [BITMAP]
image/x-xcf [BITMAP]
image/x-portable-pixmap [BITMAP]
text/plain [TEXT]
text/html [TEXT]
video/ogg [VIDEO]
video/mpeg [VIDEO]
unknown/unknown application/octet-stream application/x-empty [UNKNOWN]
END_STRING
);
#note: because this file is possibly included by a function,
#we need to access the global scope explicitely!
global $wgLoadFileinfoExtension;
if ($wgLoadFileinfoExtension) {
    wfDl('fileinfo');
}
/**
 * Implements functions related to mime types such as detection and mapping to
 * file extension.
 *
 * Instances of this class are stateles, there only needs to be one global instance
 * of MimeMagic. Please use MimeMagic::singleton() to get that instance.
 */
class MimeMagic
{
    /**
     * Mapping of media types to arrays of mime types.
     * This is used by findMediaType and getMediaType, respectively
     */
    var $mMediaTypes = null;
Example #21
0
 function setUp()
 {
     if (!wfDl('xml')) {
         $this->markTestSkipped('Requires libxml to do XMP parsing');
     }
 }