public function index() { if ($this->wg->user->isBlocked()) { $this->wg->out->blockedPage(); return false; // skip rendering } if (!$this->wg->user->isAllowed('specialvideohandler')) { $this->displayRestrictionError(); return false; } if (wfReadOnly() && !wfAutomaticReadOnly()) { $this->wg->out->readOnlyPage(); return false; } $videoId = $this->getVal('videoid', null); $provider = strtolower($this->getVal('provider', null)); $undercover = $this->getVal('undercover', false); $videoTitle = $this->getVal('videotitle', null); if ($videoId && $provider) { $overrideMetadata = array(); if (!empty($videoTitle)) { $overrideMetadata['title'] = $videoTitle; } try { $result = VideoFileUploader::uploadVideo($provider, $videoId, $title, null, $undercover, $overrideMetadata); } catch (Exception $e) { $result = (object) array('ok' => null, 'value' => null); } $this->setVal('uploadStatus', $result->ok); $this->setVal('isNewFile', empty($result->value)); $this->setVal('title', !empty($title) ? $title->getText() : ''); $this->setVal('url', !empty($title) ? $title->getFullURL() : ''); } }
/** * @param $url * @return array * @throws Exception */ protected function addVideoVideoHandlers($url) { $title = VideoFileUploader::URLtoTitle($url); if (!$title) { throw new Exception(wfMessage('videos-error-invalid-video-url')->text()); } return array($title, $title->getArticleID(), null); }
public function getSanitizedOldVideoTitleString() { $sTitle = $this->getVal('videoText', ''); $prefix = ''; if (strpos($sTitle, ':') === 0) { $sTitle = substr($sTitle, 1); $prefix = ':'; } if (empty($sTitle)) { $this->setVal('error', 1); } $sTitle = VideoFileUploader::sanitizeTitle($sTitle, '_'); $this->setVal('result', $prefix . $sTitle); }
private function execute3rdPartyVideo() { if (empty($this->mParams['videoId'])) { $this->dieUsageMsg('The videoId parameter must be set'); } $duplicate = $this->getVideoDuplicate($this->mParams['provider'], $this->mParams['videoId']); if ($duplicate) { return array('title' => $duplicate->getTitle()->getText()); } else { $uploader = new VideoFileUploader(); $title = $uploader->getUniqueTitle(wfStripIllegalFilenameChars($this->mParams['title'])); $uploader->setProvider($this->mParams['provider']); $uploader->setVideoId($this->mParams['videoId']); $uploader->setTargetTitle($title->getBaseText()); $uploader->upload($title); return array('title' => $title->getText()); } }
/** * 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; }
private function execute3rdPartyVideo() { if (empty($this->mParams['videoId'])) { $this->dieUsageMsg('The videoId parameter must be set'); } $duplicate = $this->getVideoDuplicate($this->mParams['provider'], $this->mParams['videoId']); if ($duplicate) { return array('title' => $duplicate->getTitle()->getText()); } else { $uploader = new VideoFileUploader(); $title = $uploader->getUniqueTitle(wfStripIllegalFilenameChars($this->mParams['title'])); // https://wikia-inc.atlassian.net/browse/VE-1819 if (!$title) { WikiaLogger::instance()->debug('ApiAddMediaPermanent', array('title' => $this->mParams['title'])); } $uploader->setProvider($this->mParams['provider']); $uploader->setVideoId($this->mParams['videoId']); $uploader->setTargetTitle($title->getBaseText()); $uploader->upload($title); return array('title' => $title->getText()); } }
public function doSubmit() { global $wgOut, $wgRequest, $wgUser; $replaced = false; if ('' == $wgRequest->getVal('wpWikiaVideoAddName')) { if ('' != $wgRequest->getVal('wpWikiaVideoAddPrefilled')) { $this->mName = $wgRequest->getVal('wpWikiaVideoAddPrefilled'); $replaced = true; } else { $this->mName = ''; } } else { $this->mName = $wgRequest->getVal('wpWikiaVideoAddName'); } '' != $wgRequest->getVal('wpWikiaVideoAddUrl') ? $this->mUrl = $wgRequest->getVal('wpWikiaVideoAddUrl') : ($this->mUrl = ''); if ('' != $this->mName && '' != $this->mUrl) { $this->mName = ucfirst($this->mName); // sanitize all video titles $this->mName = VideoFileUploader::sanitizeTitle($this->mName); $title = Title::makeTitleSafe(NS_VIDEO, $this->mName); if ($title instanceof Title) { $permErrors = $title->getUserPermissionsErrors('edit', $wgUser); $permErrorsUpload = $title->getUserPermissionsErrors('upload', $wgUser); $permErrorsCreate = $title->exists() ? array() : $title->getUserPermissionsErrors('create', $wgUser); if ($permErrors || $permErrorsUpload || $permErrorsCreate) { header('X-screen-type: error'); $wgOut->addWikiMsg('wva-protected'); return; } if (WikiaFileHelper::useVideoHandlersExtForEmbed()) { $res = null; try { $res = VideoFileUploader::URLtoTitle($this->mUrl, $this->mName); } catch (Exception $e) { } if (!$res) { $wgOut->addHTML(wfMsg('wva-failure')); return; } } if (WikiaFileHelper::useWikiaVideoExtForEmbed()) { $video = new VideoPage($title); $video->parseUrl($this->mUrl); $video->setName($this->mName); $video->save(); } $sk = RequestContext::getMain()->getSkin(); $link_back = $sk->makeKnownLinkObj($title); if ($replaced) { $wgOut->addHTML(wfMsg('wva-success-replaced', $link_back)); } else { $wgOut->addHTML(wfMsg('wva-success', $link_back)); } } else { //bad title returned $wgOut->addHTML(wfMsg('wva-failure')); } } else { //one of two params blank $wgOut->addHTML(wfMsg('wva-failure')); } }
public function doSubmit() { global $wgOut; $errors = array(); $replaced = false; $this->mUrl = $this->getRequest()->getVal('wpWikiaVideoAddUrl', ''); $this->mName = $this->getRequest()->getVal('wpWikiaVideoAddName', ''); if ($this->mName == '') { $this->mName = $this->getRequest()->getVal('name', ''); if ($this->mName != '') { $replaced = true; } } if ($this->mUrl == '') { $errors['videoUrl'] = wfMessage('wva-failure')->text(); $this->showForm($errors); return; } else { if ($this->mName == '') { $videoService = new VideoService(); $retval = $videoService->addVideo($this->mUrl); if (is_array($retval)) { list($title, $videoPageId, $videoProvider) = $retval; } else { $errors['videoUrl'] = $retval; $this->showForm($errors); return; } } else { $this->mName = ucfirst($this->mName); // sanitize all video titles $this->mName = VideoFileUploader::sanitizeTitle($this->mName); $title = Title::makeTitleSafe(NS_FILE, $this->mName); if ($title instanceof Title) { $permErrors = $title->getUserPermissionsErrors('edit', $this->getUser()); $permErrorsUpload = $title->getUserPermissionsErrors('upload', $this->getUser()); $permErrorsCreate = $title->exists() ? array() : $title->getUserPermissionsErrors('create', $this->getUser()); if ($permErrors || $permErrorsUpload || $permErrorsCreate) { header('X-screen-type: error'); $wgOut->addWikiMsg('wva-protected'); return; } if (empty(F::app()->wg->allowNonPremiumVideos)) { $errors['videoUrl'] = wfMessage('videohandler-non-premium')->parse(); $this->showForm($errors); return; } if (WikiaFileHelper::useVideoHandlersExtForEmbed()) { $res = null; try { $res = VideoFileUploader::URLtoTitle($this->mUrl, $this->mName); } catch (Exception $e) { } if (!$res) { $errors['videoUrl'] = wfMessage('wva-failure')->text(); $this->showForm($errors); return; } } } else { //bad title returned $errors['name'] = wfMessage('wva-failure')->text(); $this->showForm($errors); return; } } } if ($replaced) { $successMsgKey = 'wva-success-replaced'; } else { $successMsgKey = 'wva-success'; } $query = array("sort" => "recent", "msg" => $successMsgKey, "msgTitle" => urlencode($title)); $wgOut->redirect(SpecialPage::getTitleFor("Videos")->getLocalUrl($query)); }
/** * After all the video meta data and categories have been prepared, upload the video * onto Wikia. * @return int */ public function saveVideo() { $body = $this->prepareBodyString(); if ($this->debugMode()) { $this->printReadyToSaveData($body); $msg = "Ingested {$this->metaData['destinationTitle']} (id: {$this->metaData['videoId']}).\n"; $this->logger->videoIngested($msg, $this->pageCategories); return 1; } else { /** @var Title $uploadedTitle */ $uploadedTitle = null; $result = VideoFileUploader::uploadVideo($this->metaData['provider'], $this->metaData['videoId'], $uploadedTitle, $body, false, $this->metaData); if ($result->ok) { $fullUrl = WikiFactory::getLocalEnvURL($uploadedTitle->getFullURL()); $msg = "Ingested {$uploadedTitle->getText()} from partner clip id {$this->metaData['videoId']}. {$fullUrl}\n"; $this->logger->videoIngested($msg, $this->pageCategories); wfWaitForSlaves(); wfRunHooks('VideoIngestionComplete', [$uploadedTitle, $this->pageCategories]); return 1; } } $this->logger->videoWarnings(); return 0; }
} echo "Img name: ".$videoRow->img_name." \n "; $title = Title::newFromDBkey($videoRow->img_name); $provider = $videoRow->img_minor_mime; $apiWrapperName = ucfirst( $videoRow->img_minor_mime ) . 'ApiWrapper'; $videoId = $metadata['videoId']; $result = null; $status = "fail"; echo "reuploading: [from:".$provider." videoId:$videoId] - ".$videoRow->img_name."\n"; echo "title: " . $title . "\n"; try { $oUploader = new VideoFileUploader(); $oUploader->setProvider( $provider ); $oUploader->setVideoId( $videoId ); $oUploader->setDescription( null ); $oUploader->setTargetTitle( $title ); $oUploader->hideAction(); $oUploader->upload( $title ); } catch( Exception $e ) { echo ("ERROR FETCHING DATA: [{$videoRow->img_minor_mime}]". $videoRow->img_name . "\n"); echo $e->getMessage() ."\n"; } echo("========================================== \n"); }
protected function validateTitle($videoId, $name, &$msg, $isDebug) { wfProfileIn(__METHOD__); $sanitizedName = VideoFileUploader::sanitizeTitle($name); $title = $this->titleFromText($sanitizedName); if (is_null($title)) { $msg = "article title was null: clip id {$videoId}. name: {$name}"; wfProfileOut(__METHOD__); return 0; } wfProfileOut(__METHOD__); return 1; }
/** * Upload video using LocalFile framework * @param mixed $provider string or int from $wgVideoMigrationProviderMap * @param string $videoId * @param string $videoName * @return mixed FileRepoStatus or FALSE on error */ private function uploadVideoAsFile($provider, $videoId, $videoName, &$oTitle) { $oUploader = new VideoFileUploader(); $oUploader->setProvider($provider); $oUploader->setVideoId($videoId); $oUploader->setTargetTitle($videoName); return $oUploader->upload($oTitle); }
public function getUniqueTitle($title, $level = 0) { $oTitle = Title::newFromText($title, NS_FILE); if (!empty($oTitle) && $oTitle->exists()) { $newTitleObject = $oTitle->getBaseText() . '-' . $level; return VideoFileUploader::getUniqueTitle($newTitleObject, $level + 1); } return $oTitle; }
/** * 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; }
function upgradeYouTubeTag($editpage, $request) { $app = F::app(); // Don't convert <youtube> tags if the user is not logged in or is blocked. // It provides a loophole for those users to upload video. if (!$app->wg->User->isLoggedIn()) { return true; } if ($app->wg->User->isBlocked()) { return true; } if (!$app->wg->User->isAllowed('videoupload')) { return true; } $text = $editpage->textbox1; // Note that we match <nowiki> here to consume that text and any possible // <youtube> tags within it. We don't want to convert anything within <nowiki> $text = preg_replace_callback('/(<nowiki>.*?<\\/nowiki>)|(<youtube([^>]*)>([^<]+)<\\/youtube>)/i', function ($matches) { // If we don't have a youtube match (its a nowiki tag) return as is if (empty($matches[2])) { return $matches[0]; } // Separate the Youtube ID and parameters $paramText = trim($matches[3]); // Node value can look like: <youtube_id>|400px|thumb|center // @TODO evaluate calling parser to parse params and upload correctly styled video $nodeValues = explode('|', $matches[4]); $ytid = trim($nodeValues[0]); // Check to see if the whole URL is used if (preg_match('/(?:youtube\\.com\\/watch\\?(?:[^&]*&)*v=|youtu\\.be\\/)([^?&\\n]+)/', $ytid, $ytidMatches) === 1) { $ytid = $ytidMatches[1]; } // Parse out the width and height parameters $params = parseSizeParams($paramText); // If height is less than 30, they probably are using this as an audio file // so don't bother converting it. if ($params['height'] <= AUDIO_ONLY_HEIGHT) { return $matches[0]; } $url = 'http://www.youtube.com/watch?v=' . $ytid; $videoService = new VideoService(); $videoFileUploader = new VideoFileUploader(); $videoFileUploader->setExternalUrl($url); $apiWrapper = $videoFileUploader->getApiWrapper(); if (!$apiWrapper->videoExists()) { return createRawOutput($matches[0]); } $retval = $videoService->addVideo($url); if (is_array($retval)) { list($title, $videoPageId, $videoProvider) = $retval; return "[[{$title}|" . $params['width'] . "px]]"; } else { return $matches[0]; } }, $text); $editpage->textbox1 = $text; return true; }
$file = wfFindFile( $title ); $img = $file->getFullUrl(); $article = Article::newFromID($title->getArticleID()); $body = $article->getContent(); echo "$w\t$h\t$aspect\t$url\t$img\n"; // fake the upload $metadata = unserialize($file->getMetadata()); if( $metadata['aspectRatio'] > 1.7 ) { echo $metadata['aspectRatio'] . "<- skipping\n"; continue; } else { echo $metadata['aspectRatio'] . "<- previous ratio\n"; } $metadata['aspectRatio'] = 1.7777778; $apiWrapper = new ScreenplayApiWrapper($name, $metadata); $uploadedTitle = null; //$descriptionHeader = '==' . F::app()->wf->Msg('videohandler-description') . '=='; //$body = $categoryStr."\n".$descriptionHeader."\n".$apiWrapper->getDescription(); $result = VideoFileUploader::uploadVideo('screenplay', $name, $uploadedTitle, $body, false); if ($result->ok) { echo "reupload OK\n"; } else { echo "reupload failed\n"; } sleep(5); } } }