Beispiel #1
0
 /**
  * Load metadata from the file itself
  */
 function loadFromFile()
 {
     global $wgUseSharedUploads, $wgSharedUploadDirectory, $wgContLang, $wgShowEXIF;
     wfProfileIn(__METHOD__);
     $this->imagePath = $this->getFullPath();
     $this->fileExists = file_exists($this->imagePath);
     $this->fromSharedDirectory = false;
     $gis = array();
     if (!$this->fileExists) {
         wfDebug(__METHOD__ . ': ' . $this->imagePath . " not found locally!\n");
     }
     # If the file is not found, and a shared upload directory is used, look for it there.
     if (!$this->fileExists && $wgUseSharedUploads && $wgSharedUploadDirectory) {
         # In case we're on a wgCapitalLinks=false wiki, we
         # capitalize the first letter of the filename before
         # looking it up in the shared repository.
         $sharedImage = Image::newFromName($wgContLang->ucfirst($this->name));
         $this->fileExists = $sharedImage && file_exists($sharedImage->getFullPath(true));
         if ($this->fileExists) {
             $this->name = $sharedImage->name;
             $this->imagePath = $this->getFullPath(true);
             $this->fromSharedDirectory = true;
         }
     }
     if ($this->fileExists) {
         $magic =& wfGetMimeMagic();
         $this->mime = $magic->guessMimeType($this->imagePath, true);
         $this->type = $magic->getMediaType($this->imagePath, $this->mime);
         # Get size in bytes
         $this->size = filesize($this->imagePath);
         $magic =& wfGetMimeMagic();
         # Height and width
         wfSuppressWarnings();
         if ($this->mime == 'image/svg') {
             $gis = wfGetSVGsize($this->imagePath);
         } elseif ($this->mime == 'image/vnd.djvu') {
             $deja = new DjVuImage($this->imagePath);
             $gis = $deja->getImageSize();
         } elseif (!$magic->isPHPImageType($this->mime)) {
             # Don't try to get the width and height of sound and video files, that's bad for performance
             $gis = false;
         } else {
             $gis = getimagesize($this->imagePath);
         }
         wfRestoreWarnings();
         wfDebug(__METHOD__ . ': ' . $this->imagePath . " loaded, " . $this->size . " bytes, " . $this->mime . ".\n");
     } else {
         $this->mime = NULL;
         $this->type = MEDIATYPE_UNKNOWN;
         wfDebug(__METHOD__ . ': ' . $this->imagePath . " NOT FOUND!\n");
     }
     if ($gis) {
         $this->width = $gis[0];
         $this->height = $gis[1];
     } else {
         $this->width = 0;
         $this->height = 0;
     }
     #NOTE: $gis[2] contains a code for the image type. This is no longer used.
     #NOTE: we have to set this flag early to avoid load() to be called
     # be some of the functions below. This may lead to recursion or other bad things!
     # as ther's only one thread of execution, this should be safe anyway.
     $this->dataLoaded = true;
     $this->metadata = serialize($this->retrieveExifData($this->imagePath));
     if (isset($gis['bits'])) {
         $this->bits = $gis['bits'];
     } else {
         $this->bits = 0;
     }
     wfProfileOut(__METHOD__);
 }