本文整理汇总了PHP中LocalFile类的典型用法代码示例。如果您正苦于以下问题:PHP LocalFile类的具体用法?PHP LocalFile怎么用?PHP LocalFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LocalFile类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: purgeFromArchiveTable
protected function purgeFromArchiveTable(LocalFile $file)
{
$db = $file->getRepo()->getSlaveDB();
$res = $db->select('filearchive', array('fa_archive_name'), array('fa_name' => $file->getName()), __METHOD__);
foreach ($res as $row) {
$file->purgeOldThumbnails($row->fa_archive_name);
}
}
开发者ID:Grprashanthkumar,项目名称:ColfusionWeb,代码行数:8,代码来源:purgeDeletedFiles.php
示例2: uploadImage
/**
* Handle image upload
*
* Returns array with uploaded files details or error details
*/
public function uploadImage($uploadFieldName = self::DEFAULT_FILE_FIELD_NAME, $destFileName = null, $forceOverwrite = false)
{
global $IP, $wgRequest, $wgUser;
wfProfileIn(__METHOD__);
$ret = false;
// check whether upload is enabled (RT #53714)
if (!WikiaPhotoGalleryHelper::isUploadAllowed()) {
$ret = array('error' => true, 'message' => wfMsg('uploaddisabled'));
wfProfileOut(__METHOD__);
return $ret;
}
$imageName = stripslashes(!empty($destFileName) ? $destFileName : $wgRequest->getFileName($uploadFieldName));
// validate name and content of uploaded photo
$nameValidation = $this->checkImageName($imageName, $uploadFieldName);
if ($nameValidation == UploadBase::SUCCESS) {
// get path to uploaded image
$imagePath = $wgRequest->getFileTempName($uploadFieldName);
// check if image with this name is already uploaded
if ($this->imageExists($imageName) && !$forceOverwrite) {
// upload as temporary file
$this->log(__METHOD__, "image '{$imageName}' already exists!");
$tempName = $this->tempFileName($wgUser);
$title = Title::makeTitle(NS_FILE, $tempName);
$localRepo = RepoGroup::singleton()->getLocalRepo();
$file = new FakeLocalFile($title, $localRepo);
$file->upload($wgRequest->getFileTempName($uploadFieldName), '', '');
// store uploaded image in GarbageCollector (image will be removed if not used)
$tempId = $this->tempFileStoreInfo($tempName);
// generate thumbnail (to fit 200x200 box) of temporary file
$width = min(WikiaPhotoGalleryHelper::thumbnailMaxWidth, $file->width);
$height = min(WikiaPhotoGalleryHelper::thumbnailMaxHeight, $file->height);
$thumbnail = $file->transform(array('height' => $height, 'width' => $width));
// split uploaded file name into name + extension (foo-bar.png => foo-bar + png)
list($fileName, $extensionsName) = UploadBase::splitExtensions($imageName);
$extensionName = !empty($extensionsName) ? end($extensionsName) : '';
$this->log(__METHOD__, 'upload successful');
$ret = array('conflict' => true, 'name' => $imageName, 'nameParts' => array($fileName, $extensionName), 'tempId' => $tempId, 'size' => array('height' => $file->height, 'width' => $file->width), 'thumbnail' => array('height' => $thumbnail->height, 'url' => $thumbnail->url, 'width' => $thumbnail->width));
} else {
// use regular MW upload
$this->log(__METHOD__, "image '{$imageName}' is new one - uploading as MW file");
$this->log(__METHOD__, "uploading '{$imagePath}' as File:{$imageName}");
// create title and file objects for MW image to create
$imageTitle = Title::newFromText($imageName, NS_FILE);
$imageFile = new LocalFile($imageTitle, RepoGroup::singleton()->getLocalRepo());
// perform upload
$result = $imageFile->upload($imagePath, '', '');
$this->log(__METHOD__, !empty($result->ok) ? 'upload successful' : 'upload failed');
$ret = array('success' => !empty($result->ok), 'name' => $imageName, 'size' => array('height' => !empty($result->ok) ? $imageFile->getHeight() : 0, 'width' => !empty($result->ok) ? $imageFile->getWidth() : 0));
}
} else {
$reason = $nameValidation;
$this->log(__METHOD__, "upload failed - file name is not valid (error #{$reason})");
$ret = array('error' => true, 'reason' => $reason, 'message' => $this->translateError($reason));
}
wfProfileOut(__METHOD__);
return $ret;
}
开发者ID:Tjorriemorrie,项目名称:app,代码行数:62,代码来源:WikiaPhotoGalleryUpload.class.php
示例3: purgeVideoInfoCache
/**
* Clear cache of video info specific to given file
* @param LocalFile $file
* @return bool
*/
public static function purgeVideoInfoCache(\LocalFile $file)
{
$mediaService = new MediaQueryService();
$mediaService->clearCacheTotalVideos();
if (!$file->isLocal()) {
$mediaService->clearCacheTotalPremiumVideos();
}
if (!empty(F::app()->wg->UseVideoVerticalFilters)) {
VideoInfoHooksHelper::clearCategories($file->getTitle());
}
return true;
}
开发者ID:Tjorriemorrie,项目名称:app,代码行数:17,代码来源:VideoInfoHooksHelper.class.php
示例4: processUpload
/**
* Do the upload.
* Checks are made in SpecialUpload::execute()
*/
protected function processUpload()
{
// Fetch the file if required
$status = $this->mUpload->fetchFile();
if (!$status->isOK()) {
$this->showUploadError($this->getOutput()->parse($status->getWikiText()));
return;
}
if (!Hooks::run('UploadForm:BeforeProcessing', array(&$this))) {
wfDebug("Hook 'UploadForm:BeforeProcessing' broke processing the file.\n");
// This code path is deprecated. If you want to break upload processing
// do so by hooking into the appropriate hooks in UploadBase::verifyUpload
// and UploadBase::verifyFile.
// If you use this hook to break uploading, the user will be returned
// an empty form with no error message whatsoever.
return;
}
// Upload verification
$details = $this->mUpload->verifyUpload();
if ($details['status'] != UploadBase::OK) {
$this->processVerificationError($details);
return;
}
// Verify permissions for this title
$permErrors = $this->mUpload->verifyTitlePermissions($this->getUser());
if ($permErrors !== true) {
$code = array_shift($permErrors[0]);
$this->showRecoverableUploadError($this->msg($code, $permErrors[0])->parse());
return;
}
$this->mLocalFile = $this->mUpload->getLocalFile();
// Check warnings if necessary
if (!$this->mIgnoreWarning) {
$warnings = $this->mUpload->checkWarnings();
if ($this->showUploadWarning($warnings)) {
return;
}
}
// This is as late as we can throttle, after expected issues have been handled
if (UploadBase::isThrottled($this->getUser())) {
$this->showRecoverableUploadError($this->msg('actionthrottledtext')->escaped());
return;
}
// Get the page text if this is not a reupload
if (!$this->mForReUpload) {
$pageText = self::getInitialPageText($this->mComment, $this->mLicense, $this->mCopyrightStatus, $this->mCopyrightSource, $this->getConfig());
} else {
$pageText = false;
}
$status = $this->mUpload->performUpload($this->mComment, $pageText, $this->mWatchthis, $this->getUser());
if (!$status->isGood()) {
$this->showUploadError($this->getOutput()->parse($status->getWikiText()));
return;
}
// Success, redirect to description page
$this->mUploadSuccessful = true;
Hooks::run('SpecialUploadComplete', array(&$this));
$this->getOutput()->redirect($this->mLocalFile->getTitle()->getFullURL());
}
开发者ID:Acidburn0zzz,项目名称:mediawiki,代码行数:63,代码来源:SpecialUpload.php
示例5: newFileFromRow
function newFileFromRow($row)
{
if (isset($row->img_name)) {
return LocalFile::newFromRow($row, $this);
} elseif (isset($row->oi_name)) {
return OldLocalFile::newFromRow($row, $this);
} else {
throw new MWException(__METHOD__ . ': invalid row');
}
}
开发者ID:BackupTheBerlios,项目名称:shoutwiki-svn,代码行数:10,代码来源:LocalRepo.php
示例6: executeImage
private function executeImage()
{
if (empty($this->mParams['tempName'])) {
$this->dieUsageMsg('The tempName parameter must be set');
}
$tempFile = new FakeLocalFile(Title::newFromText($this->mParams['tempName'], 6), RepoGroup::singleton()->getLocalRepo());
$duplicate = $this->getFileDuplicate($tempFile->getLocalRefPath());
if ($duplicate) {
return array('title' => $duplicate->getTitle()->getText());
} else {
$title = $this->getUniqueTitle(wfStripIllegalFilenameChars($this->mParams['title']));
if (isset($this->mParams['license'])) {
$pageText = SpecialUpload::getInitialPageText('', $this->mParams['license']);
}
$file = new LocalFile($title, RepoGroup::singleton()->getLocalRepo());
$file->upload($tempFile->getPath(), '', $pageText ? $pageText : '');
return array('title' => $file->getTitle()->getText());
}
}
开发者ID:Tjorriemorrie,项目名称:app,代码行数:19,代码来源:ApiAddMediaPermanent.php
示例7: uploadFromUrl
/**
* @param LocalFile $file
* @param string $url
* @param string $comment
* @return FileRepoStatus
*/
private function uploadFromUrl($file, $url, $comment)
{
$tmpFile = tempnam(wfTempDir(), 'upload');
// fetch an asset
$res = Http::get($url, 'default', ['noProxy' => true]);
$this->assertTrue($res !== false, 'File from <' . $url . '> should be uploaded');
file_put_contents($tmpFile, $res);
$this->assertTrue(is_readable($tmpFile), 'Temp file for HTTP upload should be created and readable');
Wikia::log(__METHOD__, false, sprintf('uploading %s (%.2f kB) as %s', $tmpFile, filesize($tmpFile) / 1024, $file->getName()), true);
$res = $file->upload($tmpFile, $comment, '');
#unlink( $tmpFile );
return $res;
}
开发者ID:Tjorriemorrie,项目名称:app,代码行数:19,代码来源:ImagesServiceUploadTest.php
示例8: tempFileStoreInfo
/**
* Store info in the db to enable the script to pick it up later during the day (via an automated cleaning routine)
*/
public function tempFileStoreInfo($filename)
{
global $wgExternalSharedDB, $wgCityId;
wfProfileIn(__METHOD__);
$title = Title::makeTitle(NS_FILE, $filename);
$localRepo = RepoGroup::singleton()->getLocalRepo();
$path = LocalFile::newFromTitle($title, $localRepo)->getPath();
$dbw = wfGetDB(DB_MASTER, array(), $wgExternalSharedDB);
$dbw->insert('garbage_collector', array('gc_filename' => $path, 'gc_timestamp' => $dbw->timestamp(), 'gc_wiki_id' => $wgCityId), __METHOD__);
$id = $dbw->insertId();
$this->log(__METHOD__, "image stored as #{$id}");
$dbw->commit();
wfProfileOut(__METHOD__);
return $id;
}
开发者ID:schwarer2006,项目名称:wikia,代码行数:18,代码来源:WikiaTempFilesUpload.class.php
示例9: findFiles
function findFiles($titles)
{
// FIXME: Only accepts a $titles array where the keys are the sanitized
// file names.
if (count($titles) == 0) {
return array();
}
$dbr = $this->getSlaveDB();
$res = $dbr->select('image', LocalFile::selectFields(), array('img_name' => array_keys($titles)));
$result = array();
while ($row = $res->fetchObject()) {
$result[$row->img_name] = $this->newFileFromRow($row);
}
$res->free();
return $result;
}
开发者ID:amjadtbssm,项目名称:website,代码行数:16,代码来源:LocalRepo.php
示例10: saveSettings
public function saveSettings($settings, $cityId = null)
{
global $wgCityId, $wgUser;
$cityId = empty($cityId) ? $wgCityId : $cityId;
// Verify wordmark length ( CONN-116 )
if (!empty($settings['wordmark-text'])) {
$settings['wordmark-text'] = trim($settings['wordmark-text']);
}
if (empty($settings['wordmark-text'])) {
// Do not save wordmark if its empty.
unset($settings['wordmark-text']);
} else {
if (mb_strlen($settings['wordmark-text']) > 50) {
$settings['wordmark-text'] = mb_substr($settings['wordmark-text'], 0, 50);
}
}
if (isset($settings['favicon-image-name']) && strpos($settings['favicon-image-name'], 'Temp_file_') === 0) {
$temp_file = new LocalFile(Title::newFromText($settings['favicon-image-name'], 6), RepoGroup::singleton()->getLocalRepo());
$file = new LocalFile(Title::newFromText(self::FaviconImageName, 6), RepoGroup::singleton()->getLocalRepo());
$file->upload($temp_file->getPath(), '', '');
$temp_file->delete('');
Wikia::invalidateFavicon();
$settings['favicon-image-url'] = $file->getURL();
$settings['favicon-image-name'] = $file->getName();
$file->repo->forceMaster();
$history = $file->getHistory(1);
if (count($history) == 1) {
$oldFaviconFile = array('url' => $history[0]->getURL(), 'name' => $history[0]->getArchiveName());
}
}
if (isset($settings['wordmark-image-name']) && strpos($settings['wordmark-image-name'], 'Temp_file_') === 0) {
$temp_file = new LocalFile(Title::newFromText($settings['wordmark-image-name'], 6), RepoGroup::singleton()->getLocalRepo());
$file = new LocalFile(Title::newFromText(self::WordmarkImageName, 6), RepoGroup::singleton()->getLocalRepo());
$file->upload($temp_file->getPath(), '', '');
$temp_file->delete('');
$settings['wordmark-image-url'] = $file->getURL();
$settings['wordmark-image-name'] = $file->getName();
$file->repo->forceMaster();
$history = $file->getHistory(1);
if (count($history) == 1) {
$oldFile = array('url' => $history[0]->getURL(), 'name' => $history[0]->getArchiveName());
}
}
if (isset($settings['background-image-name']) && strpos($settings['background-image-name'], 'Temp_file_') === 0) {
$temp_file = new LocalFile(Title::newFromText($settings['background-image-name'], 6), RepoGroup::singleton()->getLocalRepo());
$file = new LocalFile(Title::newFromText(self::BackgroundImageName, 6), RepoGroup::singleton()->getLocalRepo());
$file->upload($temp_file->getPath(), '', '');
$temp_file->delete('');
$settings['background-image'] = $file->getURL();
$settings['background-image-name'] = $file->getName();
$settings['background-image-width'] = $file->getWidth();
$settings['background-image-height'] = $file->getHeight();
$imageServing = new ImageServing(null, 120, array("w" => "120", "h" => "65"));
$settings['user-background-image'] = $file->getURL();
$settings['user-background-image-thumb'] = wfReplaceImageServer($file->getThumbUrl($imageServing->getCut($file->getWidth(), $file->getHeight(), "origin") . "-" . $file->getName()));
$file->repo->forceMaster();
$history = $file->getHistory(1);
if (count($history) == 1) {
$oldBackgroundFile = array('url' => $history[0]->getURL(), 'name' => $history[0]->getArchiveName());
}
}
$reason = wfMsg('themedesigner-reason', $wgUser->getName());
// update history
if (!empty($GLOBALS[self::WikiFactoryHistory])) {
$history = $GLOBALS[self::WikiFactoryHistory];
$lastItem = end($history);
$revisionId = intval($lastItem['revision']) + 1;
} else {
$history = array();
$revisionId = 1;
}
// #140758 - Jakub
// validation
// default color values
foreach (ThemeDesignerHelper::getColorVars() as $sColorVar => $sDefaultValue) {
if (!isset($settings[$sColorVar]) || !ThemeDesignerHelper::isValidColor($settings[$sColorVar])) {
$settings[$sColorVar] = $sDefaultValue;
}
}
// update WF variable with current theme settings
WikiFactory::setVarByName(self::WikiFactorySettings, $cityId, $settings, $reason);
// add entry
$history[] = array('settings' => $settings, 'author' => $wgUser->getName(), 'timestamp' => wfTimestampNow(), 'revision' => $revisionId);
// limit history size to last 10 changes
$history = array_slice($history, -self::HistoryItemsLimit);
if (count($history) > 1) {
for ($i = 0; $i < count($history) - 1; $i++) {
if (isset($oldFaviconFile) && isset($history[$i]['settings']['favicon-image-name'])) {
if ($history[$i]['settings']['favicon-image-name'] == self::FaviconImageName) {
$history[$i]['settings']['favicon-image-name'] = $oldFaviconFile['name'];
$history[$i]['settings']['favicon-image-url'] = $oldFaviconFile['url'];
}
}
if (isset($oldFile) && isset($history[$i]['settings']['wordmark-image-name'])) {
if ($history[$i]['settings']['wordmark-image-name'] == self::WordmarkImageName) {
$history[$i]['settings']['wordmark-image-name'] = $oldFile['name'];
$history[$i]['settings']['wordmark-image-url'] = $oldFile['url'];
}
}
if (isset($oldBackgroundFile) && isset($history[$i]['settings']['background-image-name'])) {
//.........这里部分代码省略.........
开发者ID:Tjorriemorrie,项目名称:app,代码行数:101,代码来源:ThemeSettings.class.php
示例11: getDeletedPath
protected function getDeletedPath(LocalRepo $repo, LocalFile $file)
{
$hash = $repo->getFileSha1($file->getPath());
$key = "{$hash}.{$file->getExtension()}";
return $repo->getDeletedHashPath($key) . $key;
}
开发者ID:eliagbayani,项目名称:LiteratureEditor,代码行数:6,代码来源:purgeChangedFiles.php
示例12: findBySha1s
/**
* Get an array of arrays or iterators of file objects for files that
* have the given SHA-1 content hashes.
*
* Overrides generic implementation in FileRepo for performance reason
*
* @param $hashes array An array of hashes
* @return array An Array of arrays or iterators of file objects and the hash as key
*/
function findBySha1s(array $hashes)
{
if (!count($hashes)) {
return array();
//empty parameter
}
$dbr = $this->getSlaveDB();
$res = $dbr->select('image', LocalFile::selectFields(), array('img_sha1' => $hashes), __METHOD__, array('ORDER BY' => 'img_name'));
$result = array();
foreach ($res as $row) {
$file = $this->newFileFromRow($row);
$result[$file->getSha1()][] = $file;
}
$res->free();
return $result;
}
开发者ID:nischayn22,项目名称:mediawiki-core,代码行数:25,代码来源:LocalRepo.php
示例13: findFilesByPrefix
/**
* Return an array of files where the name starts with $prefix.
*
* @param string $prefix The prefix to search for
* @param int $limit The maximum amount of files to return
* @return array
*/
public function findFilesByPrefix($prefix, $limit)
{
$selectOptions = array('ORDER BY' => 'img_name', 'LIMIT' => intval($limit));
// Query database
$dbr = $this->getSlaveDB();
$res = $dbr->select('image', LocalFile::selectFields(), 'img_name ' . $dbr->buildLike($prefix, $dbr->anyString()), __METHOD__, $selectOptions);
// Build file objects
$files = array();
foreach ($res as $row) {
$files[] = $this->newFileFromRow($row);
}
return $files;
}
开发者ID:rugby110,项目名称:mediawiki,代码行数:20,代码来源:LocalRepo.php
示例14: testMoveTo
public function testMoveTo()
{
//existing file
$this->assertTrue(is_file(TESTS_FSI_LOCALFILE_TMP_PATH . '/myFile.ext'));
$this->assertFalse(is_file(TESTS_FSI_LOCALFILE_TMP_PATH . '/myDir/myFile.ext'));
$originalContent = file_get_contents(TESTS_FSI_LOCALFILE_TMP_PATH . '/myFile.ext');
$this->assertTrue($this->fixture_file->moveTo($this->fixture_dir));
$this->assertFalse(is_file(TESTS_FSI_LOCALFILE_TMP_PATH . '/myFile.ext'));
$this->assertTrue(is_file(TESTS_FSI_LOCALFILE_TMP_PATH . '/myDir/myFile.ext'));
$this->assertEquals($originalContent, file_get_contents(TESTS_FSI_LOCALFILE_TMP_PATH . '/myDir/myFile.ext'));
unlink(TESTS_FSI_LOCALFILE_TMP_PATH . '/myDir/myFile.ext');
//non-existing file
$this->assertFalse(is_file(TESTS_FSI_LOCALFILE_TMP_PATH . '/myFile.ext'));
try {
$this->fixture_file->moveTo($this->fixture_dir);
$fail->fail();
} catch (EyeFileNotFoundException $e) {
// normal situation
}
//existing directory containing files
mkdir(TESTS_FSI_LOCALFILE_TMP_PATH . '/dir1');
$dir = new LocalFile(TESTS_FSI_LOCALFILE_TMP_PATH . '/dir1');
$originalContent = '## test - content ##';
file_put_contents(TESTS_FSI_LOCALFILE_TMP_PATH . '/dir1/mySubFile.ext', $originalContent);
$this->assertTrue(is_dir(TESTS_FSI_LOCALFILE_TMP_PATH . '/dir1'));
$this->assertTrue(is_file(TESTS_FSI_LOCALFILE_TMP_PATH . '/dir1/mySubFile.ext'));
$this->assertTrue($dir->moveTo($this->fixture_dir));
$this->assertFalse(is_dir(TESTS_FSI_LOCALFILE_TMP_PATH . '/dir1'));
$this->assertTrue(is_dir(TESTS_FSI_LOCALFILE_TMP_PATH . '/myDir/dir1'));
$this->assertTrue(is_file(TESTS_FSI_LOCALFILE_TMP_PATH . '/myDir/dir1/mySubFile.ext'));
$this->assertEquals($originalContent, file_get_contents(TESTS_FSI_LOCALFILE_TMP_PATH . '/myDir/dir1/mySubFile.ext'));
unlink(TESTS_FSI_LOCALFILE_TMP_PATH . '/myDir/dir1/mySubFile.ext');
rmdir(TESTS_FSI_LOCALFILE_TMP_PATH . '/myDir/dir1');
}
开发者ID:DavidGarciaCat,项目名称:eyeos,代码行数:34,代码来源:LocalFileTest.php
示例15: run
/**
* @param $resultPageSet ApiPageSet
* @return void
*/
private function run($resultPageSet = null)
{
$repo = $this->mRepo;
if (!$repo instanceof LocalRepo) {
$this->dieUsage('Local file repository does not support querying all images', 'unsupportedrepo');
}
$db = $this->getDB();
$params = $this->extractRequestParams();
if (!is_null($params['continue'])) {
$cont = explode('|', $params['continue']);
if (count($cont) != 1) {
$this->dieUsage("Invalid continue param. You should pass the " . "original value returned by the previous query", "_badcontinue");
}
$op = $params['dir'] == 'descending' ? '<' : '>';
$cont_from = $db->addQuotes($cont[0]);
$this->addWhere("img_name {$op}= {$cont_from}");
}
// Image filters
$dir = $params['dir'] == 'descending' ? 'older' : 'newer';
$from = is_null($params['from']) ? null : $this->titlePartToKey($params['from']);
$to = is_null($params['to']) ? null : $this->titlePartToKey($params['to']);
$this->addWhereRange('img_name', $dir, $from, $to);
if (isset($params['prefix'])) {
$this->addWhere('img_name' . $db->buildLike($this->titlePartToKey($params['prefix']), $db->anyString()));
}
if (isset($params['minsize'])) {
$this->addWhere('img_size>=' . intval($params['minsize']));
}
if (isset($params['maxsize'])) {
$this->addWhere('img_size<=' . intval($params['maxsize']));
}
$sha1 = false;
if (isset($params['sha1'])) {
if (!$this->validateSha1Hash($params['sha1'])) {
$this->dieUsage('The SHA1 hash provided is not valid', 'invalidsha1hash');
}
$sha1 = wfBaseConvert($params['sha1'], 16, 36, 31);
} elseif (isset($params['sha1base36'])) {
$sha1 = $params['sha1base36'];
if (!$this->validateSha1Base36Hash($sha1)) {
$this->dieUsage('The SHA1Base36 hash provided is not valid', 'invalidsha1base36hash');
}
}
if ($sha1) {
$this->addWhereFld('img_sha1', $sha1);
}
if (!is_null($params['mime'])) {
global $wgMiserMode;
if ($wgMiserMode) {
$this->dieUsage('MIME search disabled in Miser Mode', 'mimesearchdisabled');
}
list($major, $minor) = File::splitMime($params['mime']);
$this->addWhereFld('img_major_mime', $major);
$this->addWhereFld('img_minor_mime', $minor);
}
$this->addTables('image');
$prop = array_flip($params['prop']);
$this->addFields(LocalFile::selectFields());
$limit = $params['limit'];
$this->addOption('LIMIT', $limit + 1);
$sort = $params['dir'] == 'descending' ? ' DESC' : '';
$this->addOption('ORDER BY', 'img_name' . $sort);
$res = $this->select(__METHOD__);
$titles = array();
$count = 0;
$result = $this->getResult();
foreach ($res as $row) {
if (++$count > $limit) {
// We've reached the one extra which shows that there are additional pages to be had. Stop here...
$this->setContinueEnumParameter('continue', $row->img_name);
break;
}
if (is_null($resultPageSet)) {
$file = $repo->newFileFromRow($row);
$info = array_merge(array('name' => $row->img_name), ApiQueryImageInfo::getInfo($file, $prop, $result));
self::addTitleInfo($info, $file->getTitle());
$fit = $result->addValue(array('query', $this->getModuleName()), null, $info);
if (!$fit) {
$this->setContinueEnumParameter('continue', $row->img_name);
break;
}
} else {
$titles[] = Title::makeTitle(NS_FILE, $row->img_name);
}
}
if (is_null($resultPageSet)) {
$result->setIndexedTagName_internal(array('query', $this->getModuleName()), 'img');
} else {
$resultPageSet->populateFromTitles($titles);
}
}
开发者ID:h4ck3rm1k3,项目名称:mediawiki,代码行数:95,代码来源:ApiQueryAllImages.php
示例16: insertImage
protected function insertImage($name, $mwname, $result)
{
global $wgRequest, $wgImageMagickConvertCommand, $wgServer;
if (!$result) {
$result = array();
} elseif ($result['error']) {
return $result;
}
$fromPage = $wgRequest->getVal('viapage');
if (!empty($mwname) && !empty($name)) {
$name = trim(urldecode($name));
$dateTime = new DateTime();
$mwDate = wfTimestamp(TS_MW);
// Mediawiki timestamp: 'YmdHis'
list($first, $ext) = self::splitFilenameExt($name);
$ext = strtolower($ext);
$validExts = array('GIF', 'JPG', 'JPEG', 'PNG');
if (!in_array(strtoupper($ext), $validExts)) {
$result['error'] = 'Error: Invalid file extension ' . strtoupper($ext) . '. Valid extensions are:';
foreach ($validExts as $validExt) {
$result['error'] .= ' ' . strtoupper($validExt);
}
$result['error'] .= '.';
return $result;
}
$saveName = false;
$titleExists = false;
$suffixNum = 1;
while (!$saveName || $titleExists) {
$saveName = 'User Completed Image ' . $fromPage . ' ' . $dateTime->format('Y.m.d H.i.s') . ' ' . $suffixNum . '.' . $ext;
$title = Title::makeTitleSafe(NS_IMAGE, $saveName);
$newFile = true;
$titleExists = $title->exists();
$suffixNum++;
}
$temp_file = new TempLocalImageFile(Title::newFromText($mwname, NS_IMAGE), RepoGroup::singleton()->getLocalRepo());
if (!$temp_file || !$temp_file->exists()) {
$result['error'] = 'Error: A server error has occurred. Please try again.';
return $result;
}
// Image orientation is a bit wonky on some mobile devices; use ImageMagick's auto-orient to try fixing it.
$tempFilePath = $temp_file->getPath();
$cmd = $wgImageMagickConvertCommand . ' ' . $tempFilePath . ' -auto-orient ' . $tempFilePath;
exec($cmd);
// Use a CC license
$comment = '{{Self}}';
$file = new LocalFile($title, RepoGroup::singleton()->getLocalRepo());
$file->upload($tempFilePath, $comment, $comment);
if (!$file || !$file->exists()) {
$result['error'] = 'Error: A server error has occurred. Please try again.';
return $result;
}
$temp_file->delete('');
$fileTitle = $file->getTitle();
$fileURL = $file->url;
$thumbURL = '';
$thumb = $file->getThumbnail(200, -1, true, true);
if (!$thumb) {
$result['error'] = 'Error: A server error has occurred. Please try again.';
$file->delete('');
return $result;
}
$thumbURL = $thumb->url;
$result['titleText'] = $fileTitle->getText();
$result['titleDBkey'] = substr($fileTitle->getDBkey(), 21);
// Only keep important info
$result['titlePreText'] = '/' . $fileTitle->getPrefixedText();
$result['titleArtID'] = $fileTitle->getArticleID();
$result['timestamp'] = $mwDate;
$result['fromPage'] = $wgRequest->getVal('viapage');
$result['thumbURL'] = $thumbURL;
$result['fileURL'] = $wgServer . $fileURL;
}
return $result;
}
开发者ID:ErdemA,项目名称:wikihow,代码行数:75,代码来源:ImageUploadHandler.class.php
示例17: execute
function execute($par)
{
global $wgOut, $wgUser, $wgRequest;
global $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview;
if ($wgUser->isBlocked()) {
$wgOut->blockedPage();
return;
}
if ($wgUser->getID() == 0) {
$wgOut->setRobotpolicy('noindex,nofollow');
$wgOut->showErrorPage('nosuchspecialpage', 'nospecialpagetext');
return;
}
if (!in_array('staff', $wgUser->getGroups())) {
$wgOut->setRobotpolicy('noindex,nofollow');
$wgOut->showErrorPage('nosuchspecialpage', 'nospecialpagetext');
return;
}
$this->errorFile = "";
$this->errorTitle = "";
if ($wgRequest->getVal('delete')) {
$wgOut->setArticleBodyOnly(true);
$hpid = str_replace('delete_', '', $wgRequest->getVal('delete'));
$html = self::deleteHPImage($hpid);
$wgOut->addHTML($html);
return;
}
$this->postSuccessful = true;
if ($wgRequest->wasPosted()) {
if ($wgRequest->getVal("updateActive")) {
$dbw = wfGetDB(DB_MASTER);
//first clear them all
$dbw->update(WikihowHomepageAdmin::HP_TABLE, array('hp_active' => 0, 'hp_order' => 0), '*', __METHOD__);
$images = $wgRequest->getArray("hp_images");
$count = 1;
foreach ($images as $image) {
if (!$image) {
continue;
}
$dbw->update(WikihowHomepageAdmin::HP_TABLE, array('hp_active' => 1, 'hp_order' => $count), array('hp_id' => $image));
$count++;
}
} else {
$title = WikiPhoto::getArticleTitleNoCheck($wgRequest->getVal('articleName'));
if (!$title->exists()) {
$this->postSuccessful = false;
$this->errorTitle = "* That article does not exist.";
}
if ($this->postSuccessful) {
//keep going
$imageTitle = Title::newFromText($wgRequest->getVal('wpDestFile'), NS_IMAGE);
$file = new LocalFile($imageTitle, RepoGroup::singleton()->getLocalRepo());
$file->upload($wgRequest->getFileTempName('wpUploadFile'), '', '');
$filesize = $file->getSize();
if ($filesize > 0) {
$dbw = wfGetDB(DB_MASTER);
$dbw->insert(WikihowHomepageAdmin::HP_TABLE, array('hp_page' => $title->getArticleID(), 'hp_image' => $imageTitle->getArticleID()));
$article = new Article($imageTitle);
$limit = array();
$limit['move'] = "sysop";
$limit['edit'] = "sysop";
$protectResult = $article->updateRestrictions($limit, "Used on homepage");
} else {
$this->postSuccessful = false;
$this->errorFile = "* We encountered an error uploading that file.";
}
}
}
}
$useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
$useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview;
$adc = wfBoolToStr($useAjaxDestCheck);
$alp = wfBoolToStr($useAjaxLicensePreview);
$wgOut->setPageTitle('WikiHow Homepage Admin');
$wgOut->addScript("<script type=\"text/javascript\">\nwgAjaxUploadDestCheck = {$adc};\nwgAjaxLicensePreview = {$alp};\n</script>");
$wgOut->addScript(HtmlSnips::makeUrlTags('js', array('jquery-ui-1.8.custom.min.js'), 'extensions/wikihow/common/ui/js', false));
$wgOut->addScript(HtmlSnips::makeUrlTags('js', array('wikihowhomepageadmin.js'), 'extensions/wikihow/homepage', false));
$wgOut->addScript(HtmlSnips::makeUrlTags('css', array('wikihowhomepageadmin.css'), 'extensions/wikihow/homepage', false));
$wgOut->addScript(HtmlSnips::makeUrlTags('js', array('upload.js'), 'skins/common', false));
$this->displayHomepageData();
$this->displayForm();
}
开发者ID:biribogos,项目名称:wikihow-src,代码行数:82,代码来源:WikihowHomepageAdmin.body.php
示例18: addMediawikiImage
/**
* Add a new image file into the mediawiki infrastructure so that it can
* be accessed as [[Image:filename.jpg]]
*/
private static function addMediawikiImage($articleID, &$image)
{
// Download the preview image and set the filename to the temporarary location
$err = self::downloadImagePreview($image);
if ($err) {
return $err;
}
// check if we've already uploaded this image
$dupTitle = DupImage::checkDupImage($image['filename']);
// if we've already uploaded this image, just return that filename
if ($dupTitle) {
//$image['dupTitle'] = true;
$image['mediawikiName'] = $dupTitle;
return '';
}
// find name for image; change filename to Filename 1.jpg if
// Filename.jpg already existed
$regexp = '/[^' . Title::legalChars() . ']+/';
$first = preg_replace($regexp, '', $image['first']);
$ext = $image['ext'];
$newName = $first . '-preview.' . $ext;
$i = 1;
do {
$title = Title::newFromText($newName, NS_IMAGE);
if ($title && !$title->exists()) {
break;
}
$newName = $first . '-preview Version ' . ++$i . '.' . $ext;
} while ($i <= 1000);
// insert image into wikihow mediawiki repos
$comment = '{{' . self::PHOTO_LICENSE . '}}';
// next 6 lines taken and modified from
// extensions/wikihow/eiu/Easyimageupload.body.php
$title = Title::makeTitleSafe(NS_IMAGE, $newName);
if (!$title) {
return "Couln't Make a title";
}
$file = new LocalFile($title, RepoGroup::singleton()->getLocalRepo());
if (!$file) {
return "Couldn't make a local file";
}
$ret = $file->upload($image['filename'], $comment, $comment);
if (!$ret->ok) {
return "Couldn't upload file " . $image['filename'];
}
// instruct later processing about which mediawiki name was used
$image['mediawikiName'] = $newName;
// Add our uploaded image to the dup table so it's no uploaded again
DupImage::addDupImage($image['filename'], $image['mediawikiName']);
return '';
}
开发者ID:ErdemA,项目名称:wikihow,代码行数:55,代码来源:wikivideoProcessVideos.php
示例19: copyFile
public static function copyFile($params)
{
$apiManager = new ApiManager();
$user = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosUser();
$cloudspace = false;
$cloudOrig = isset($params['cloud']['origin']) && strlen($params['cloud']['origin']) > 0 ? $params['cloud']['origin'] : null;
$cloudDestination = isset($params['cloud']['destination']) && strlen($params['cloud']['destination']) > 0 ? $params['cloud']['destination'] : null;
$pathCloud = "home://~" . $user->getName() . "/Cloudspaces/";
$pathOrig = null;
if ($cloudOrig) {
if ($pathCloud . $cloudOrig == $params['orig']) {
$pathOrig = "/";
} else {
$pathOrig = substr($params['orig'], strlen($pathCloud . $cloudOrig)) . "/";
}
}
if ($cloudDestination) {
$cloudspace = true;
}
$file = null;
$isFolder = true;
$tmpFile = null;
$filename = null;
$pathinfo = null;
$pathAbsolute = null;
if (!$params['file']['is_folder']) {
$isFolder = false;
$tmpFile = new LocalFile('/var/tmp/' . date('Y_m_d_H_i_s') . '_' . $user->getId());
$pathAbsolute = AdvancedPathLib::getPhpLocalHackPath($tmpFile->getAbsolutePath());
if (array_key_exists('id', $params['file'])) {
$token = $_SESSION['access_token_' . $cloudOrig . '_v2'];
$resourceUrl = null;
if (isset($params['file']['resource_url'])) {
$token = new stdClass();
$token->key = $params['access_token_key'];
$token->secret = $params['access_token_secret'];
$resourceUrl = $params['resource_url'];
}
$metadata = $apiManager->downloadMetadata($token, $params['file']['id'], $pathAbsolute, $user->getId(), true, $cloudOrig, $resourceUrl);
if ($metadata['status'] == 'KO') {
if ($metadata['error'] == 403) {
$denied = self::permissionDeniedCloud($cloudOrig);
$metadata['path'] = $denied['path'];
}
return $metadata;
} else {
if (isset($metadata['local'])) {
$file = FSI::getFile($params['file']['pathEyeos']);
$tmpFile->putContents($file->getContents());
}
}
} else {
$file = FSI::getFile($params['file']['path']);
$tmpFile->putContents($file->getContents());
}
}
if (
|
请发表评论