/**
  * get video data from file
  * @param File $file
  * @param boolean $premiumOnly
  * @return array|null  $video
  */
 public function getVideoDataByFile($file, $premiumOnly = false)
 {
     $app = F::app();
     $app->wf->ProfileIn(__METHOD__);
     $video = null;
     if ($file instanceof File && $file->exists() && F::build('WikiaFileHelper', array($file), 'isFileTypeVideo')) {
         if (!($premiumOnly && $file->isLocal())) {
             $fileMetadata = $file->getMetadata();
             $userId = $file->getUser('id');
             $addedAt = $file->getTimestamp() ? $file->getTimestamp() : $this->wf->Timestamp(TS_MW);
             $duration = 0;
             $hdfile = 0;
             if ($fileMetadata) {
                 $fileMetadata = unserialize($fileMetadata);
                 if (array_key_exists('duration', $fileMetadata)) {
                     $duration = $fileMetadata['duration'];
                 }
                 if (array_key_exists('hd', $fileMetadata)) {
                     $hdfile = $fileMetadata['hd'] ? 1 : 0;
                 }
             }
             $premium = $file->isLocal() ? 0 : 1;
             $video = array('videoTitle' => $file->getTitle()->getDBKey(), 'addedAt' => $addedAt, 'addedBy' => $userId, 'duration' => $duration, 'premium' => $premium, 'hdfile' => $hdfile);
         }
     }
     $app->wf->ProfileOut(__METHOD__);
     return $video;
 }
Example #2
0
 /**
  * @param File $image
  * @return bool
  */
 function isAnimatedImage($image)
 {
     $ser = $image->getMetadata();
     if ($ser) {
         $metadata = unserialize($ser);
         if ($metadata['frameCount'] > 1) {
             return true;
         }
     }
     return false;
 }
Example #3
0
 /**
  * On supporting image formats, try to read out the low-level orientation
  * of the file and return the angle that the file needs to be rotated to
  * be viewed.
  *
  * This information is only useful when manipulating the original file;
  * the width and height we normally work with is logical, and will match
  * any produced output views.
  *
  * @param File $file
  * @return int 0, 90, 180 or 270
  */
 public function getRotation($file)
 {
     if (!$this->autoRotateEnabled()) {
         return 0;
     }
     $data = $file->getMetadata();
     return $this->getRotationForExif($data);
 }
Example #4
0
 public function getCommonMetaArray(File $file)
 {
     $metadata = $file->getMetadata();
     if (!$metadata) {
         return array();
     }
     $metadata = $this->unpackMetadata($metadata);
     if (!$metadata || isset($metadata['error'])) {
         return array();
     }
     $stdMetadata = array();
     foreach ($metadata as $name => $value) {
         $tag = strtolower($name);
         if ($tag === 'originalwidth' || $tag === 'originalheight') {
             // Skip these. In the exif metadata stuff, it is assumed these
             // are measured in px, which is not the case here.
             continue;
         }
         if (isset(self::$metaConversion[$tag])) {
             $tag = self::$metaConversion[$tag];
             $stdMetadata[$tag] = $value;
         }
     }
     return $stdMetadata;
 }
Example #5
0
 /**
  * Return the duration of an APNG file.
  *
  * Shown in the &query=imageinfo&iiprop=size api query.
  *
  * @param File $file
  * @return float The duration of the file.
  */
 public function getLength($file)
 {
     $serMeta = $file->getMetadata();
     MediaWiki\suppressWarnings();
     $metadata = unserialize($serMeta);
     MediaWiki\restoreWarnings();
     if (!$metadata || !isset($metadata['duration']) || !$metadata['duration']) {
         return 0.0;
     } else {
         return (double) $metadata['duration'];
     }
 }
Example #6
0
 /**
  * Get metadata, unserializing it if neccessary.
  *
  * @param File $file The DjVu file in question
  * @return string XML metadata as a string.
  */
 private function getUnserializedMetadata(File $file)
 {
     $metadata = $file->getMetadata();
     if (substr($metadata, 0, 3) === '<?xml') {
         // Old style. Not serialized but instead just a raw string of XML.
         return $metadata;
     }
     wfSuppressWarnings();
     $unser = unserialize($metadata);
     wfRestoreWarnings();
     if (is_array($unser)) {
         if (isset($unser['error'])) {
             return false;
         } elseif (isset($unser['xml'])) {
             return $unser['xml'];
         } else {
             // Should never ever reach here.
             throw new MWException("Error unserializing DjVu metadata.");
         }
     }
     // unserialize failed. Guess it wasn't really serialized after all,
     return $metadata;
 }
Example #7
0
 /**
  * Can we render this file?
  *
  * Image magick doesn't support indexed xcf files as of current
  * writing (as of 6.8.9-3)
  * @param File $file
  * @return bool
  */
 public function canRender($file)
 {
     MediaWiki\suppressWarnings();
     $xcfMeta = unserialize($file->getMetadata());
     MediaWiki\restoreWarnings();
     if (isset($xcfMeta['colorType']) && $xcfMeta['colorType'] === 'index-coloured') {
         return false;
     }
     return parent::canRender($file);
 }
Example #8
0
 /**
  * Cache a document tree for the DjVu XML metadata
  * @param File $image
  * @param bool $gettext DOCUMENT (Default: false)
  * @return bool|SimpleXMLElement
  */
 function getMetaTree($image, $gettext = false)
 {
     if ($gettext && isset($image->djvuTextTree)) {
         return $image->djvuTextTree;
     }
     if (!$gettext && isset($image->dejaMetaTree)) {
         return $image->dejaMetaTree;
     }
     $metadata = $image->getMetadata();
     if (!$this->isMetadataValid($image, $metadata)) {
         wfDebug("DjVu XML metadata is invalid or missing, should have been fixed in upgradeRow\n");
         return false;
     }
     wfProfileIn(__METHOD__);
     wfSuppressWarnings();
     try {
         // Set to false rather than null to avoid further attempts
         $image->dejaMetaTree = false;
         $image->djvuTextTree = false;
         $tree = new SimpleXMLElement($metadata);
         if ($tree->getName() == 'mw-djvu') {
             /** @var SimpleXMLElement $b */
             foreach ($tree->children() as $b) {
                 if ($b->getName() == 'DjVuTxt') {
                     // @todo File::djvuTextTree and File::dejaMetaTree are declared
                     // dynamically. Add a public File::$data to facilitate this?
                     $image->djvuTextTree = $b;
                 } elseif ($b->getName() == 'DjVuXML') {
                     $image->dejaMetaTree = $b;
                 }
             }
         } else {
             $image->dejaMetaTree = $tree;
         }
     } catch (Exception $e) {
         wfDebug("Bogus multipage XML metadata on '{$image->getName()}'\n");
     }
     wfRestoreWarnings();
     wfProfileOut(__METHOD__);
     if ($gettext) {
         return $image->djvuTextTree;
     } else {
         return $image->dejaMetaTree;
     }
 }
Example #9
0
 /**
  * @param File $image
  * @return bool
  */
 public function isAnimatedImage($image)
 {
     $ser = $image->getMetadata();
     if ($ser) {
         $metadata = unserialize($ser);
         if (isset($metadata['animated']) && $metadata['animated'] === true) {
             return true;
         }
     }
     return false;
 }
Example #10
0
 public function getCommonMetaArray(File $file)
 {
     $metadata = $file->getMetadata();
     if ($metadata === self::OLD_BROKEN_FILE || $metadata === self::BROKEN_FILE || $this->isMetadataValid($file, $metadata) === self::METADATA_BAD) {
         // So we don't try and display metadata from PagedTiffHandler
         // for example when using InstantCommons.
         return array();
     }
     $exif = unserialize($metadata);
     if (!$exif) {
         return array();
     }
     unset($exif['MEDIAWIKI_EXIF_VERSION']);
     return $exif;
 }
Example #11
0
 /**
  * Get metadata, unserializing it if neccessary.
  *
  * @param File $file The DjVu file in question
  * @return String XML metadata as a string.
  */
 private function getUnserializedMetadata(File $file)
 {
     $metadata = $file->getMetadata();
     if (substr($metadata, 0, 3) === '<?xml') {
         // Old style. Not serialized but instead just a raw string of XML.
         return $metadata;
     }
     wfSuppressWarnings();
     $unser = unserialize($metadata);
     wfRestoreWarnings();
     if (is_array($unser)) {
         return $unser['xml'];
     }
     // unserialize failed. Guess it wasn't really serialized after all,
     return $metadata;
 }