本文整理汇总了PHP中TempFSFile类的典型用法代码示例。如果您正苦于以下问题:PHP TempFSFile类的具体用法?PHP TempFSFile怎么用?PHP TempFSFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TempFSFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
protected function setUp()
{
parent::setUp();
$filename = 'Foo.png';
$this->tmpPrefix = $this->getNewTempDirectory();
$backend = new FSFileBackend(['name' => 'local-migratefilerepolayouttest', 'wikiId' => wfWikiID(), 'containerPaths' => ['migratefilerepolayouttest-original' => "{$this->tmpPrefix}-original", 'migratefilerepolayouttest-public' => "{$this->tmpPrefix}-public", 'migratefilerepolayouttest-thumb' => "{$this->tmpPrefix}-thumb", 'migratefilerepolayouttest-temp' => "{$this->tmpPrefix}-temp", 'migratefilerepolayouttest-deleted' => "{$this->tmpPrefix}-deleted"]]);
$dbMock = $this->getMockBuilder('DatabaseMysql')->disableOriginalConstructor()->getMock();
$imageRow = new stdClass();
$imageRow->img_name = $filename;
$imageRow->img_sha1 = sha1($this->text);
$dbMock->expects($this->any())->method('select')->will($this->onConsecutiveCalls(new FakeResultWrapper([$imageRow]), new FakeResultWrapper([]), new FakeResultWrapper([])));
$repoMock = $this->getMock('LocalRepo', ['getMasterDB'], [['name' => 'migratefilerepolayouttest', 'backend' => $backend]]);
$repoMock->expects($this->any())->method('getMasterDB')->will($this->returnValue($dbMock));
$this->migratorMock = $this->getMock('MigrateFileRepoLayout', ['getRepo']);
$this->migratorMock->expects($this->any())->method('getRepo')->will($this->returnValue($repoMock));
$this->tmpFilepath = TempFSFile::factory('migratefilelayout-test-', 'png')->getPath();
file_put_contents($this->tmpFilepath, $this->text);
$hashPath = $repoMock->getHashPath($filename);
$status = $repoMock->store($this->tmpFilepath, 'public', $hashPath . $filename, FileRepo::OVERWRITE);
}
示例2: concatenateChunks
/**
* Append the final chunk and ready file for parent::performUpload()
* @return FileRepoStatus
*/
public function concatenateChunks()
{
$chunkIndex = $this->getChunkIndex();
wfDebug(__METHOD__ . " concatenate {$this->mChunkIndex} chunks:" . $this->getOffset() . ' inx:' . $chunkIndex . "\n");
// Concatenate all the chunks to mVirtualTempPath
$fileList = [];
// The first chunk is stored at the mVirtualTempPath path so we start on "chunk 1"
for ($i = 0; $i <= $chunkIndex; $i++) {
$fileList[] = $this->getVirtualChunkLocation($i);
}
// Get the file extension from the last chunk
$ext = FileBackend::extensionFromPath($this->mVirtualTempPath);
// Get a 0-byte temp file to perform the concatenation at
$tmpFile = TempFSFile::factory('chunkedupload_', $ext, wfTempDir());
$tmpPath = false;
// fail in concatenate()
if ($tmpFile) {
// keep alive with $this
$tmpPath = $tmpFile->bind($this)->getPath();
}
// Concatenate the chunks at the temp file
$tStart = microtime(true);
$status = $this->repo->concatenate($fileList, $tmpPath, FileRepo::DELETE_SOURCE);
$tAmount = microtime(true) - $tStart;
if (!$status->isOK()) {
return $status;
}
wfDebugLog('fileconcatenate', "Combined {$i} chunks in {$tAmount} seconds.");
// File system path of the actual full temp file
$this->setTempFile($tmpPath);
$ret = $this->verifyUpload();
if ($ret['status'] !== UploadBase::OK) {
wfDebugLog('fileconcatenate', "Verification failed for chunked upload");
$status->fatal($this->getVerificationErrorCode($ret['status']));
return $status;
}
// Update the mTempPath and mStashFile
// (for FileUpload or normal Stash to take over)
$tStart = microtime(true);
// This is a re-implementation of UploadBase::tryStashFile(), we can't call it because we
// override doStashFile() with completely different functionality in this class...
$error = $this->runUploadStashFileHook($this->user);
if ($error) {
call_user_func_array([$status, 'fatal'], $error);
return $status;
}
try {
$this->mStashFile = parent::doStashFile($this->user);
} catch (UploadStashException $e) {
$status->fatal('uploadstash-exception', get_class($e), $e->getMessage());
return $status;
}
$tAmount = microtime(true) - $tStart;
$this->mStashFile->setLocalReference($tmpFile);
// reuse (e.g. for getImageInfo())
wfDebugLog('fileconcatenate', "Stashed combined file ({$i} chunks) in {$tAmount} seconds.");
return $status;
}
示例3: getLocalCopy
/**
* @see FileBackendStore::getLocalCopy()
* @return null|TempFSFile
*/
public function getLocalCopy(array $params)
{
list($srcCont, $srcRel) = $this->resolveStoragePathReal($params['src']);
if ($srcRel === null) {
return null;
}
// Blindly create a tmp file and stream to it, catching any exception if the file does
// not exist. Also, doing a stat here will cause infinite loops when filling metadata.
$tmpFile = null;
try {
$sContObj = $this->getContainer($srcCont);
$obj = new CF_Object($sContObj, $srcRel, false, false);
// skip HEAD
// Get source file extension
$ext = FileBackend::extensionFromPath($srcRel);
// Create a new temporary file...
$tmpFile = TempFSFile::factory('localcopy_', $ext);
if ($tmpFile) {
$handle = fopen($tmpFile->getPath(), 'wb');
if ($handle) {
$obj->stream($handle, $this->headersFromParams($params));
fclose($handle);
} else {
$tmpFile = null;
// couldn't open temp file
}
}
} catch (NoSuchContainerException $e) {
$tmpFile = null;
} catch (NoSuchObjectException $e) {
$tmpFile = null;
} catch (CloudFilesException $e) {
// some other exception?
$tmpFile = null;
$this->handleException($e, null, __METHOD__, $params);
}
return $tmpFile;
}
示例4: provider_testStore
public function provider_testStore()
{
$cases = array();
$tmpName = TempFSFile::factory("unittests_", 'txt')->getPath();
$toPath = $this->baseStorePath() . '/unittest-cont1/fun/obj1.txt';
$op = array('op' => 'store', 'src' => $tmpName, 'dst' => $toPath);
$cases[] = array($op, $tmpName, $toPath);
$op2 = $op;
$op2['overwrite'] = true;
$cases[] = array($op2, $tmpName, $toPath);
$op2 = $op;
$op2['overwriteSame'] = true;
$cases[] = array($op2, $tmpName, $toPath);
return $cases;
}
示例5: getTargetEncodePath
/**
* Get the target encode path for a video encode
*
* @param $file File
* @param $transcodeKey String
*
* @return the local target encode path
*/
static public function getTargetEncodePath( &$file, $transcodeKey ){
$filePath = self::getDerivativeFilePath( $file, $transcodeKey );
$ext = strtolower( pathinfo( "$filePath", PATHINFO_EXTENSION ) );
// Create a temp FS file with the same extension
$tmpFile = TempFSFile::factory( 'transcode_' . $transcodeKey, $ext);
if ( !$tmpFile ) {
return False;
}
$tmpFile->bind( $file );
return $tmpFile->getPath(); //path with 0-byte temp file
}
示例6: execute
public function execute()
{
$this->useTransactionalTimeLimit();
$params = $this->extractRequestParams();
$rotation = $params['rotation'];
$continuationManager = new ApiContinuationManager($this, [], []);
$this->setContinuationManager($continuationManager);
$pageSet = $this->getPageSet();
$pageSet->execute();
$result = [];
$result = $pageSet->getInvalidTitlesAndRevisions(['invalidTitles', 'special', 'missingIds', 'missingRevIds', 'interwikiTitles']);
foreach ($pageSet->getTitles() as $title) {
$r = [];
$r['id'] = $title->getArticleID();
ApiQueryBase::addTitleInfo($r, $title);
if (!$title->exists()) {
$r['missing'] = true;
if ($title->isKnown()) {
$r['known'] = true;
}
}
$file = wfFindFile($title, ['latest' => true]);
if (!$file) {
$r['result'] = 'Failure';
$r['errormessage'] = 'File does not exist';
$result[] = $r;
continue;
}
$handler = $file->getHandler();
if (!$handler || !$handler->canRotate()) {
$r['result'] = 'Failure';
$r['errormessage'] = 'File type cannot be rotated';
$result[] = $r;
continue;
}
// Check whether we're allowed to rotate this file
$permError = $this->checkPermissions($this->getUser(), $file->getTitle());
if ($permError !== null) {
$r['result'] = 'Failure';
$r['errormessage'] = $permError;
$result[] = $r;
continue;
}
$srcPath = $file->getLocalRefPath();
if ($srcPath === false) {
$r['result'] = 'Failure';
$r['errormessage'] = 'Cannot get local file path';
$result[] = $r;
continue;
}
$ext = strtolower(pathinfo("{$srcPath}", PATHINFO_EXTENSION));
$tmpFile = TempFSFile::factory('rotate_', $ext, wfTempDir());
$dstPath = $tmpFile->getPath();
$err = $handler->rotate($file, ['srcPath' => $srcPath, 'dstPath' => $dstPath, 'rotation' => $rotation]);
if (!$err) {
$comment = wfMessage('rotate-comment')->numParams($rotation)->inContentLanguage()->text();
$status = $file->upload($dstPath, $comment, $comment, 0, false, false, $this->getUser());
if ($status->isGood()) {
$r['result'] = 'Success';
} else {
$r['result'] = 'Failure';
$r['errormessage'] = $this->getErrorFormatter()->arrayFromStatus($status);
}
} else {
$r['result'] = 'Failure';
$r['errormessage'] = $err->toText();
}
$result[] = $r;
}
$apiResult = $this->getResult();
ApiResult::setIndexedTagName($result, 'page');
$apiResult->addValue(null, $this->getModuleName(), $result);
$this->setContinuationManager(null);
$continuationManager->setContinuationIntoResult($apiResult);
}
示例7: transform
/**
* Transform a media file
*
* @param array $params an associative array of handler-specific parameters.
* Typical keys are width, height and page.
* @param $flags Integer: a bitfield, may contain self::RENDER_NOW to force rendering
* @return MediaTransformOutput|bool False on failure
*/
function transform($params, $flags = 0)
{
global $wgUseSquid, $wgIgnoreImageErrors, $wgThumbnailEpoch;
wfProfileIn(__METHOD__);
do {
if (!$this->canRender()) {
$thumb = $this->iconThumb();
break;
// not a bitmap or renderable image, don't try
}
// Get the descriptionUrl to embed it as comment into the thumbnail. Bug 19791.
$descriptionUrl = $this->getDescriptionUrl();
if ($descriptionUrl) {
$params['descriptionUrl'] = wfExpandUrl($descriptionUrl, PROTO_CANONICAL);
}
$handler = $this->getHandler();
$script = $this->getTransformScript();
if ($script && !($flags & self::RENDER_NOW)) {
// Use a script to transform on client request, if possible
$thumb = $handler->getScriptedTransform($this, $script, $params);
if ($thumb) {
break;
}
}
$normalisedParams = $params;
$handler->normaliseParams($this, $normalisedParams);
$thumbName = $this->thumbName($normalisedParams);
$thumbUrl = $this->getThumbUrl($thumbName);
$thumbPath = $this->getThumbPath($thumbName);
// final thumb path
if ($this->repo) {
// Defer rendering if a 404 handler is set up...
if ($this->repo->canTransformVia404() && !($flags & self::RENDER_NOW)) {
wfDebug(__METHOD__ . " transformation deferred.");
// XXX: Pass in the storage path even though we are not rendering anything
// and the path is supposed to be an FS path. This is due to getScalerType()
// getting called on the path and clobbering $thumb->getUrl() if it's false.
$thumb = $handler->getTransform($this, $thumbPath, $thumbUrl, $params);
break;
}
// Clean up broken thumbnails as needed
$this->migrateThumbFile($thumbName);
// Check if an up-to-date thumbnail already exists...
wfDebug(__METHOD__ . ": Doing stat for {$thumbPath}\n");
if (!($flags & self::RENDER_FORCE) && $this->repo->fileExists($thumbPath)) {
$timestamp = $this->repo->getFileTimestamp($thumbPath);
if ($timestamp !== false && $timestamp >= $wgThumbnailEpoch) {
// XXX: Pass in the storage path even though we are not rendering anything
// and the path is supposed to be an FS path. This is due to getScalerType()
// getting called on the path and clobbering $thumb->getUrl() if it's false.
$thumb = $handler->getTransform($this, $thumbPath, $thumbUrl, $params);
$thumb->setStoragePath($thumbPath);
break;
}
} elseif ($flags & self::RENDER_FORCE) {
wfDebug(__METHOD__ . " forcing rendering per flag File::RENDER_FORCE\n");
}
}
// If the backend is ready-only, don't keep generating thumbnails
// only to return transformation errors, just return the error now.
if ($this->repo->getReadOnlyReason() !== false) {
$thumb = $this->transformErrorOutput($thumbPath, $thumbUrl, $params, $flags);
break;
}
// Create a temp FS file with the same extension and the thumbnail
$thumbExt = FileBackend::extensionFromPath($thumbPath);
$tmpFile = TempFSFile::factory('transform_', $thumbExt);
if (!$tmpFile) {
$thumb = $this->transformErrorOutput($thumbPath, $thumbUrl, $params, $flags);
break;
}
$tmpThumbPath = $tmpFile->getPath();
// path of 0-byte temp file
// Actually render the thumbnail...
wfProfileIn(__METHOD__ . '-doTransform');
$thumb = $handler->doTransform($this, $tmpThumbPath, $thumbUrl, $params);
wfProfileOut(__METHOD__ . '-doTransform');
$tmpFile->bind($thumb);
// keep alive with $thumb
if (!$thumb) {
// bad params?
$thumb = null;
} elseif ($thumb->isError()) {
// transform error
$this->lastError = $thumb->toText();
// Ignore errors if requested
if ($wgIgnoreImageErrors && !($flags & self::RENDER_NOW)) {
$thumb = $handler->getTransform($this, $tmpThumbPath, $thumbUrl, $params);
}
} elseif ($this->repo && $thumb->hasFile() && !$thumb->fileIsSource()) {
// Copy the thumbnail from the file system into storage...
$disposition = $this->getThumbDisposition($thumbName);
//.........这里部分代码省略.........
示例8: doTestDoOperationsPipeline
private function doTestDoOperationsPipeline()
{
$base = self::baseStorePath();
$fileAContents = '3tqtmoeatmn4wg4qe-mg3qt3 tq';
$fileBContents = 'g-jmq3gpqgt3qtg q3GT ';
$fileCContents = 'eigna[ogmewt 3qt g3qg flew[ag';
$tmpNameA = TempFSFile::factory("unittests_", 'txt')->getPath();
file_put_contents($tmpNameA, $fileAContents);
$tmpNameB = TempFSFile::factory("unittests_", 'txt')->getPath();
file_put_contents($tmpNameB, $fileBContents);
$tmpNameC = TempFSFile::factory("unittests_", 'txt')->getPath();
file_put_contents($tmpNameC, $fileCContents);
$this->filesToPrune[] = $tmpNameA;
# avoid file leaking
$this->filesToPrune[] = $tmpNameB;
# avoid file leaking
$this->filesToPrune[] = $tmpNameC;
# avoid file leaking
$fileA = "{$base}/unittest-cont1/e/a/b/fileA.txt";
$fileB = "{$base}/unittest-cont1/e/a/b/fileB.txt";
$fileC = "{$base}/unittest-cont1/e/a/b/fileC.txt";
$fileD = "{$base}/unittest-cont1/e/a/b/fileD.txt";
$this->prepare(array('dir' => dirname($fileA)));
$this->create(array('dst' => $fileA, 'content' => $fileAContents));
$this->prepare(array('dir' => dirname($fileB)));
$this->prepare(array('dir' => dirname($fileC)));
$this->prepare(array('dir' => dirname($fileD)));
$status = $this->backend->doOperations(array(array('op' => 'store', 'src' => $tmpNameA, 'dst' => $fileA, 'overwriteSame' => 1), array('op' => 'store', 'src' => $tmpNameB, 'dst' => $fileB, 'overwrite' => 1), array('op' => 'store', 'src' => $tmpNameC, 'dst' => $fileC, 'overwrite' => 1), array('op' => 'copy', 'src' => $fileA, 'dst' => $fileC, 'overwrite' => 1), array('op' => 'copy', 'src' => $fileC, 'dst' => $fileA, 'overwriteSame' => 1), array('op' => 'move', 'src' => $fileC, 'dst' => $fileD, 'overwrite' => 1), array('op' => 'move', 'src' => $fileB, 'dst' => $fileC), array('op' => 'move', 'src' => $fileD, 'dst' => $fileA, 'overwriteSame' => 1), array('op' => 'move', 'src' => $fileC, 'dst' => $fileA, 'overwrite' => 1), array('op' => 'copy', 'src' => $fileA, 'dst' => $fileC), array('op' => 'move', 'src' => $fileA, 'dst' => $fileC, 'overwriteSame' => 1), array('op' => 'copy', 'src' => $fileC, 'dst' => $fileC, 'overwrite' => 1), array('op' => 'copy', 'src' => $fileC, 'dst' => $fileC, 'overwriteSame' => 1), array('op' => 'move', 'src' => $fileC, 'dst' => $fileC, 'overwrite' => 1), array('op' => 'move', 'src' => $fileC, 'dst' => $fileC, 'overwriteSame' => 1), array('op' => 'null')));
$this->assertGoodStatus($status, "Operation batch succeeded");
$this->assertEquals(true, $status->isOK(), "Operation batch succeeded");
$this->assertEquals(16, count($status->success), "Operation batch has correct success array");
$this->assertEquals(false, $this->backend->fileExists(array('src' => $fileA)), "File does not exist at {$fileA}");
$this->assertEquals(false, $this->backend->fileExists(array('src' => $fileB)), "File does not exist at {$fileB}");
$this->assertEquals(false, $this->backend->fileExists(array('src' => $fileD)), "File does not exist at {$fileD}");
$this->assertEquals(true, $this->backend->fileExists(array('src' => $fileC)), "File exists at {$fileC}");
$this->assertEquals($fileBContents, $this->backend->getFileContents(array('src' => $fileC)), "Correct file contents of {$fileC}");
$this->assertEquals(strlen($fileBContents), $this->backend->getFileSize(array('src' => $fileC)), "Correct file size of {$fileC}");
$this->assertEquals(wfBaseConvert(sha1($fileBContents), 16, 36, 31), $this->backend->getFileSha1Base36(array('src' => $fileC)), "Correct file SHA-1 of {$fileC}");
}
示例9: makeTemporaryFile
/**
* Create a new temporary file in the URL subdirectory of wfTempDir().
*
* @return string Path to the file
*/
protected function makeTemporaryFile()
{
$tmpFile = TempFSFile::factory('URL', 'urlupload_', wfTempDir());
$tmpFile->bind($this);
return $tmpFile->getPath();
}
示例10: doGetLocalCopyMulti
protected function doGetLocalCopyMulti(array $params)
{
$tmpFiles = array();
// (path => TempFSFile)
foreach ($params['srcs'] as $srcPath) {
$src = $this->resolveHashKey($srcPath);
if ($src === null || !isset($this->files[$src])) {
$fsFile = null;
} else {
// Create a new temporary file with the same extension...
$ext = FileBackend::extensionFromPath($src);
$fsFile = TempFSFile::factory('localcopy_', $ext);
if ($fsFile) {
$bytes = file_put_contents($fsFile->getPath(), $this->files[$src]['data']);
if ($bytes !== strlen($this->files[$src]['data'])) {
$fsFile = null;
}
}
}
$tmpFiles[$srcPath] = $fsFile;
}
return $tmpFiles;
}
示例11: execute
public function execute()
{
$params = $this->extractRequestParams();
$rotation = $params['rotation'];
$this->getResult()->beginContinuation($params['continue'], array(), array());
$pageSet = $this->getPageSet();
$pageSet->execute();
$result = array();
self::addValues($result, $pageSet->getInvalidTitles(), 'invalid', 'title');
self::addValues($result, $pageSet->getSpecialTitles(), 'special', 'title');
self::addValues($result, $pageSet->getMissingPageIDs(), 'missing', 'pageid');
self::addValues($result, $pageSet->getMissingRevisionIDs(), 'missing', 'revid');
self::addValues($result, $pageSet->getInterwikiTitlesAsResult());
foreach ($pageSet->getTitles() as $title) {
$r = array();
$r['id'] = $title->getArticleID();
ApiQueryBase::addTitleInfo($r, $title);
if (!$title->exists()) {
$r['missing'] = '';
}
$file = wfFindFile($title);
if (!$file) {
$r['result'] = 'Failure';
$r['errormessage'] = 'File does not exist';
$result[] = $r;
continue;
}
$handler = $file->getHandler();
if (!$handler || !$handler->canRotate()) {
$r['result'] = 'Failure';
$r['errormessage'] = 'File type cannot be rotated';
$result[] = $r;
continue;
}
// Check whether we're allowed to rotate this file
$permError = $this->checkPermissions($this->getUser(), $file->getTitle());
if ($permError !== null) {
$r['result'] = 'Failure';
$r['errormessage'] = $permError;
$result[] = $r;
continue;
}
$srcPath = $file->getLocalRefPath();
if ($srcPath === false) {
$r['result'] = 'Failure';
$r['errormessage'] = 'Cannot get local file path';
$result[] = $r;
continue;
}
$ext = strtolower(pathinfo("{$srcPath}", PATHINFO_EXTENSION));
$tmpFile = TempFSFile::factory('rotate_', $ext);
$dstPath = $tmpFile->getPath();
$err = $handler->rotate($file, array("srcPath" => $srcPath, "dstPath" => $dstPath, "rotation" => $rotation));
if (!$err) {
$comment = wfMessage('rotate-comment')->numParams($rotation)->inContentLanguage()->text();
$status = $file->upload($dstPath, $comment, $comment, 0, false, false, $this->getUser());
if ($status->isGood()) {
$r['result'] = 'Success';
} else {
$r['result'] = 'Failure';
$r['errormessage'] = $this->getResult()->convertStatusToArray($status);
}
} else {
$r['result'] = 'Failure';
$r['errormessage'] = $err->toText();
}
$result[] = $r;
}
$apiResult = $this->getResult();
$apiResult->setIndexedTagName($result, 'page');
$apiResult->addValue(null, $this->getModuleName(), $result);
$apiResult->endContinuation();
}
示例12: getLocalCopy
/**
* @see FileBackendStore::getLocalCopy()
*/
public function getLocalCopy(array $params)
{
$source = $this->resolveToFSPath($params['src']);
if ($source === null) {
return null;
}
// Create a new temporary file with the same extension...
$ext = FileBackend::extensionFromPath($params['src']);
$tmpFile = TempFSFile::factory(wfBaseName($source) . '_', $ext);
if (!$tmpFile) {
return null;
}
$tmpPath = $tmpFile->getPath();
// Copy the source file over the temp file
$ok = copy($source, $tmpPath);
if (!$ok) {
return null;
}
$this->chmod($tmpPath);
return $tmpFile;
}
示例13: wfRenderTimeline
/**
* @param $timelinesrc string
* @return string
*/
function wfRenderTimeline($timelinesrc)
{
global $wgUploadDirectory, $wgUploadPath, $wgArticlePath, $wgTmpDirectory, $wgRenderHashAppend;
global $wgTimelineSettings;
// Get the backend to store plot data and pngs
if ($wgTimelineSettings->fileBackend != '') {
$backend = FileBackendGroup::singleton()->get($wgTimelineSettings->fileBackend);
} else {
$backend = new FSFileBackend(array('name' => 'timeline-backend', 'lockManager' => 'nullLockManager', 'containerPaths' => array('timeline-render' => "{$wgUploadDirectory}/timeline"), 'fileMode' => 777));
}
// Get a hash of the plot data
$hash = md5($timelinesrc);
if ($wgRenderHashAppend != '') {
$hash = md5($hash . $wgRenderHashAppend);
}
// Storage destination path (excluding file extension)
$fname = 'mwstore://' . $backend->getName() . "/timeline-render/{$hash}";
// Wikia change - begin
wfRunHooks('BeforeRenderTimeline', [&$backend, &$fname, $hash]);
// Wikia change - end
$previouslyFailed = $backend->fileExists(array('src' => "{$fname}.err"));
$previouslyRendered = $backend->fileExists(array('src' => "{$fname}.png"));
if ($previouslyRendered) {
$timestamp = $backend->getFileTimestamp(array('src' => "{$fname}.png"));
$expired = $timestamp < $wgTimelineSettings->epochTimestamp;
} else {
$expired = false;
}
// Create a new .map, .png (or .gif), and .err file as needed...
if ($expired || !$previouslyRendered && !$previouslyFailed) {
if (!is_dir($wgTmpDirectory)) {
mkdir($wgTmpDirectory, 0777);
}
$tmpFile = TempFSFile::factory('timeline_');
if ($tmpFile) {
$tmpPath = $tmpFile->getPath();
file_put_contents($tmpPath, $timelinesrc);
// store plot data to file
// Get command for ploticus to read the user input and output an error,
// map, and rendering (png or gif) file under the same dir as the temp file.
$cmdline = wfEscapeShellArg($wgTimelineSettings->perlCommand, $wgTimelineSettings->timelineFile) . " -i " . wfEscapeShellArg($tmpPath) . " -m -P " . wfEscapeShellArg($wgTimelineSettings->ploticusCommand) . " -T " . wfEscapeShellArg($wgTmpDirectory) . " -A " . wfEscapeShellArg($wgArticlePath) . " -f " . wfEscapeShellArg($wgTimelineSettings->fontFile);
// Actually run the command...
wfDebug("Timeline cmd: {$cmdline}\n");
$retVal = null;
$ret = wfShellExec($cmdline, $retVal);
// Copy the output files into storage...
// @TODO: store error files in another container or not at all?
$opt = array('force' => 1, 'nonLocking' => 1, 'allowStale' => 1);
// performance
$backend->prepare(array('dir' => dirname($fname)));
$backend->store(array('src' => "{$tmpPath}.map", 'dst' => "{$fname}.map"), $opt);
$backend->store(array('src' => "{$tmpPath}.png", 'dst' => "{$fname}.png"), $opt);
$backend->store(array('src' => "{$tmpPath}.err", 'dst' => "{$fname}.err"), $opt);
} else {
return "<div id=\"toc\" dir=\"ltr\"><tt>Timeline error. " . "Could not create temp file</tt></div>";
// ugh
}
if ($ret == "" || $retVal > 0) {
// Message not localized, only relevant during install
return "<div id=\"toc\" dir=\"ltr\"><tt>Timeline error. " . "Command line was: " . htmlspecialchars($cmdline) . "</tt></div>";
}
}
// Wikia change - begin
if ($backend->fileExists(array('src' => "{$fname}.err", 'latest' => true))) {
$err = $backend->getFileContents(array('src' => "{$fname}.err"));
} else {
$err = '';
}
// Wikia change - end
if ($err != "") {
// Convert the error from poorly-sanitized HTML to plain text
$err = strtr($err, array('</p><p>' => "\n\n", '<p>' => '', '</p>' => '', '<b>' => '', '</b>' => '', '<br>' => "\n"));
$err = Sanitizer::decodeCharReferences($err);
// Now convert back to HTML again
$encErr = nl2br(htmlspecialchars($err));
$txt = "<div id=\"toc\" dir=\"ltr\"><tt>{$encErr}</tt></div>";
} else {
// Wikia change - begin
if ($backend->fileExists(array('src' => "{$fname}.map", 'latest' => true))) {
$map = $backend->getFileContents(array('src' => "{$fname}.map"));
} else {
$map = '';
}
// Wikia change - end
$map = str_replace(' >', ' />', $map);
$map = "<map name=\"timeline_" . htmlspecialchars($hash) . "\">{$map}</map>";
$map = easyTimelineFixMap($map);
$url = "{$wgUploadPath}/timeline/{$hash}.png";
// Wikia change - begin
$url = wfReplaceImageServer($url);
// Wikia change - end
$txt = $map . "<img usemap=\"#timeline_" . htmlspecialchars($hash) . "\" " . "src=\"" . htmlspecialchars($url) . "\">";
if ($expired) {
// Replacing an older file, we may need to purge the old one.
global $wgUseSquid;
if ($wgUseSquid) {
//.........这里部分代码省略.........
示例14: getLocalCopy
/**
* @see FileBackend::getLocalCopy()
*/
function getLocalCopy( array $params ) {
list( $srcCont, $srcRel ) = $this->resolveStoragePath( $params['src'] );
if ( $srcRel === null ) {
return null;
}
// Get source file extension
$ext = FileBackend::extensionFromPath( $srcRel );
// Create a new temporary file...
// TODO: Caution: tempfile should not write a local file.
$tmpFile = TempFSFile::factory( wfBaseName( $srcRel ) . '_', $ext );
if ( !$tmpFile ) {
return null;
}
$tmpPath = $tmpFile->getPath();
try {
$this->storageClient->getBlob( $srcCont, $srcRel, $tmpPath );
}
catch ( Exception $e ) {
$tmpFile = null;
}
return $tmpFile;
}
示例15: concatenateChunks
/**
* Append the final chunk and ready file for parent::performUpload()
* @return FileRepoStatus
*/
public function concatenateChunks()
{
wfDebug(__METHOD__ . " concatenate {$this->mChunkIndex} chunks:" . $this->getOffset() . ' inx:' . $this->getChunkIndex() . "\n");
// Concatenate all the chunks to mVirtualTempPath
$fileList = array();
// The first chunk is stored at the mVirtualTempPath path so we start on "chunk 1"
for ($i = 0; $i <= $this->getChunkIndex(); $i++) {
$fileList[] = $this->getVirtualChunkLocation($i);
}
// Get the file extension from the last chunk
$ext = FileBackend::extensionFromPath($this->mVirtualTempPath);
// Get a 0-byte temp file to perform the concatenation at
$tmpFile = TempFSFile::factory('chunkedupload_', $ext);
$tmpPath = $tmpFile ? $tmpFile->getPath() : false;
// fail in concatenate()
// Concatenate the chunks at the temp file
$status = $this->repo->concatenate($fileList, $tmpPath, FileRepo::DELETE_SOURCE);
if (!$status->isOk()) {
return $status;
}
// Update the mTempPath and mLocalFile
// ( for FileUpload or normal Stash to take over )
$this->mTempPath = $tmpPath;
// file system path
$this->mLocalFile = parent::stashFile();
return $status;
}