本文整理汇总了PHP中File::getTitle方法的典型用法代码示例。如果您正苦于以下问题:PHP File::getTitle方法的具体用法?PHP File::getTitle怎么用?PHP File::getTitle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类File
的用法示例。
在下文中一共展示了File::getTitle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkPermissions
/**
* Checks that the user has permissions to perform this revert.
* Dies with usage message on inadequate permissions.
* @param $user User The user to check.
*/
protected function checkPermissions($user)
{
$permissionErrors = array_merge($this->file->getTitle()->getUserPermissionsErrors('edit', $user), $this->file->getTitle()->getUserPermissionsErrors('upload', $user));
if ($permissionErrors) {
$this->dieUsageMsg($permissionErrors[0]);
}
}
示例2: getVideoDataByFile
/**
* get video data from file
* @param File $file
* @param boolean $premiumOnly
* @return array|null $video
*/
public function getVideoDataByFile($file, $premiumOnly = false)
{
$app = F::app();
$app->wf->ProfileIn(__METHOD__);
$video = null;
if ($file instanceof File && $file->exists() && F::build('WikiaFileHelper', array($file), 'isFileTypeVideo')) {
if (!($premiumOnly && $file->isLocal())) {
$fileMetadata = $file->getMetadata();
$userId = $file->getUser('id');
$addedAt = $file->getTimestamp() ? $file->getTimestamp() : $this->wf->Timestamp(TS_MW);
$duration = 0;
$hdfile = 0;
if ($fileMetadata) {
$fileMetadata = unserialize($fileMetadata);
if (array_key_exists('duration', $fileMetadata)) {
$duration = $fileMetadata['duration'];
}
if (array_key_exists('hd', $fileMetadata)) {
$hdfile = $fileMetadata['hd'] ? 1 : 0;
}
}
$premium = $file->isLocal() ? 0 : 1;
$video = array('videoTitle' => $file->getTitle()->getDBKey(), 'addedAt' => $addedAt, 'addedBy' => $userId, 'duration' => $duration, 'premium' => $premium, 'hdfile' => $hdfile);
}
}
$app->wf->ProfileOut(__METHOD__);
return $video;
}
示例3: getDescLinkAttribs
/**
* @param $title string
* @param $params string|array Query parameters to add
* @return array
*/
public function getDescLinkAttribs( $title = null, $params = array() ) {
if ( is_array( $params ) ) {
$query = $params;
} else {
$query = array();
}
if ( $this->page && $this->page !== 1 ) {
$query['page'] = $this->page;
}
if ( $this->lang ) {
$query['lang'] = $this->lang;
}
if ( is_string( $params ) && $params !== '' ) {
$query = $params . '&' . wfArrayToCgi( $query );
}
$attribs = array(
'href' => $this->file->getTitle()->getLocalURL( $query ),
'class' => 'image',
);
if ( $title ) {
$attribs['title'] = $title;
}
return $attribs;
}
示例4: getDescLinkAttribs
/**
* @param $title string
* @param string $params
* @return array
*/
public function getDescLinkAttribs($title = null, $params = '')
{
$query = $this->page ? 'page=' . urlencode($this->page) : '';
if ($params) {
$query .= $query ? '&' . $params : $params;
}
$attribs = array('href' => $this->file->getTitle()->getLocalURL($query), 'class' => 'image');
if ($title) {
$attribs['title'] = $title;
}
return $attribs;
}
示例5: getDataParams
/**
* Get data-params attribute (for video on mobile)
* @param File $file
* @param string $imgSrc
* @param array $options
* @return string
*/
public static function getDataParams($file, $imgSrc, $options)
{
if (is_callable([$file, 'getProviderName'])) {
$provider = $file->getProviderName();
} else {
$provider = '';
}
$dataParams = ['type' => 'video', 'name' => htmlspecialchars($file->getTitle()->getDBKey()), 'full' => $imgSrc, 'provider' => $provider];
if (!empty($options['caption'])) {
$dataParams['capt'] = 1;
}
return htmlentities(json_encode([$dataParams]), ENT_QUOTES);
}
示例6: run
function run($filename)
{
$path = UPLOAD_PATH . DIRECTORY_SEPARATOR . $filename;
if (!is_readable($path)) {
$path = APP_ATTACHMENT_URL . $filename;
}
$finfo = new finfo(FILEINFO_MIME);
$content = file_get_contents($path);
$file = new File();
$name = $file->findFileByUrl($filename) ? $file->getTitle() : $filename;
$mime = $finfo->buffer($content);
header('Content-Type: ' . $mime);
header('Content-Disposition: attachment; filename="' . $name . '"');
echo $content;
}
示例7: getExistsWarning
/**
* Helper function that does various existence checks for a file.
* The following checks are performed:
* - The file exists
* - Article with the same name as the file exists
* - File exists with normalized extension
* - The file looks like a thumbnail and the original exists
*
* @param File $file The File object to check
* @return mixed False if the file does not exists, else an array
*/
public static function getExistsWarning($file)
{
if ($file->exists()) {
return ['warning' => 'exists', 'file' => $file];
}
if ($file->getTitle()->getArticleID()) {
return ['warning' => 'page-exists', 'file' => $file];
}
if (strpos($file->getName(), '.') == false) {
$partname = $file->getName();
$extension = '';
} else {
$n = strrpos($file->getName(), '.');
$extension = substr($file->getName(), $n + 1);
$partname = substr($file->getName(), 0, $n);
}
$normalizedExtension = File::normalizeExtension($extension);
if ($normalizedExtension != $extension) {
// We're not using the normalized form of the extension.
// Normal form is lowercase, using most common of alternate
// extensions (eg 'jpg' rather than 'JPEG').
// Check for another file using the normalized form...
$nt_lc = Title::makeTitle(NS_FILE, "{$partname}.{$normalizedExtension}");
$file_lc = wfLocalFile($nt_lc);
if ($file_lc->exists()) {
return ['warning' => 'exists-normalized', 'file' => $file, 'normalizedFile' => $file_lc];
}
}
// Check for files with the same name but a different extension
$similarFiles = RepoGroup::singleton()->getLocalRepo()->findFilesByPrefix("{$partname}.", 1);
if (count($similarFiles)) {
return ['warning' => 'exists-normalized', 'file' => $file, 'normalizedFile' => $similarFiles[0]];
}
if (self::isThumbName($file->getName())) {
# Check for filenames like 50px- or 180px-, these are mostly thumbnails
$nt_thb = Title::newFromText(substr($partname, strpos($partname, '-') + 1) . '.' . $extension, NS_FILE);
$file_thb = wfLocalFile($nt_thb);
if ($file_thb->exists()) {
return ['warning' => 'thumb', 'file' => $file, 'thumbFile' => $file_thb];
} else {
// File does not exist, but we just don't like the name
return ['warning' => 'thumb-name', 'file' => $file, 'thumbFile' => $file_thb];
}
}
foreach (self::getFilenamePrefixBlacklist() as $prefix) {
if (substr($partname, 0, strlen($prefix)) == $prefix) {
return ['warning' => 'bad-prefix', 'file' => $file, 'prefix' => $prefix];
}
}
return false;
}
示例8: openShowImage
protected function openShowImage()
{
global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgLang, $wgEnableUploads, $wgSend404Code;
$this->loadFile();
$sizeSel = intval($wgUser->getOption('imagesize'));
if (!isset($wgImageLimits[$sizeSel])) {
$sizeSel = User::getDefaultOption('imagesize');
// The user offset might still be incorrect, specially if
// $wgImageLimits got changed (see bug #8858).
if (!isset($wgImageLimits[$sizeSel])) {
// Default to the first offset in $wgImageLimits
$sizeSel = 0;
}
}
$max = $wgImageLimits[$sizeSel];
$maxWidth = $max[0];
$maxHeight = $max[1];
$dirmark = $wgLang->getDirMark();
if ($this->displayImg->exists()) {
# image
$page = $wgRequest->getIntOrNull('page');
if (is_null($page)) {
$params = array();
$page = 1;
} else {
$params = array('page' => $page);
}
$width_orig = $this->displayImg->getWidth($page);
$width = $width_orig;
$height_orig = $this->displayImg->getHeight($page);
$height = $height_orig;
$longDesc = wfMsg('parentheses', $this->displayImg->getLongDesc());
wfRunHooks('ImageOpenShowImageInlineBefore', array(&$this, &$wgOut));
if ($this->displayImg->allowInlineDisplay()) {
# image
# "Download high res version" link below the image
# $msgsize = wfMsgHtml( 'file-info-size', $width_orig, $height_orig, Linker::formatSize( $this->displayImg->getSize() ), $mime );
# We'll show a thumbnail of this image
if ($width > $maxWidth || $height > $maxHeight) {
# Calculate the thumbnail size.
# First case, the limiting factor is the width, not the height.
if ($width / $height >= $maxWidth / $maxHeight) {
$height = round($height * $maxWidth / $width);
$width = $maxWidth;
# Note that $height <= $maxHeight now.
} else {
$newwidth = floor($width * $maxHeight / $height);
$height = round($height * $newwidth / $width);
$width = $newwidth;
# Note that $height <= $maxHeight now, but might not be identical
# because of rounding.
}
$msgbig = wfMsgHtml('show-big-image');
$otherSizes = array();
foreach ($wgImageLimits as $size) {
if ($size[0] < $width_orig && $size[1] < $height_orig && $size[0] != $width && $size[1] != $height) {
$otherSizes[] = $this->makeSizeLink($params, $size[0], $size[1]);
}
}
$msgsmall = wfMessage('show-big-image-preview')->rawParams($this->makeSizeLink($params, $width, $height))->parse();
if (count($otherSizes) && $this->displayImg->getRepo()->canTransformVia404()) {
$msgsmall .= ' ' . Html::rawElement('span', array('class' => 'mw-filepage-other-resolutions'), wfMessage('show-big-image-other')->rawParams($wgLang->pipeList($otherSizes))->params(count($otherSizes))->parse());
}
} elseif ($width == 0 && $height == 0) {
# Some sort of audio file that doesn't have dimensions
# Don't output a no hi res message for such a file
$msgsmall = '';
} else {
# Image is small enough to show full size on image page
$msgsmall = wfMessage('file-nohires')->parse();
}
$params['width'] = $width;
$params['height'] = $height;
$thumbnail = $this->displayImg->transform($params);
$showLink = true;
$anchorclose = Html::rawElement('div', array('class' => 'mw-filepage-resolutioninfo'), $msgsmall);
$isMulti = $this->displayImg->isMultipage() && $this->displayImg->pageCount() > 1;
if ($isMulti) {
$wgOut->addHTML('<table class="multipageimage"><tr><td>');
}
if ($thumbnail) {
$options = array('alt' => $this->displayImg->getTitle()->getPrefixedText(), 'file-link' => true);
$wgOut->addHTML('<div class="fullImageLink" id="file">' . $thumbnail->toHtml($options) . $anchorclose . "</div>\n");
}
if ($isMulti) {
$count = $this->displayImg->pageCount();
if ($page > 1) {
$label = $wgOut->parse(wfMsg('imgmultipageprev'), false);
$link = Linker::link($this->getTitle(), $label, array(), array('page' => $page - 1), array('known', 'noclasses'));
$thumb1 = Linker::makeThumbLinkObj($this->getTitle(), $this->displayImg, $link, $label, 'none', array('page' => $page - 1));
} else {
$thumb1 = '';
}
if ($page < $count) {
$label = wfMsg('imgmultipagenext');
$link = Linker::link($this->getTitle(), $label, array(), array('page' => $page + 1), array('known', 'noclasses'));
$thumb2 = Linker::makeThumbLinkObj($this->getTitle(), $this->displayImg, $link, $label, 'none', array('page' => $page + 1));
} else {
$thumb2 = '';
}
//.........这里部分代码省略.........
示例9: setFile
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;
}
示例10: onFileUpload
public static function onFileUpload(File $file)
{
self::updateTitle($file->getTitle(), 'file');
return true;
}
示例11: processMissingFile
/**
* @param LocalFile $file file to check
* @return int RESULT_* flag
* @see BAC-731
*/
private function processMissingFile(File $file)
{
global $wgUploadDirectory, $wgCityId;
try {
$exists = $this->repo->fileExists($file->getPath());
} catch (Exception $ex) {
$exists = true;
$this->error(sprintf("%s caught: %s", get_class($ex), $ex->getMessage()));
}
// file is fine, continue...
if ($exists) {
return self::RESULT_EXISTS;
}
$restored = false;
$this->output(sprintf("'%s' doesn't exist (%s)\n", $file->getTitle(), $file->getUrlRel()));
// let's assume that given file was moved from A
// let's get all possible A's and try to find images for them
$candidates = $this->getCandidates($file);
if (empty($candidates) && !empty($this->otherLocation)) {
# check other location - maybe this file is there :)
$candidates = $this->checkOtherLocation($file);
}
if (!empty($candidates)) {
$this->output(sprintf(" %d candidate(s) found...\n", count($candidates)));
foreach ($candidates as $candidate) {
$srcFile = LocalFile::newFromTitle($candidate, $this->repo);
$srcPath = $wgUploadDirectory . '/' . $srcFile->getUrlRel();
// check on FS storage
$foundOnFS = file_exists($srcPath);
$this->output(sprintf(" '%s' -> <%s> [%s]\n", $srcFile->getName(), $srcPath, $foundOnFS ? 'found' : 'not found'));
// check the next candidate (or if --dry-run)
if (!$foundOnFS || $this->isDryRun) {
continue;
}
// upload found image to Swift
$swift = \Wikia\SwiftStorage::newFromWiki($wgCityId);
$metadata = ['Sha1Base36' => $file->getSha1()];
$status = $swift->store($srcPath, $file->getUrlRel(), $metadata, $file->getMimeType());
if ($status->isOK()) {
self::log('restored', $file->getName());
$restored = true;
break;
}
}
$this->output("\n");
}
// remove an image if it can't be restored
if (!$restored && !$this->isDryRun) {
$file->delete(self::REASON);
$this->output(sprintf(" Removed '%s'!\n", $file->getName()));
self::log('removed', $file->getName());
}
return $restored ? self::RESULT_RESTORED : self::RESULT_NOT_RESTORED;
}
示例12: resetVideoThumb
/**
* Reset the video thumbnail to its original image as defined by the video provider.
* @param File $file The video file to reset
* @param string|null $thumbnailUrl
* @param int $delayIndex Corresponds to a delay for a job to be queued up if we aren't
* able to reset the thumbnail. This index corresponds to a class constant kept in the
* ApiWrapper classes.
* @return FileRepoStatus The status of the publish operation
*/
public function resetVideoThumb(File $file, $thumbnailUrl = null, $delayIndex = 0)
{
$mime = $file->getMimeType();
list(, $provider) = explode('/', $mime);
$videoId = $file->getVideoId();
$title = $file->getTitle();
$oUploader = new VideoFileUploader();
$oUploader->setProvider($provider);
$oUploader->setVideoId($videoId);
$oUploader->setTargetTitle($title->getDBkey());
if (empty($thumbnailUrl)) {
$thumbnailUrl = $oUploader->getApiWrapper()->getThumbnailUrl();
}
$result = $oUploader->resetThumbnail($file, $thumbnailUrl, $delayIndex);
if ($result->isGood()) {
// update data and clear cache
$status = $this->updateThumbnailData($file);
if (!$status->isGood()) {
$result->fatal($status->getMessage());
}
}
return $result;
}
示例13: onFileDeleteComplete
/**
* If a file is deleted, check if the sha1 (and timestamp?) exist in the
* approved_revs_files table, and delete that row accordingly. A deleted
* version of a file should not be the approved version!
**/
public static function onFileDeleteComplete(File $file, $oldimage, $article, $user, $reason)
{
$dbr = wfGetDB(DB_SLAVE);
// check if this file has an approved revision
$approvedFile = $dbr->selectRow('approved_revs_files', array('approved_timestamp', 'approved_sha1'), array('file_title' => $file->getTitle()->getDBkey()));
// If an approved revision exists, loop through all files in history.
// Since this hook happens AFTER deletion (there is no hook before deletion), check to see
// if the sha1 of the approved revision is NOT in the history. If it is not in the history,
// then it has no business being in the approved_revs_files table, and should be deleted.
if ($approvedFile) {
$revs = array();
$approvedExists = false;
$hist = $file->getHistory();
foreach ($hist as $OldLocalFile) {
// need to check both sha1 and timestamp, since reverted files can have the same
// sha1, but different timestamps
if ($OldLocalFile->getTimestamp() == $approvedFile->approved_timestamp && $OldLocalFile->getSha1() == $approvedFile->approved_sha1) {
$approvedExists = true;
}
}
if (!$approvedExists) {
ApprovedRevs::unsetApprovedFileInDB($file->getTitle());
}
}
return true;
}
示例14: writeViewData
/**
* writeViewData
* @param File $objFile
* @author Cornelius Hansjakob <cha@massiveart.at>
* @version 1.0
*/
private function writeViewData(File &$objFile)
{
$this->core->logger->debug('media->controllers->UploadController->writeViewData()');
$this->view->assign('fileId', $objFile->getId());
$this->view->assign('fileFileId', $objFile->getFileId());
$this->view->assign('fileExtension', $objFile->getExtension());
$this->view->assign('fileTitle', $objFile->getTitle());
$this->view->assign('mimeType', $objFile->getMimeType());
$this->view->assign('strDefaultDescription', 'Beschreibung hinzufügen...');
// TODO : guiTexts
$this->view->assign('languageId', 1);
// TODO : language
}
示例15: onThumbnailVideoHTML
public static function onThumbnailVideoHTML($options, $linkAttribs, $imageAttribs, File $file, &$html)
{
global $wgRTEParserEnabled;
if (!empty($wgRTEParserEnabled)) {
return true;
}
if (is_null(self::$isWikiaMobile)) {
self::init();
}
if (self::$isWikiaMobile) {
wfProfileIn(__METHOD__);
/**
* WikiaMobile: lazy loading images in a SEO-friendly manner
* @author Federico "Lox" Lucignano <federico@wikia-inc.com
* @author Artur Klajnerok <arturk@wikia-inc.com>
*/
$origImg = Xml::element('img', $imageAttribs, '', true);
if (empty($imageAttribs['alt'])) {
unset($imageAttribs['alt']);
}
//Not all 'files' have getProviderName defined
if (is_callable([$file, 'getProviderName'])) {
$provider = $file->getProviderName();
} else {
$provider = '';
}
$imageParams = array('type' => 'video', 'provider' => $provider, 'full' => $imageAttribs['src']);
if (!empty($imageAttribs['data-video-key'])) {
$imageParams['name'] = htmlspecialchars($imageAttribs['data-video-key']);
}
if (!empty($options['caption'])) {
$imageParams['capt'] = 1;
}
// TODO: this resizes every video thumbnail with a width over 64px regardless of where it appears.
// We may want to add the ability to allow custom image widths (like on the file page history table for example)
$size = WikiaMobileMediaService::calculateMediaSize($file->getWidth(), $file->getHeight());
$thumb = $file->transform($size);
$imageAttribs['src'] = wfReplaceImageServer($thumb->getUrl(), $file->getTimestamp());
$imageAttribs['width'] = $size['width'];
$imageAttribs['height'] = $size['height'];
$data = ['attributes' => $imageAttribs, 'parameters' => [$imageParams], 'anchorAttributes' => $linkAttribs, 'noscript' => $origImg, 'isSmall' => WikiaMobileMediaService::isSmallImage($imageAttribs['width'], $imageAttribs['height'])];
$title = $file->getTitle()->getDBKey();
$titleText = $file->getTitle()->getText();
$views = MediaQueryService::getTotalVideoViewsByTitle($title);
$data['content'] = Xml::element('span', ['class' => 'videoInfo'], "{$titleText} (" . $file->getHandler()->getFormattedDuration() . ", " . wfMessage('wikiamobile-video-views-counter', $views)->inContentLanguage()->text() . ')');
$html = F::app()->sendRequest('WikiaMobileMediaService', 'renderImageTag', $data, true)->toString();
wfProfileOut(__METHOD__);
}
return true;
}