/** * @param string $provider Ex: youtube * @param string $videoId Video id from provider * @return array */ private function execute3rdPartyVideo($provider, $videoId) { $tempVideo = new WikiaLocalFile(Title::newFromText(uniqid('Temp_', true), NS_FILE), RepoGroup::singleton()->getLocalRepo()); // forceMime makes sure the correct file properties are set and sent to the handler when afterSetProps is called $tempVideo->forceMime('video/' . $provider); $tempVideo->setVideoId($videoId); $tempVideo->afterSetProps(); $options = ['autoplay' => true, 'isAjax' => true]; return array('embedCode' => json_encode($tempVideo->getEmbedCode(self::EMBED_WIDTH, $options))); }
/** * Impliments revert functionality for videos * @param Array $data - Not used but maintaining method signature * @return bool - Whether the action was successful */ public function onSubmit($data) { // Get the archive name of the video $oldImageName = $this->getRequest()->getText('oldimage'); // Get the video file page $page = $this->page; // Get the DB version of the title text $title = $page->getTitle(); $dbKey = $title->getDBkey(); // Get the repo for this file $file = $page->getDisplayedFile(); $repo = $file->repo; // This returns a file object for an archived version of a video $archiveImg = WikiaLocalFile::newFromArchiveTitle($dbKey, $oldImageName, $repo); if (empty($archiveImg)) { return false; } // Get the original URL used to upload this video $handler = $archiveImg->getHandler(); $providerURL = $handler->getProviderDetailUrl(); // Upload this video again to this DB key. This will create a new version $title = VideoFileUploader::URLtoTitle($providerURL, $dbKey); return $title ? true : false; }
function insertVideo() { global $wgRequest, $wgUser, $wgContLang; $url = $wgRequest->getVal('url'); $tempname = 'Temp_video_' . $wgUser->getID() . '_' . rand(0, 1000); $title = Title::makeTitle(NS_FILE, $tempname); $isNonPremium = false; try { $awf = ApiWrapperFactory::getInstance(); /* @var $awf ApiWrapperFactory */ $apiwrapper = $awf->getApiWrapper($url); } catch (WikiaException $e) { $isNonPremium = true; } if (!empty($apiwrapper)) { // try ApiWrapper first - is it from partners? $provider = $apiwrapper->getMimeType(); $file = new WikiaLocalFile($title, RepoGroup::singleton()->getLocalRepo()); $file->forceMime($provider); $file->setVideoId($apiwrapper->getVideoId()); $file->setProps(array('mime' => $provider)); $props['id'] = $apiwrapper->getVideoId(); $props['vname'] = $apiwrapper->getTitle(); $props['metadata'] = ''; $props['provider'] = $provider; $props['code'] = $file->getEmbedCode(VIDEO_PREVIEW, false, false, true); $props['oname'] = ''; } else { // if not a partner video try to parse link for File: $file = null; // get the video name $nsFileTranslated = $wgContLang->getNsText(NS_FILE); // added $nsFileTransladed to fix bugId:#48874 $pattern = '/(File:|Video:|' . $nsFileTranslated . ':)(.+)$/'; if (preg_match($pattern, $url, $matches)) { $file = wfFindFile($matches[2]); if (!$file) { // bugID: 26721 $file = wfFindFile(urldecode($matches[2])); } } elseif (preg_match($pattern, urldecode($url), $matches)) { $file = wfFindFile($matches[2]); if (!$file) { // bugID: 26721 $file = wfFindFile($matches[2]); } } else { if ($isNonPremium) { header('X-screen-type: error'); if (!empty(F::app()->wg->allowNonPremiumVideos)) { return $e->getMessage(); } // return wfMessage("videohandler-non-premium")->parse(); //TODO: re-instate html links once VETUpgrade branch is merged into trunk (Liz) return wfMsg('videohandler-non-premium'); } header('X-screen-type: error'); return wfMsg('vet-bad-url'); } if (!$file) { header('X-screen-type: error'); return wfMsg('vet-non-existing'); } $embedCode = $file->getEmbedCode(VIDEO_PREVIEW, false, false, true); $props['provider'] = 'FILE'; $props['id'] = $file->getHandler()->getVideoId(); $props['vname'] = $file->getTitle()->getText(); $props['code'] = is_string($embedCode) ? $embedCode : json_encode($embedCode); $props['metadata'] = ''; $props['oname'] = ''; } return $this->detailsPage($props); }
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); }