function insertVideo() { global $wgRequest, $wgUser; wfProfileIn(__METHOD__); if ($wgUser->isBlocked()) { header('X-screen-type: error'); wfProfileOut(__METHOD__); return wfMessage('videos-error-blocked-user')->plain(); } if (!$wgUser->isAllowed('videoupload')) { header('X-screen-type: error'); wfProfileOut(__METHOD__); return wfMessage('videos-error-admin-only')->plain(); } $url = $wgRequest->getVal('url'); $tempname = 'Temp_video_' . $wgUser->getID() . '_' . rand(0, 1000); $title = Title::makeTitle(NS_FILE, $tempname); $nonPremiumException = null; try { $awf = ApiWrapperFactory::getInstance(); /* @var $awf ApiWrapperFactory */ $apiwrapper = $awf->getApiWrapper($url); } catch (Exception $e) { $nonPremiumException = $e; } $embedOptions = ['autoplay' => false, 'isAjax' => false]; if (!empty($apiwrapper)) { // try ApiWrapper first - is it from a supported 3rd party ( non-premium ) provider? $provider = $apiwrapper->getMimeType(); $file = new WikiaLocalFile($title, RepoGroup::singleton()->getLocalRepo()); $file->forceMime($provider); $file->setVideoId($apiwrapper->getVideoId()); $file->setProps(array('mime' => $provider)); // Loading this to deal with video descriptions $vHelper = new VideoHandlerHelper(); $props['id'] = $apiwrapper->getVideoId(); $props['vname'] = $apiwrapper->getTitle(); $props['metadata'] = ''; $props['description'] = $vHelper->getVideoDescription($file); $props['provider'] = $provider; $embed_code = $file->getEmbedCode(VIDEO_PREVIEW, $embedOptions); $props['code'] = json_encode($embed_code); } else { // if not a supported 3rd party ( non-premium ) video, try to parse link for File: // get the video file $videoService = new VideoService(); $file = $videoService->getVideoFileByUrl($url); if (!$file) { header('X-screen-type: error'); if ($nonPremiumException) { if (empty(F::app()->wg->allowNonPremiumVideos)) { wfProfileOut(__METHOD__); return wfMessage('videohandler-non-premium')->parse(); } if ($nonPremiumException->getMessage() != '') { wfProfileOut(__METHOD__); return $nonPremiumException->getMessage(); } } wfProfileOut(__METHOD__); return wfMessage('vet-bad-url')->plain(); } // Loading this to deal with video descriptions $vHelper = new VideoHandlerHelper(); $embedCode = $file->getEmbedCode(VIDEO_PREVIEW, $embedOptions); $props['provider'] = 'FILE'; $props['id'] = $file->getHandler()->getVideoId(); $props['vname'] = $file->getTitle()->getText(); $props['code'] = json_encode($embedCode); $props['metadata'] = ''; $props['description'] = $vHelper->getVideoDescription($file); $props['premiumVideo'] = !$file->isLocal(); } wfProfileOut(__METHOD__); return $this->detailsPage($props); }
/** * Get video data * @param string $title * @param string $altThumbTitle * @param string $displayTitle * @param string $description * @param array $thumbOptions * @return array */ public function getVideoData($title, $altThumbTitle = '', $displayTitle = '', $description = '', $thumbOptions = array()) { wfProfileIn(__METHOD__); $video = array(); /** @var Title $title A string $title will get converted to an object here */ $file = WikiaFileHelper::getVideoFileFromTitle($title); if (!empty($file)) { $videoTitle = $title->getText(); if (empty($displayTitle)) { $displayTitle = $videoTitle; } // get thumbnail $thumb = $file->transform(array('width' => self::THUMBNAIL_WIDTH, 'height' => self::THUMBNAIL_HEIGHT)); $videoThumb = $thumb->toHtml($thumbOptions); $thumbUrl = $thumb->getUrl(); $largeThumb = $file->transform(array('width' => self::MAX_THUMBNAIL_WIDTH, 'height' => self::MAX_THUMBNAIL_HEIGHT)); $largeThumbUrl = $largeThumb->getUrl(); // replace original thumbnail with the new one $altThumbName = ''; $altThumbKey = ''; if (!empty($altThumbTitle)) { $imageData = $this->getImageData($altThumbTitle); if (!empty($imageData)) { $videoThumb = str_replace($thumbUrl, $imageData['thumbUrl'], $videoThumb); $largeThumbUrl = $imageData['largeThumbUrl']; $altThumbName = $imageData['imageTitle']; $altThumbKey = $imageData['imageKey']; // TODO: Saipetch will fix this :) $thumbUrl = $imageData['thumbUrl']; } } // get description if (empty($description)) { $videoHandlerHelper = new VideoHandlerHelper(); $description = $videoHandlerHelper->getVideoDescription($file); } $video = array('videoTitle' => $videoTitle, 'videoKey' => $title->getDBkey(), 'videoThumb' => $videoThumb, 'largeThumbUrl' => $largeThumbUrl, 'altThumbName' => $altThumbName, 'altThumbKey' => $altThumbKey, 'displayTitle' => $displayTitle, 'description' => $description, 'thumbUrl' => $thumbUrl); } wfProfileOut(__METHOD__); return $video; }