本文整理汇总了PHP中LocalFile::exists方法的典型用法代码示例。如果您正苦于以下问题:PHP LocalFile::exists方法的具体用法?PHP LocalFile::exists怎么用?PHP LocalFile::exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LocalFile
的用法示例。
在下文中一共展示了LocalFile::exists方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validateParameters
/**
* Validate the user parameters and set $this->archiveName and $this->file.
* Throws an error if validation fails
*/
protected function validateParameters()
{
// Validate the input title
$title = Title::makeTitleSafe(NS_FILE, $this->params['filename']);
if (is_null($title)) {
$this->dieUsageMsg(array('invalidtitle', $this->params['filename']));
}
$localRepo = RepoGroup::singleton()->getLocalRepo();
// Check if the file really exists
$this->file = $localRepo->newFile($title);
if (!$this->file->exists()) {
$this->dieUsageMsg('notanarticle');
}
// Check if the archivename is valid for this file
$this->archiveName = $this->params['archivename'];
$oldFile = $localRepo->newFromArchiveName($title, $this->archiveName);
if (!$oldFile->exists()) {
$this->dieUsageMsg('filerevert-badversion');
}
}
示例2: purgeFromArchiveTable
protected function purgeFromArchiveTable(LocalRepo $repo, LocalFile $file)
{
$dbr = $repo->getSlaveDB();
$res = $dbr->select('filearchive', array('fa_archive_name'), array('fa_name' => $file->getName()), __METHOD__);
foreach ($res as $row) {
if ($row->fa_archive_name === null) {
// Was not an old version (current version names checked already)
continue;
}
$ofile = $repo->newFromArchiveName($file->getTitle(), $row->fa_archive_name);
// If there is an orphaned storage file still there...delete it
if (!$file->exists() && $repo->fileExists($ofile->getPath())) {
$dpath = $this->getDeletedPath($repo, $ofile);
if ($repo->fileExists($dpath)) {
// Sanity check to avoid data loss
$repo->getBackend()->delete(array('src' => $ofile->getPath()));
$this->output("Deleted orphan file: {$ofile->getPath()}.\n");
} else {
$this->error("File was not deleted: {$ofile->getPath()}.\n");
}
}
$file->purgeOldThumbnails($row->fa_archive_name);
}
}
示例3: exists
/**
* If archive name is an empty string, then file does not "exist"
*
* This is the case for a couple files on Wikimedia servers where
* the old version is "lost".
*/
public function exists()
{
$archiveName = $this->getArchiveName();
if ($archiveName === '' || !is_string($archiveName)) {
return false;
}
return parent::exists();
}
示例4: 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;
}
示例5: deleteImageHelper
protected function deleteImageHelper($imageName)
{
$title = Title::newFromText($imageName, NS_FILE);
$file = new LocalFile($title, RepoGroup::singleton()->getLocalRepo());
$visualization = new CityVisualization();
$visualization->removeImageFromReview($this->wg->cityId, $title->getArticleId(), $this->wg->contLang->getCode());
if ($file->exists()) {
$file->delete('no longer needed');
}
}