/** * 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]); } }
/** * 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; }
/** * @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; }
/** * @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; }
/** * 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); }
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; }
/** * 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; }
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 = ''; } global $wgScript; $formParams = array('name' => 'pageselector', 'action' => $wgScript, 'onchange' => 'document.pageselector.submit();'); $options = array(); for ($i = 1; $i <= $count; $i++) { $options[] = Xml::option($wgLang->formatNum($i), $i, $i == $page); } $select = Xml::tags('select', array('id' => 'pageselector', 'name' => 'page'), implode("\n", $options)); $wgOut->addHTML('</td><td><div class="multipageimagenavbox">' . Xml::openElement('form', $formParams) . Html::hidden('title', $this->getTitle()->getPrefixedDBkey()) . wfMsgExt('imgmultigoto', array('parseinline', 'replaceafter'), $select) . Xml::submitButton(wfMsg('imgmultigo')) . Xml::closeElement('form') . "<hr />{$thumb1}\n{$thumb2}<br style=\"clear: both\" /></div></td></tr></table>"); } } else { # if direct link is allowed but it's not a renderable image, show an icon. if ($this->displayImg->isSafeFile()) { $icon = $this->displayImg->iconThumb(); $wgOut->addHTML('<div class="fullImageLink" id="file">' . $icon->toHtml(array('file-link' => true)) . "</div>\n"); } $showLink = true; } if ($showLink) { $filename = wfEscapeWikiText($this->displayImg->getName()); $linktext = $filename; if (isset($msgbig)) { $linktext = wfEscapeWikiText($msgbig); } $medialink = "[[Media:{$filename}|{$linktext}]]"; if (!$this->displayImg->isSafeFile()) { $warning = wfMsgNoTrans('mediawarning'); $wgOut->addWikiText(<<<EOT <div class="fullMedia"><span class="dangerousLink">{$medialink}</span>{$dirmark} <span class="fileInfo">{$longDesc}</span></div> <div class="mediaWarning">{$warning}</div> EOT ); } else { $wgOut->addWikiText(<<<EOT <div class="fullMedia">{$medialink}{$dirmark} <span class="fileInfo">{$longDesc}</span> </div> EOT ); } } if (!$this->displayImg->isLocal()) { $this->printSharedImageText(); } } else { # Image does not exist if ($wgEnableUploads && $wgUser->isAllowed('upload')) { // Only show an upload link if the user can upload $uploadTitle = SpecialPage::getTitleFor('Upload'); $nofile = array('filepage-nofile-link', $uploadTitle->getFullURL(array('wpDestFile' => $this->mPage->getFile()->getName()))); } else { $nofile = 'filepage-nofile'; } // Note, if there is an image description page, but // no image, then this setRobotPolicy is overriden // by Article::View(). $wgOut->setRobotPolicy('noindex,nofollow'); $wgOut->wrapWikiMsg("<div id='mw-imagepage-nofile' class='plainlinks'>\n\$1\n</div>", $nofile); if (!$this->getID() && $wgSend404Code) { // If there is no image, no shared image, and no description page, // output a 404, to be consistent with articles. $wgRequest->response()->header('HTTP/1.1 404 Not Found'); } } $wgOut->setFileVersion($this->displayImg); }
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; }
public static function onFileUpload(File $file) { self::updateTitle($file->getTitle(), 'file'); return true; }
/** * @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; }
/** * 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; }
/** * 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; }
/** * writeViewData * @param File $objFile * @author Cornelius Hansjakob <*****@*****.**> * @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 }
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 <*****@*****.**> */ $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; }
/** * * @param Skin $skin * @param File $result * @return string */ function formatResult($skin, $result) { global $wgContLang, $wgLang; $nt = $result->getTitle(); $text = $wgContLang->convert($nt->getText()); $plink = $skin->link(Title::newFromText($nt->getPrefixedText()), $text); $userText = $result->getUser('text'); $user = $skin->link(Title::makeTitle(NS_USER, $userText), $userText); $time = $wgLang->timeanddate($result->getTimestamp()); return "{$plink} . . {$user} . . {$time}"; }
/** * Check if the premium video is added to the wiki * @param File $file * @return boolean $isAdded */ public static function isAdded($file) { $isAdded = true; if ($file instanceof File && !$file->isLocal() && F::app()->wg->WikiaVideoRepoDBName == $file->getRepo()->getWiki()) { $info = VideoInfo::newFromTitle($file->getTitle()->getDBkey()); if (empty($info)) { $isAdded = false; } } return $isAdded; }
/** * Return placeholder than will later be parsed by ImageServing * * @param File $file * @return string|bool placeholder's HTML or false when image doesn't exist */ public static function getPlaceholder($file) { $res = false; if ($file instanceof File || $file instanceof LocalFile) { /* @var File $file */ $res = " <image mw='" . $file->getTitle()->getPartialURL() . "' /> "; } return $res; }
/** * (a) Update flaggedrevs page/tracking tables * (b) Pages with stable versions that use this page will be purged * Note: pages with current versions that use this page should already be purged */ public static function onFileUpload(File $file) { FlaggedRevs::stableVersionUpdates($file->getTitle()); FlaggedRevs::extraHTMLCacheUpdate($file->getTitle()); return true; }
public function onThumbnailVideoHTML($options, $linkAttribs, $imageAttribs, File $file, &$html) { $this->wf->profileIn(__METHOD__); if (self::$isWikiaMobile) { /** * WikiaMobile: lazy loading images in a SEO-friendly manner * @author Federico "Lox" Lucignano <federico@wikia-inc.com * @author Artur Klajnerok <*****@*****.**> */ $origImg = Xml::element('img', $imageAttribs, '', true); if (empty($imageAttribs['alt'])) { unset($imageAttribs['alt']); } $imageParams = array('type' => 'video', 'full' => $imageAttribs['src']); if (!empty($linkAttribs['data-video-name'])) { $imageParams['name'] = $linkAttribs['data-video-name']; } if (!empty($options['caption'])) { $imageParams['capt'] = true; } if ($file instanceof File) { $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 = array('attributes' => $imageAttribs, 'parameters' => array($imageParams), 'anchorAttributes' => $linkAttribs, 'noscript' => $origImg); if ($file instanceof File) { $title = $file->getTitle()->getDBKey(); $titleText = $file->getTitle()->getText(); $data['content'] = Xml::element('span', array('class' => 'videoInfo'), "{$titleText} (" . $file->getHandler()->getFormattedDuration() . ", " . $this->wf->MsgForContent('wikiamobile-video-views-counter', MediaQueryService::getTotalVideoViewsByTitle($title)) . ')'); } $html = $this->app->sendRequest('WikiaMobileMediaService', 'renderImageTag', $data, true)->toString(); } $this->wf->profileOut(__METHOD__); return true; }
/** * * @param Skin $skin * @param File $result * @return string HTML */ function formatResult($skin, $result) { global $wgContLang; $nt = $result->getTitle(); $text = $wgContLang->convert($nt->getText()); $plink = Linker::link($nt, htmlspecialchars($text)); $userText = $result->getUser('text'); if ($result->isLocal()) { $userId = $result->getUser('id'); $user = Linker::userLink($userId, $userText); $user .= '<span style="white-space: nowrap;">'; $user .= Linker::userToolLinks($userId, $userText); $user .= '</span>'; } else { $user = htmlspecialchars($userText); } $time = htmlspecialchars($this->getLanguage()->userTimeAndDate($result->getTimestamp(), $this->getUser())); return "{$plink} . . {$user} . . {$time}"; }
/** * 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; }
/** * Constructor * * @param File $file File we're reverting */ public function __construct($file) { $this->title = $file->getTitle(); $this->file = $file; }
/** @inheritdoc */ public function toArray() { $data = array('id' => $this->id, 'owner' => $this->owner->getName(), 'title' => $this->title, 'description' => $this->description, 'public' => $this->public, 'isWatchlist' => $this->isWatchlist, 'image' => $this->image ? $this->image->getTitle()->getText() : null); return $data; }
/** * Get file-based metadata in standardized format. * * Note that for a remote file, this might return metadata supplied by extensions. * * @param File $file File to use * @return array [<property name> => ['value' => <value>]], or [] on error * @since 1.23 */ protected function getExtendedMetadataFromFile(File $file) { // If this is a remote file accessed via an API request, we already // have remote metadata so we just ignore any local one if ($file instanceof ForeignAPIFile) { // In case of error we pretend no metadata - this will get cached. // Might or might not be a good idea. return $file->getExtendedMetadata() ?: []; } $uploadDate = wfTimestamp(TS_ISO_8601, $file->getTimestamp()); $fileMetadata = ['DateTime' => ['value' => $uploadDate, 'source' => 'mediawiki-metadata']]; $title = $file->getTitle(); if ($title) { $text = $title->getText(); $pos = strrpos($text, '.'); if ($pos) { $name = substr($text, 0, $pos); } else { $name = $text; } $fileMetadata['ObjectName'] = ['value' => $name, 'source' => 'mediawiki-metadata']; } return $fileMetadata; }
/** * writeViewData * @param File $objFile * @author Cornelius Hansjakob <*****@*****.**> * @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('fileVersion', $objFile->getVersion()); $this->view->assign('filePath', sprintf($this->core->sysConfig->media->paths->icon32, $objFile->getSegmentPath())); $this->view->assign('mimeType', $objFile->getMimeType()); $this->view->assign('strDefaultDescription', $this->core->translate->_('Add_description_')); $this->view->assign('languageId', $this->intLanguageId); }
protected function openShowImage() { global $wgImageLimits, $wgEnableUploads, $wgSend404Code; $this->loadFile(); $out = $this->getContext()->getOutput(); $user = $this->getContext()->getUser(); $lang = $this->getContext()->getLanguage(); $dirmark = $lang->getDirMarkEntity(); $request = $this->getContext()->getRequest(); $max = $this->getImageLimitsFromOption($user, 'imagesize'); $maxWidth = $max[0]; $maxHeight = $max[1]; if ($this->displayImg->exists()) { # image $page = $request->getIntOrNull('page'); if (is_null($page)) { $params = array(); $page = 1; } else { $params = array('page' => $page); } $renderLang = $request->getVal('lang'); if (!is_null($renderLang)) { $handler = $this->displayImg->getHandler(); if ($handler && $handler->validateParam('lang', $renderLang)) { $params['lang'] = $renderLang; } else { $renderLang = null; } } $width_orig = $this->displayImg->getWidth($page); $width = $width_orig; $height_orig = $this->displayImg->getHeight($page); $height = $height_orig; $filename = wfEscapeWikiText($this->displayImg->getName()); $linktext = $filename; wfRunHooks('ImageOpenShowImageInlineBefore', array(&$this, &$out)); if ($this->displayImg->allowInlineDisplay()) { # image # "Download high res version" link below the image # $msgsize = wfMessage( 'file-info-size', $width_orig, $height_orig, Linker::formatSize( $this->displayImg->getSize() ), $mime )->escaped(); # 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) { // FIXME: Possible division by 0. bug 36911 $height = round($height * $maxWidth / $width); // FIXME: Possible division by 0. bug 36911 $width = $maxWidth; # Note that $height <= $maxHeight now. } else { $newwidth = floor($width * $maxHeight / $height); // FIXME: Possible division by 0. bug 36911 $height = round($height * $newwidth / $width); // FIXME: Possible division by 0. bug 36911 $width = $newwidth; # Note that $height <= $maxHeight now, but might not be identical # because of rounding. } $linktext = wfMessage('show-big-image')->escaped(); if ($this->displayImg->getRepo()->canTransformVia404()) { $thumbSizes = $wgImageLimits; // Also include the full sized resolution in the list, so // that users know they can get it. This will link to the // original file asset if mustRender() === false. In the case // that we mustRender, some users have indicated that they would // find it useful to have the full size image in the rendered // image format. $thumbSizes[] = array($width_orig, $height_orig); } else { # Creating thumb links triggers thumbnail generation. # Just generate the thumb for the current users prefs. $thumbSizes = array($this->getImageLimitsFromOption($user, 'thumbsize')); if (!$this->displayImg->mustRender()) { // We can safely include a link to the "full-size" preview, // without actually rendering. $thumbSizes[] = array($width_orig, $height_orig); } } # Generate thumbnails or thumbnail links as needed... $otherSizes = array(); foreach ($thumbSizes as $size) { // We include a thumbnail size in the list, if it is // less than or equal to the original size of the image // asset ($width_orig/$height_orig). We also exclude // the current thumbnail's size ($width/$height) // since that is added to the message separately, so // it can be denoted as the current size being shown. if ($size[0] <= $width_orig && $size[1] <= $height_orig && $size[0] != $width && $size[1] != $height) { $sizeLink = $this->makeSizeLink($params, $size[0], $size[1]); if ($sizeLink) { $otherSizes[] = $sizeLink; } } } $otherSizes = array_unique($otherSizes); $msgsmall = ''; $sizeLinkBigImagePreview = $this->makeSizeLink($params, $width, $height); if ($sizeLinkBigImagePreview) { $msgsmall .= wfMessage('show-big-image-preview')->rawParams($sizeLinkBigImagePreview)->parse(); } if (count($otherSizes)) { $msgsmall .= ' ' . Html::rawElement('span', array('class' => 'mw-filepage-other-resolutions'), wfMessage('show-big-image-other')->rawParams($lang->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 = ''; } elseif ($this->displayImg->isVectorized()) { # For vectorized images, full size is just the frame size $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); Linker::processResponsiveImages($this->displayImg, $thumbnail, $params); $anchorclose = Html::rawElement('div', array('class' => 'mw-filepage-resolutioninfo'), $msgsmall); $isMulti = $this->displayImg->isMultipage() && $this->displayImg->pageCount() > 1; if ($isMulti) { $out->addModules('mediawiki.page.image.pagination'); $out->addHTML('<table class="multipageimage"><tr><td>'); } if ($thumbnail) { $options = array('alt' => $this->displayImg->getTitle()->getPrefixedText(), 'file-link' => true); $out->addHTML('<div class="fullImageLink" id="file">' . $thumbnail->toHtml($options) . $anchorclose . "</div>\n"); } if ($isMulti) { $count = $this->displayImg->pageCount(); if ($page > 1) { $label = $out->parse(wfMessage('imgmultipageprev')->text(), false); // on the client side, this link is generated in ajaxifyPageNavigation() // in the mediawiki.page.image.pagination module $link = Linker::linkKnown($this->getTitle(), $label, array(), array('page' => $page - 1)); $thumb1 = Linker::makeThumbLinkObj($this->getTitle(), $this->displayImg, $link, $label, 'none', array('page' => $page - 1)); } else { $thumb1 = ''; } if ($page < $count) { $label = wfMessage('imgmultipagenext')->text(); $link = Linker::linkKnown($this->getTitle(), $label, array(), array('page' => $page + 1)); $thumb2 = Linker::makeThumbLinkObj($this->getTitle(), $this->displayImg, $link, $label, 'none', array('page' => $page + 1)); } else { $thumb2 = ''; } global $wgScript; $formParams = array('name' => 'pageselector', 'action' => $wgScript); $options = array(); for ($i = 1; $i <= $count; $i++) { $options[] = Xml::option($lang->formatNum($i), $i, $i == $page); } $select = Xml::tags('select', array('id' => 'pageselector', 'name' => 'page'), implode("\n", $options)); $out->addHTML('</td><td><div class="multipageimagenavbox">' . Xml::openElement('form', $formParams) . Html::hidden('title', $this->getTitle()->getPrefixedDBkey()) . wfMessage('imgmultigoto')->rawParams($select)->parse() . Xml::submitButton(wfMessage('imgmultigo')->text()) . Xml::closeElement('form') . "<hr />{$thumb1}\n{$thumb2}<br style=\"clear: both\" /></div></td></tr></table>"); } } elseif ($this->displayImg->isSafeFile()) { # if direct link is allowed but it's not a renderable image, show an icon. $icon = $this->displayImg->iconThumb(); $out->addHTML('<div class="fullImageLink" id="file">' . $icon->toHtml(array('file-link' => true)) . "</div>\n"); } $longDesc = wfMessage('parentheses', $this->displayImg->getLongDesc())->text(); $medialink = "[[Media:{$filename}|{$linktext}]]"; if (!$this->displayImg->isSafeFile()) { $warning = wfMessage('mediawarning')->plain(); // dirmark is needed here to separate the file name, which // most likely ends in Latin characters, from the description, // which may begin with the file type. In RTL environment // this will get messy. // The dirmark, however, must not be immediately adjacent // to the filename, because it can get copied with it. // See bug 25277. $out->addWikiText(<<<EOT <div class="fullMedia"><span class="dangerousLink">{$medialink}</span> {$dirmark}<span class="fileInfo">{$longDesc}</span></div> <div class="mediaWarning">{$warning}</div> EOT ); } else { $out->addWikiText(<<<EOT <div class="fullMedia">{$medialink} {$dirmark}<span class="fileInfo">{$longDesc}</span> </div> EOT ); } $renderLangOptions = $this->displayImg->getAvailableLanguages(); if (count($renderLangOptions) >= 1) { $currentLanguage = $renderLang; $defaultLang = $this->displayImg->getDefaultRenderLanguage(); if (is_null($currentLanguage)) { $currentLanguage = $defaultLang; } $out->addHtml($this->doRenderLangOpt($renderLangOptions, $currentLanguage, $defaultLang)); } // Add cannot animate thumbnail warning if (!$this->displayImg->canAnimateThumbIfAppropriate()) { // Include the extension so wiki admins can // customize it on a per file-type basis // (aka say things like use format X instead). // additionally have a specific message for // file-no-thumb-animation-gif $ext = $this->displayImg->getExtension(); $noAnimMesg = wfMessageFallback('file-no-thumb-animation-' . $ext, 'file-no-thumb-animation')->plain(); $out->addWikiText(<<<EOT <div class="mw-noanimatethumb">{$noAnimMesg}</div> EOT ); } if (!$this->displayImg->isLocal()) { $this->printSharedImageText(); } } else { # Image does not exist if (!$this->getID()) { # No article exists either # Show deletion log to be consistent with normal articles LogEventsList::showLogExtract($out, array('delete', 'move'), $this->getTitle()->getPrefixedText(), '', array('lim' => 10, 'conds' => array("log_action != 'revision'"), 'showIfEmpty' => false, 'msgKey' => array('moveddeleted-notice'))); } if ($wgEnableUploads && $user->isAllowed('upload')) { // Only show an upload link if the user can upload $uploadTitle = SpecialPage::getTitleFor('Upload'); $nofile = array('filepage-nofile-link', $uploadTitle->getFullURL(array('wpDestFile' => $this->mPage->getFile()->getName()))); } else { $nofile = 'filepage-nofile'; } // Note, if there is an image description page, but // no image, then this setRobotPolicy is overridden // by Article::View(). $out->setRobotPolicy('noindex,nofollow'); $out->wrapWikiMsg("<div id='mw-imagepage-nofile' class='plainlinks'>\n\$1\n</div>", $nofile); if (!$this->getID() && $wgSend404Code) { // If there is no image, no shared image, and no description page, // output a 404, to be consistent with articles. $request->response()->header('HTTP/1.1 404 Not Found'); } } $out->setFileVersion($this->displayImg); }
/** * * @param Skin $skin * @param File $result * @return string */ function formatResult($skin, $result) { global $wgContLang; $nt = $result->getTitle(); $text = $wgContLang->convert($nt->getText()); $plink = Linker::link(Title::newFromText($nt->getPrefixedText()), $text); $userText = $result->getUser('text'); $user = Linker::link(Title::makeTitle(NS_USER, $userText), $userText); $time = $this->getLanguage()->userTimeAndDate($result->getTimestamp(), $this->getUser()); return "{$plink} . . {$user} . . {$time}"; }
/** * HTML Content for external link * * @return string */ public function getExternalLink() { $title = $this->file ? $this->file->getTitle() : $this->getName(); return sprintf('<a href="%1$s" title="%2$s" target="_blank" rel="external" class="file-url">%1$s</a>', Convert::raw2att($this->url), Convert::raw2att($title)); }
/** * Get file-based metadata in standardized format. * * Note that for a remote file, this might return metadata supplied by extensions. * * @param File $file File to use * @return array [<property name> => ['value' => <value>]], or [] on error * @since 1.23 */ protected function getExtendedMetadataFromFile(File $file) { // If this is a remote file accessed via an API request, we already // have remote metadata so we just ignore any local one if ($file instanceof ForeignAPIFile) { // In case of error we pretend no metadata - this will get cached. // Might or might not be a good idea. return $file->getExtendedMetadata() ?: array(); } wfProfileIn(__METHOD__); $uploadDate = wfTimestamp(TS_ISO_8601, $file->getTimestamp()); $fileMetadata = array('DateTime' => array('value' => $uploadDate, 'source' => 'mediawiki-metadata')); $title = $file->getTitle(); if ($title) { $text = $title->getText(); $pos = strrpos($text, '.'); if ($pos) { $name = substr($text, 0, $pos); } else { $name = $text; } $fileMetadata['ObjectName'] = array('value' => $name, 'source' => 'mediawiki-metadata'); } $common = $file->getCommonMetaArray(); if ($common !== false) { foreach ($common as $key => $value) { $fileMetadata[$key] = array('value' => $value, 'source' => 'file-metadata'); } } wfProfileOut(__METHOD__); return $fileMetadata; }