Example #1
0
 function testWriterOpenButDontChange()
 {
     $f = new File("/" . FRAMEWORK_CORE_PATH . "tests/io/reader_writer/myfile_01.txt");
     $this->assertEqual(24, $f->getSize(), "La dimensione del file non corrisponde!! : " . $f->getSize());
     try {
         $writer = $f->openWriter();
         $this->assertTrue($writer instanceof FileWriter, "L'oggetto non e' del tipo specificato!!");
         $this->assertTrue($writer->isOpen(), "Il writer non e' aperto!!");
         $writer->close();
         $this->assertFalse($writer->isOpen(), "Il writer non e' stato chiuso!!");
     } catch (Exception $ex) {
         $this->fail("Errore nell'apertura del writer di un file esistente!!");
     }
 }
Example #2
0
 /**
  * Tests File::getSize
  */
 public function testGetSize()
 {
     $spl = $this->getFileInfo();
     $file = new File($spl);
     $size = $file->getSize();
     $this->assertEquals($spl->getSize(), $size, 'size should match');
 }
Example #3
0
 /**
  * @return array|null
  */
 public function getDuplicates()
 {
     $this->loadFile();
     if (!is_null($this->mDupes)) {
         return $this->mDupes;
     }
     $hash = $this->mFile->getSha1();
     if (!$hash) {
         $this->mDupes = [];
         return $this->mDupes;
     }
     $dupes = RepoGroup::singleton()->findBySha1($hash);
     // Remove duplicates with self and non matching file sizes
     $self = $this->mFile->getRepoName() . ':' . $this->mFile->getName();
     $size = $this->mFile->getSize();
     /**
      * @var $file File
      */
     foreach ($dupes as $index => $file) {
         $key = $file->getRepoName() . ':' . $file->getName();
         if ($key == $self) {
             unset($dupes[$index]);
         }
         if ($file->getSize() != $size) {
             unset($dupes[$index]);
         }
     }
     $this->mDupes = $dupes;
     return $this->mDupes;
 }
Example #4
0
 function testCompressUncompress()
 {
     $f = new File("/" . FRAMEWORK_CORE_PATH . "tests/utils/compress/test.ffa");
     $f->delete();
     FFArchive::compress($f, new Dir("/" . FRAMEWORK_CORE_PATH . "tests/utils/compress/data/"));
     $ext_dir = new Dir("/" . FRAMEWORK_CORE_PATH . "tests/utils/extract/");
     $ext_dir->touch();
     $f = new File("/" . FRAMEWORK_CORE_PATH . "tests/utils/compress/test.ffa");
     $this->assertTrue($f->exists(), "Il file da decomprimere non esiste!!");
     FFArchive::extract($f, $ext_dir);
     $f1 = new File("/" . FRAMEWORK_CORE_PATH . "tests/utils/extract/cartella.png");
     $this->assertTrue($f1->exists(), "Il file cartella.png non e' stato estratto!!");
     $this->assertEqual($f1->getSize(), 441, "La dimensione di cartella.png non corrisponde!!");
     $f2 = new File("/" . FRAMEWORK_CORE_PATH . "tests/utils/extract/file1.txt");
     $this->assertTrue($f2->exists(), "Il file file1.txt non e' stato estratto!!");
     $f3 = new File("/" . FRAMEWORK_CORE_PATH . "tests/utils/extract/file2.dat");
     $this->assertTrue($f3->exists(), "Il file file2.dat non e' stato estratto!!");
     $d1 = new Dir("/" . FRAMEWORK_CORE_PATH . "tests/utils/extract/empty_folder");
     $this->assertTrue($d1->exists(), "La cartella vuota non e' stata estratta!!");
     $d2 = new Dir("/" . FRAMEWORK_CORE_PATH . "tests/utils/extract/folder");
     $this->assertTrue($d2->exists(), "La cartella folder non e' stata estratta!!");
     $f4 = new File("/" . FRAMEWORK_CORE_PATH . "tests/utils/extract/folder/sub/yep.txt");
     $this->assertTrue($f4->exists(), "Il file yep.txt non e' stato estratto!!");
     $this->assertEqual($f4->getSize(), 10, "La dimensione di yep.txt non corrisponde!!");
     $this->assertTrue($ext_dir->delete(true), "La directory coi file estratti non e' stata elimintata!!");
     $this->assertFalse($f1->exists(), "Il file cartella.png esiste ancora!!");
 }
Example #5
0
 public function index()
 {
     $file = $this->fetchParam("file", null, null, null, false);
     $fileSize = File::getSize(BASE_PATH . $file);
     $file_info = array("file_ext" => File::getExtension(BASE_PATH . $file), "file_size" => $fileSize, "file_size_kilobytes" => number_format($fileSize / 1024), "file_size_human" => self::format_bytes_human($fileSize));
     return $file_info;
 }
 public function index($file, $parameters = array())
 {
     $file = Path::assemble(BASE_PATH, $file);
     if (File::exists($file)) {
         $fileSize = File::getSize(BASE_PATH . $file);
         switch ($parameters) {
             case "file_ext":
                 return File::getExtension($file);
                 break;
             case "file_size":
                 return File::getSize(BASE_PATH . $file);
                 break;
             case "file_size_kilobytes":
                 return number_format($fileSize / 1024);
                 break;
             case "file_size_human":
                 return self::format_bytes_human($fileSize);
                 break;
             default:
                 return File::getExtension($file);
         }
     } else {
         Log::error("File does not exist or is not readable", "fileinfo_modifier", $file);
     }
 }
Example #7
0
 function testGetSize()
 {
     $f_test_file = new File("/" . FRAMEWORK_CORE_PATH . "tests/io/test_dir/content_dir/test_file.txt");
     $f_ext_test = new File("/" . FRAMEWORK_CORE_PATH . "tests/io/test_dir/content_dir/ext_test.plug.txt");
     $this->assertEqual(12, $f_test_file->getSize());
     $this->assertEqual(0, $f_ext_test->getSize());
 }
Example #8
0
 function testBackupDir()
 {
     $resulting_path = Backup::backup_dir("/" . FRAMEWORK_CORE_PATH . "tests/io/advances_dir_list/");
     $f = new File($resulting_path);
     $this->assertTrue($f->exists(), "Il file di backup non e' stato creato!!");
     $this->assertTrue($f->getSize() > 0, "Il file ha dimensione nulla!!");
     $f->delete();
 }
Example #9
0
 function testSaveAsArchive()
 {
     $result_file = new File(ModuleArchiver::MODULES_ARCHIVE_DIR . "test__category-1_2_3.ffa");
     $this->assertFalse($result_file->exists(), "Il file del modulo non e' stato creato!!");
     ModuleUtils::set_modules_path("/" . FRAMEWORK_CORE_PATH . "tests/modules/fakeroot2/modules/");
     $this->assertTrue(AvailableModules::is_module_available("test", "category"), "Il modulo test/category non e' disponibile!!");
     ModuleArchiver::save_as_archive("test", "category");
     $this->assertTrue($result_file->exists(), "Il file del modulo non e' stato creato!!");
     $this->assertTrue($result_file->getSize() > 0, "Il file e' vuoto!!");
     $result_file->delete();
     ModuleUtils::set_modules_path("/framework/modules/");
 }
Example #10
0
 private function get_layout_cache_key()
 {
     if ($this->layout_cache_key != null) {
         return $this->layout_cache_key;
     }
     $layout_class_source = ClassLoader::instance()->get_element_content_by_name(get_class($this));
     $f = new File("/" . $this->layout_path);
     $layout_file_path = $f->getPath();
     $layout_file_size = $f->getSize();
     $layout_modification_time = $f->getModificationTime();
     $this->layout_cache_key = md5($layout_class_source . $layout_file_path . $layout_file_size . $layout_modification_time);
     return $this->layout_cache_key;
 }
Example #11
0
 /**
  * Writes a line in the log file
  *
  * @param string $line
  */
 public function write($line)
 {
     File::append($this->filepath, date($this->date_format) . ' - ' . $line . "\n");
     // If the max size is exceeded
     if (File::getSize($this->filepath) >= $this->max_size) {
         File::delete($this->filepath . '.' . $this->nb_old_logs);
         for ($i = $this->nb_old_logs; $i >= 1; $i--) {
             if (File::exists($this->filepath . ($i == 1 ? '' : '.' . ($i - 1)))) {
                 File::rename($this->filepath . ($i == 1 ? '' : '.' . ($i - 1)), $this->filepath . '.' . $i);
             }
         }
     }
 }
 public function redactor__fetch_files()
 {
     $this->authCheck();
     $dir = Path::tidy(ltrim(Request::get('path'), '/') . '/');
     $file_list = glob($dir . "*.*", GLOB_BRACE);
     $files = array();
     if (count($file_list) > 0) {
         foreach ($file_list as $file) {
             $pi = pathinfo($file);
             $files[] = array('link' => Path::toAsset($file), 'title' => $pi['filename'], 'name' => $pi['basename'], 'size' => File::getHumanSize(File::getSize(Path::assemble(BASE_PATH, $file))));
         }
     }
     echo json_encode($files);
 }
 public function control()
 {
     $this->redirectToSternIndiaEndPoint();
     $config = Config::getInstance();
     if (isset($_POST['upload']) && $_POST['upload'] == 'Upload') {
         $target_dir = new FileSystem('upload/');
         $file = new File('foo', $target_dir);
         $name = date('D_d_m_Y_H_m_s_');
         $name = $name . $file->getName();
         $file->setName($name);
         $config = Config::getInstance();
         $file->addValidations(array(new Mimetype($config->getMimeTypes()), new Size('5M')));
         $data = array('name' => $file->getNameWithExtension(), 'extension' => $file->getExtension(), 'mime' => $file->getMimetype(), 'size' => $file->getSize(), 'md5' => $file->getMd5());
         try {
             // /Profiler::debugPoint(true,__METHOD__, __FILE__, __LINE__,$data);
             $file->upload();
             //Profiler::debugPoint(true,__METHOD__, __FILE__, __LINE__,$data);
         } catch (Exception $e) {
             $errors = $file->getErrors();
         }
         $csvReader = new CSVReader();
         $destinationFile = $target_dir->directory . $file->getNameWithExtension();
         $data = $csvReader->parse_file($destinationFile);
         //$country= DAOFactory::getDAO('LocationDAO');
         foreach ($data as $loc_arr) {
             Utils::processLocation($loc_arr);
         }
         //Profiler::debugPoint(true,__METHOD__, __FILE__, __LINE__);
         $target_dir = "uploads/";
         $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
         $uploadOk = 1;
         $imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);
         // Check if image file is a actual image or fake image
         if (isset($_POST["submit"])) {
             $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
             if ($check !== false) {
                 echo "File is an image - " . $check["mime"] . ".";
                 $uploadOk = 1;
             } else {
                 echo "File is not an image.";
                 $uploadOk = 0;
             }
         }
     }
     return $this->generateView();
 }
Example #14
0
 public function index($file, $parameters = array())
 {
     switch ($parameters) {
         case "file_ext":
             return File::getExtension();
             break;
         case "file_size":
             return File::getSize(BASE_PATH . $file);
             break;
         case "file_size_kilobytes":
             return number_format($fileSize / 1024);
             break;
         case "file_size_human":
             return self::format_bytes_human($fileSize);
             break;
         default:
             return File::getExtension();
     }
 }
 /**
  * @param File $file
  * @param bool $dumpContents
  * @return string
  */
 function writeUpload($file, $dumpContents = false)
 {
     if ($file->isOld()) {
         $archiveName = "      " . Xml::element('archivename', null, $file->getArchiveName()) . "\n";
     } else {
         $archiveName = '';
     }
     if ($dumpContents) {
         $be = $file->getRepo()->getBackend();
         # Dump file as base64
         # Uses only XML-safe characters, so does not need escaping
         # @todo Too bad this loads the contents into memory (script might swap)
         $contents = '      <contents encoding="base64">' . chunk_split(base64_encode($be->getFileContents(array('src' => $file->getPath())))) . "      </contents>\n";
     } else {
         $contents = '';
     }
     if ($file->isDeleted(File::DELETED_COMMENT)) {
         $comment = Xml::element('comment', array('deleted' => 'deleted'));
     } else {
         $comment = Xml::elementClean('comment', null, $file->getDescription());
     }
     return "    <upload>\n" . $this->writeTimestamp($file->getTimestamp()) . $this->writeContributor($file->getUser('id'), $file->getUser('text')) . "      " . $comment . "\n" . "      " . Xml::element('filename', null, $file->getName()) . "\n" . $archiveName . "      " . Xml::element('src', null, $file->getCanonicalURL()) . "\n" . "      " . Xml::element('size', null, $file->getSize()) . "\n" . "      " . Xml::element('sha1base36', null, $file->getSha1()) . "\n" . "      " . Xml::element('rel', null, $file->getRel()) . "\n" . $contents . "    </upload>\n";
 }
Example #16
0
 /** 
  * Get total size of subfolders and files of this folder
  * @return size of this folder in bytes
  */
 function getSize()
 {
     if (!empty($this->id)) {
         global $dbi;
         $totalSize = 0;
         /* Get size of subfolders */
         $result = $dbi->query("SELECT id FROM " . folderTableName . " WHERE parentId=" . $this->id);
         for ($j = 0; list($id) = $result->fetchrow_array(); $j++) {
             $folder = new Folder($id);
             $totalSize += $folder->getSize();
         }
         /* Get size of files */
         $result = $dbi->query("SELECT id FROM " . fileTableName . " WHERE folderId=" . $this->id);
         for ($j = 0; list($id) = $result->fetchrow_array(); $j++) {
             $file = new File($id);
             $totalSize += $file->getSize();
         }
         /* Return size of folder in bytes */
         return $totalSize;
     }
 }
Example #17
0
 /**
  * @param File $file
  * @returns string
  */
 private function fileLine($file)
 {
     global $wgLang, $wgTitle;
     $target = $this->page->getPrefixedText();
     $date = $wgLang->timeanddate($file->getTimestamp(), true);
     $del = '';
     # Hidden files...
     if ($file->isDeleted(File::DELETED_FILE)) {
         $del = ' <tt>' . wfMsgHtml('deletedrev') . '</tt>';
         if (!$file->userCan(File::DELETED_FILE)) {
             $pageLink = $date;
         } else {
             $pageLink = $this->skin->makeKnownLinkObj($wgTitle, $date, "target={$target}&file={$file->sha1}." . $file->getExtension());
         }
         $pageLink = '<span class="history-deleted">' . $pageLink . '</span>';
         # Regular files...
     } else {
         $url = $file->getUrlRel();
         $pageLink = "<a href=\"{$url}\">{$date}</a>";
     }
     $data = wfMsg('widthheight', $wgLang->formatNum($file->getWidth()), $wgLang->formatNum($file->getHeight())) . ' (' . wfMsgExt('nbytes', 'parsemag', $wgLang->formatNum($file->getSize())) . ')';
     $data = htmlspecialchars($data);
     return "<li>{$pageLink} " . $this->fileUserTools($file) . " {$data} " . $this->fileComment($file) . "{$del}</li>";
 }
Example #18
0
 /**
  * Subtitle for the image. Different from the base
  * class so it can be denoted that SVG's have
  * a "nominal" resolution, and not a fixed one,
  * as well as so animation can be denoted.
  *
  * @param File $file
  * @return string
  */
 function getLongDesc($file)
 {
     global $wgLang;
     $metadata = $this->unpackMetadata($file->getMetadata());
     if (isset($metadata['error'])) {
         return wfMessage('svg-long-error', $metadata['error']['message'])->text();
     }
     $size = $wgLang->formatSize($file->getSize());
     if ($this->isAnimatedImage($file)) {
         $msg = wfMessage('svg-long-desc-animated');
     } else {
         $msg = wfMessage('svg-long-desc');
     }
     $msg->numParams($file->getWidth(), $file->getHeight())->params($size);
     return $msg->parse();
 }
Example #19
0
 /**
  * Used instead of getLongDesc if there is no handler registered for file.
  *
  * @param File $file
  * @return string
  */
 static function getGeneralLongDesc($file)
 {
     return wfMessage('file-info')->sizeParams($file->getSize())->params($file->getMimeType())->parse();
 }
Example #20
0
<?php

require_once __DIR__ . '/../app/lib/File.php';
try {
    $err = File::getError();
    if ($err) {
        throw new Exception($err);
    }
    if (File::getSize() > 512000) {
        throw new Exception('File is too large');
    }
    $tmp_name = File::getTmpName();
    $newName = '/uploads/' . time() . '_' . File::getOriginalName();
    if (!move_uploaded_file($tmp_name, __DIR__ . $newName)) {
        throw new Exception('Unable move file in the server');
    }
    echo json_encode(array('path' => $newName));
} catch (Exception $e) {
    http_response_code(412);
    echo json_encode(array('error' => array('Message' => $e->getMessage())));
}
 /**
  * Adds new properties to the parent (KickAssets) file JSON
  * 
  * @return array
  */
 protected function buildJSON()
 {
     $json = $this->parent->createFileJSON($this->file);
     $json['created'] = $this->file->obj('Created')->FormatFromSettings();
     $json['lastEdited'] = $this->file->obj('LastEdited')->FormatFromSettings();
     $json['url'] = $this->file->getAbsoluteURL();
     $json['size'] = $this->file->getSize();
     $json['folder'] = $this->file->Parent()->Filename;
     if ($this->file instanceof Image) {
         $json['previewImage'] = $this->file->CroppedImage(400, 133)->URL;
         $json['detailImage'] = $this->file->getKickAssetsDetailImage()->URL;
     }
     return $json;
 }
Example #22
0
 public function setFile(File $toSave)
 {
     $permissionEngine = PermissionEngine::getInstance();
     if (!$permissionEngine->currentUserCanDo('uploadFile')) {
         return false;
     }
     $database = Database::getInstance();
     if (!$database->isConnected()) {
         return false;
     }
     $validator = new checkIfKnownMimeType();
     if (!$validator->validate($toSave->getMimeType())) {
         return false;
     }
     if (!is_readable($toSave->getLocation())) {
         return false;
     }
     $id = $database->escapeString($toSave->getID());
     $dateUploaded = $database->escapeString($toSave->getUploadedDate()->format('Y-m-d H:i:s'));
     $title = $database->escapeString(strip_tags($toSave->getTitle()));
     $mimeType = $database->escapeString($toSave->getMimeType());
     $size = $database->escapeString($toSave->getSize());
     $location = $database->escapeString($toSave->getLocation());
     $nodeID = $database->escapeString($toSave->getNodeID());
     $uploader = $database->escapeString($toSave->getUploaderID());
     $folder = $database->escapeString($toSave->getFolderID());
     $result = $database->updateTable('file', "uploaded='{$dateUploaded}', title='{$title}', mimeType='{$mimeType}', size={$size}, location='{$location}', nodeID={$nodeID}, uploader={$uploader}, folderID={$folder}", "fileID='{$id}'");
     if ($result === false) {
         return false;
     }
     return true;
 }
Example #23
0
 /**
  * Used instead of getLongDesc if there is no handler registered for file.
  *
  * @param File $file
  * @return string
  */
 static function getGeneralLongDesc($file)
 {
     return wfMessage('file-info')->sizeParams($file->getSize())->params('<span class="mime-type">' . $file->getMimeType() . '</span>')->parse();
 }
Example #24
0
 public function getHTML()
 {
     $data = wfMsg('widthheight', $this->list->getLang()->formatNum($this->file->getWidth()), $this->list->getLang()->formatNum($this->file->getHeight())) . ' (' . wfMsgExt('nbytes', 'parsemag', $this->list->getLang()->formatNum($this->file->getSize())) . ')';
     return '<li>' . $this->getLink() . ' ' . $this->getUserTools() . ' ' . $data . ' ' . $this->getComment() . '</li>';
 }
 /**
  * Get result information for an image revision
  *
  * @param File $file
  * @param array $prop Array of properties to get (in the keys)
  * @param ApiResult $result
  * @param array $thumbParams Containing 'width' and 'height' items, or null
  * @param array|bool|string $opts Options for data fetching.
  *   This is an array consisting of the keys:
  *    'version': The metadata version for the metadata option
  *    'language': The language for extmetadata property
  *    'multilang': Return all translations in extmetadata property
  *    'revdelUser': User to use when checking whether to show revision-deleted fields.
  * @return array Result array
  */
 static function getInfo($file, $prop, $result, $thumbParams = null, $opts = false)
 {
     global $wgContLang;
     $anyHidden = false;
     if (!$opts || is_string($opts)) {
         $opts = array('version' => $opts ?: 'latest', 'language' => $wgContLang, 'multilang' => false, 'extmetadatafilter' => array(), 'revdelUser' => null);
     }
     $version = $opts['version'];
     $vals = array(ApiResult::META_TYPE => 'assoc');
     // Timestamp is shown even if the file is revdelete'd in interface
     // so do same here.
     if (isset($prop['timestamp'])) {
         $vals['timestamp'] = wfTimestamp(TS_ISO_8601, $file->getTimestamp());
     }
     // Handle external callers who don't pass revdelUser
     if (isset($opts['revdelUser']) && $opts['revdelUser']) {
         $revdelUser = $opts['revdelUser'];
         $canShowField = function ($field) use($file, $revdelUser) {
             return $file->userCan($field, $revdelUser);
         };
     } else {
         $canShowField = function ($field) use($file) {
             return !$file->isDeleted($field);
         };
     }
     $user = isset($prop['user']);
     $userid = isset($prop['userid']);
     if ($user || $userid) {
         if ($file->isDeleted(File::DELETED_USER)) {
             $vals['userhidden'] = true;
             $anyHidden = true;
         }
         if ($canShowField(File::DELETED_USER)) {
             if ($user) {
                 $vals['user'] = $file->getUser();
             }
             if ($userid) {
                 $vals['userid'] = $file->getUser('id');
             }
             if (!$file->getUser('id')) {
                 $vals['anon'] = true;
             }
         }
     }
     // This is shown even if the file is revdelete'd in interface
     // so do same here.
     if (isset($prop['size']) || isset($prop['dimensions'])) {
         $vals['size'] = intval($file->getSize());
         $vals['width'] = intval($file->getWidth());
         $vals['height'] = intval($file->getHeight());
         $pageCount = $file->pageCount();
         if ($pageCount !== false) {
             $vals['pagecount'] = $pageCount;
         }
         // length as in how many seconds long a video is.
         $length = $file->getLength();
         if ($length) {
             // Call it duration, because "length" can be ambiguous.
             $vals['duration'] = (double) $length;
         }
     }
     $pcomment = isset($prop['parsedcomment']);
     $comment = isset($prop['comment']);
     if ($pcomment || $comment) {
         if ($file->isDeleted(File::DELETED_COMMENT)) {
             $vals['commenthidden'] = true;
             $anyHidden = true;
         }
         if ($canShowField(File::DELETED_COMMENT)) {
             if ($pcomment) {
                 $vals['parsedcomment'] = Linker::formatComment($file->getDescription(File::RAW), $file->getTitle());
             }
             if ($comment) {
                 $vals['comment'] = $file->getDescription(File::RAW);
             }
         }
     }
     $canonicaltitle = isset($prop['canonicaltitle']);
     $url = isset($prop['url']);
     $sha1 = isset($prop['sha1']);
     $meta = isset($prop['metadata']);
     $extmetadata = isset($prop['extmetadata']);
     $commonmeta = isset($prop['commonmetadata']);
     $mime = isset($prop['mime']);
     $mediatype = isset($prop['mediatype']);
     $archive = isset($prop['archivename']);
     $bitdepth = isset($prop['bitdepth']);
     $uploadwarning = isset($prop['uploadwarning']);
     if ($uploadwarning) {
         $vals['html'] = SpecialUpload::getExistsWarning(UploadBase::getExistsWarning($file));
     }
     if ($file->isDeleted(File::DELETED_FILE)) {
         $vals['filehidden'] = true;
         $anyHidden = true;
     }
     if ($anyHidden && $file->isDeleted(File::DELETED_RESTRICTED)) {
         $vals['suppressed'] = true;
     }
     if (!$canShowField(File::DELETED_FILE)) {
         //Early return, tidier than indenting all following things one level
         return $vals;
     }
     if ($canonicaltitle) {
         $vals['canonicaltitle'] = $file->getTitle()->getPrefixedText();
     }
     if ($url) {
         if (!is_null($thumbParams)) {
             $mto = $file->transform($thumbParams);
             self::$transformCount++;
             if ($mto && !$mto->isError()) {
                 $vals['thumburl'] = wfExpandUrl($mto->getUrl(), PROTO_CURRENT);
                 // bug 23834 - If the URL's are the same, we haven't resized it, so shouldn't give the wanted
                 // thumbnail sizes for the thumbnail actual size
                 if ($mto->getUrl() !== $file->getUrl()) {
                     $vals['thumbwidth'] = intval($mto->getWidth());
                     $vals['thumbheight'] = intval($mto->getHeight());
                 } else {
                     $vals['thumbwidth'] = intval($file->getWidth());
                     $vals['thumbheight'] = intval($file->getHeight());
                 }
                 if (isset($prop['thumbmime']) && $file->getHandler()) {
                     list(, $mime) = $file->getHandler()->getThumbType($mto->getExtension(), $file->getMimeType(), $thumbParams);
                     $vals['thumbmime'] = $mime;
                 }
             } elseif ($mto && $mto->isError()) {
                 $vals['thumberror'] = $mto->toText();
             }
         }
         $vals['url'] = wfExpandUrl($file->getFullURL(), PROTO_CURRENT);
         $vals['descriptionurl'] = wfExpandUrl($file->getDescriptionUrl(), PROTO_CURRENT);
     }
     if ($sha1) {
         $vals['sha1'] = wfBaseConvert($file->getSha1(), 36, 16, 40);
     }
     if ($meta) {
         wfSuppressWarnings();
         $metadata = unserialize($file->getMetadata());
         wfRestoreWarnings();
         if ($metadata && $version !== 'latest') {
             $metadata = $file->convertMetadataVersion($metadata, $version);
         }
         $vals['metadata'] = $metadata ? self::processMetaData($metadata, $result) : null;
     }
     if ($commonmeta) {
         $metaArray = $file->getCommonMetaArray();
         $vals['commonmetadata'] = $metaArray ? self::processMetaData($metaArray, $result) : array();
     }
     if ($extmetadata) {
         // Note, this should return an array where all the keys
         // start with a letter, and all the values are strings.
         // Thus there should be no issue with format=xml.
         $format = new FormatMetadata();
         $format->setSingleLanguage(!$opts['multilang']);
         $format->getContext()->setLanguage($opts['language']);
         $extmetaArray = $format->fetchExtendedMetadata($file);
         if ($opts['extmetadatafilter']) {
             $extmetaArray = array_intersect_key($extmetaArray, array_flip($opts['extmetadatafilter']));
         }
         $vals['extmetadata'] = $extmetaArray;
     }
     if ($mime) {
         $vals['mime'] = $file->getMimeType();
     }
     if ($mediatype) {
         $vals['mediatype'] = $file->getMediaType();
     }
     if ($archive && $file->isOld()) {
         $vals['archivename'] = $file->getArchiveName();
     }
     if ($bitdepth) {
         $vals['bitdepth'] = $file->getBitDepth();
     }
     return $vals;
 }
Example #26
0
 /**
  * Output HTTP response for file
  * Side effect: writes HTTP response to STDOUT.
  *
  * @param File $file File object with a local path (e.g. UnregisteredLocalFile,
  *   LocalFile. Oddly these don't share an ancestor!)
  * @throws SpecialUploadStashTooLargeException
  * @return bool
  */
 private function outputLocalFile(File $file)
 {
     if ($file->getSize() > self::MAX_SERVE_BYTES) {
         throw new SpecialUploadStashTooLargeException();
     }
     return $file->getRepo()->streamFile($file->getPath(), array('Content-Transfer-Encoding: binary', 'Expires: Sun, 17-Jan-2038 19:14:07 GMT'));
 }
 public function getHTML()
 {
     $data = $this->list->msg('widthheight')->numParams($this->file->getWidth(), $this->file->getHeight())->text() . ' (' . $this->list->msg('nbytes')->numParams($this->file->getSize())->text() . ')';
     return '<li>' . $this->getLink() . ' ' . $this->getUserTools() . ' ' . $data . ' ' . $this->getComment() . '</li>';
 }
Example #28
0
 /**
  * Used instead of getShortDesc if there is no handler registered for file.
  *
  * @param File $file
  * @return string
  */
 static function getGeneralLongDesc($file)
 {
     global $wgLang;
     return wfMessage('file-info', $wgLang->formatSize($file->getSize()), $file->getMimeType())->parse();
 }
 /**
  * Get file size (if known) as string
  *
  * @return string|false String value, or false if doesn't exist
  */
 public function getSize()
 {
     if ($this->file) {
         return $this->file->getSize();
     }
     return false;
 }
 /**
  * @param File $file
  * @return string
  */
 function getLongDesc($file)
 {
     global $wgLang;
     $pages = $file->pageCount();
     $size = htmlspecialchars($wgLang->formatSize($file->getSize()));
     if ($pages === false || $pages <= 1) {
         $msg = wfMessage('file-info-size')->numParams($file->getWidth(), $file->getHeight())->params($size, '<span class="mime-type">' . $file->getMimeType() . '</span>')->parse();
     } else {
         $msg = wfMessage('file-info-size-pages')->numParams($file->getWidth(), $file->getHeight())->params($size, '<span class="mime-type">' . $file->getMimeType() . '</span>')->numParams($pages)->parse();
     }
     return $msg;
 }