Example #1
0
 /**
  * Get file-based metadata in standardized format.
  *
  * Note that for a remote file, this might return metadata supplied by extensions.
  *
  * @param File $file File to use
  * @return array [<property name> => ['value' => <value>]], or [] on error
  * @since 1.23
  */
 protected function getExtendedMetadataFromFile(File $file)
 {
     // If this is a remote file accessed via an API request, we already
     // have remote metadata so we just ignore any local one
     if ($file instanceof ForeignAPIFile) {
         // In case of error we pretend no metadata - this will get cached.
         // Might or might not be a good idea.
         return $file->getExtendedMetadata() ?: array();
     }
     wfProfileIn(__METHOD__);
     $uploadDate = wfTimestamp(TS_ISO_8601, $file->getTimestamp());
     $fileMetadata = array('DateTime' => array('value' => $uploadDate, 'source' => 'mediawiki-metadata'));
     $title = $file->getTitle();
     if ($title) {
         $text = $title->getText();
         $pos = strrpos($text, '.');
         if ($pos) {
             $name = substr($text, 0, $pos);
         } else {
             $name = $text;
         }
         $fileMetadata['ObjectName'] = array('value' => $name, 'source' => 'mediawiki-metadata');
     }
     $common = $file->getCommonMetaArray();
     if ($common !== false) {
         foreach ($common as $key => $value) {
             $fileMetadata[$key] = array('value' => $value, 'source' => 'file-metadata');
         }
     }
     wfProfileOut(__METHOD__);
     return $fileMetadata;
 }