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);
 }
Ejemplo n.º 2
0
 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'));
     }
 }
Ejemplo n.º 3
0
 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));
 }
Ejemplo n.º 4
0
 /**
  * Return if the title we plan on using to create the video is valid.
  * @param $destinationTitle
  * @return bool
  */
 public function isValidDestinationTitle($destinationTitle)
 {
     $sanitizedName = VideoFileUploader::sanitizeTitle($destinationTitle);
     $title = Title::newFromText($sanitizedName, NS_FILE);
     return !is_null($title);
 }
Ejemplo n.º 5
0
 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;
 }
Ejemplo n.º 6
0
 function insertFinalVideo()
 {
     global $wgRequest, $wgContLang;
     $id = $wgRequest->getVal('id');
     $provider = $wgRequest->getVal('provider');
     $name = urldecode($wgRequest->getVal('name'));
     $oname = urldecode($wgRequest->getVal('oname'));
     if ('' == $name) {
         $name = $oname;
     }
     $embed_code = '';
     $tag = '';
     $message = '';
     if ($provider == 'FILE') {
         // no need to upload, local reference
         $title = $oTitle = Title::newFromText($name, NS_FILE);
         if (empty($oTitle)) {
             header('X-screen-type: error');
             return wfMsg('vet-name-incorrect');
         }
         wfRunHooks('AddPremiumVideo', array($title));
     } else {
         // needs to upload
         // sanitize name and init title objects
         $name = VideoFileUploader::sanitizeTitle($name);
         if ($name == '') {
             header('X-screen-type: error');
             return wfMsg('vet-warn3');
         }
         $nameFile = VideoFileUploader::sanitizeTitle($name);
         $titleFile = VideoFileUploader::getUniqueTitle($nameFile);
         if (empty($titleFile)) {
             header('X-screen-type: error');
             return wfMsg('vet-name-incorrect');
         }
         // by definition, WikiaFileHelper::useVideoHandlersExtForEmbed() == true
         $nameSanitized = $titleFile->getBaseText();
         $title = $titleFile;
         $extra = 0;
         $metadata = array();
         while ('' != $wgRequest->getVal('metadata' . $extra)) {
             $metadata[] = $wgRequest->getVal('metadata' . $extra);
             $extra++;
         }
         if (!empty($titleFile)) {
             $parts = explode('/', $provider);
             $provider = $parts[1];
             $oTitle = null;
             $status = $this->uploadVideoAsFile($provider, $id, $nameSanitized, $oTitle);
             if (!$status->ok) {
                 header('X-screen-type: error');
                 return wfMsg('wva-thumbnail-upload-failed');
             }
             $message = wfMsg('vet-single-success');
         }
     }
     $ns_vid = $wgContLang->getFormattedNsText($title->getNamespace());
     $caption = $wgRequest->getVal('caption');
     $size = $wgRequest->getVal('size');
     $width = $wgRequest->getVal('width');
     $layout = $wgRequest->getVal('layout');
     header('X-screen-type: summary');
     $tag = $ns_vid . ":" . $oTitle->getText();
     if (!empty($size)) {
         $tag .= "|{$size}";
     }
     if (!empty($layout)) {
         $tag .= "|{$layout}";
     }
     if ($width != 'px') {
         $tag .= "|{$width}";
     }
     if ($caption != '') {
         $tag .= "|" . $caption;
     }
     $tag = "[[{$tag}]]";
     $tmpl = new EasyTemplate(dirname(__FILE__) . '/templates/');
     $tmpl->set_vars(array('tag' => $tag, 'message' => $message, 'code' => $embed_code));
     return $tmpl->render('summary');
 }
Ejemplo n.º 7
0
 function insertFinalVideo()
 {
     global $wgRequest, $wgContLang;
     $id = $wgRequest->getVal('id');
     $provider = $wgRequest->getVal('provider');
     $name = urldecode($wgRequest->getVal('name'));
     $embed_code = '';
     if ($provider == 'FILE') {
         // no need to upload, local reference
         $title = $oTitle = Title::newFromText($name, NS_FILE);
         if (empty($oTitle)) {
             header('X-screen-type: error');
             return wfMessage('vet-name-incorrect')->plain();
         }
         wfRunHooks('AddPremiumVideo', array($title));
     } else {
         // needs to upload
         // sanitize name and init title objects
         $name = VideoFileUploader::sanitizeTitle($name);
         if ($name == '') {
             header('X-screen-type: error');
             return wfMessage('vet-warn3')->plain();
         }
         $nameFile = VideoFileUploader::sanitizeTitle($name);
         $titleFile = VideoFileUploader::getUniqueTitle($nameFile);
         if (empty($titleFile)) {
             header('X-screen-type: error');
             return wfMessage('vet-name-incorrect')->plain();
         }
         // by definition, WikiaFileHelper::useVideoHandlersExtForEmbed() == true
         $nameSanitized = $titleFile->getBaseText();
         $title = $titleFile;
         $extra = 0;
         $metadata = array();
         while ('' != $wgRequest->getVal('metadata' . $extra)) {
             $metadata[] = $wgRequest->getVal('metadata' . $extra);
             $extra++;
         }
         $parts = explode('/', $provider);
         $provider = $parts[1];
         $oTitle = null;
         $status = $this->uploadVideoAsFile($provider, $id, $nameSanitized, $oTitle);
         if (!$status->ok) {
             header('X-screen-type: error');
             return wfMessage('wva-thumbnail-upload-failed')->plain();
         }
     }
     $description = trim(urldecode($wgRequest->getVal('description')));
     // Set the video descriptions
     $vHelper = new VideoHandlerHelper();
     $vHelper->setVideoDescription($oTitle, $description);
     $message = wfMessage('vet-single-success')->plain();
     $ns_file = $wgContLang->getFormattedNsText($title->getNamespace());
     $caption = $wgRequest->getVal('caption');
     $width = $wgRequest->getVal('width');
     $width = empty($width) ? 335 : $width;
     $layout = $wgRequest->getVal('layout');
     header('X-screen-type: summary');
     $tag = $ns_file . ":" . $oTitle->getText();
     // all videos added via VET will be shown as thumbnails / "framed"
     $tag .= "|thumb";
     if (!empty($layout)) {
         $tag .= "|{$layout}";
     }
     if ($width != '') {
         $tag .= "|{$width} px";
     }
     if ($caption != '') {
         $tag .= "|" . $caption;
     }
     $tag = "[[{$tag}]]";
     $button_message = wfMessage('vet-return')->plain();
     // Adding a video from article view page
     $editFromViewMode = $wgRequest->getVal('placeholder');
     if ($editFromViewMode) {
         Wikia::setVar('EditFromViewMode', true);
         $article_title = $wgRequest->getVal('article');
         $ns = $wgRequest->getVal('ns');
         $box = $wgRequest->getVal('box');
         $article_title_obj = Title::newFromText($article_title, $ns);
         $article_obj = new Article($article_title_obj);
         $text = $article_obj->getContent();
         // match [[File:Placeholder|video]]
         $placeholder = MediaPlaceholderMatch($text, $box, true);
         $success = false;
         if ($placeholder) {
             $placeholder_tag = $placeholder[0];
             $file = wfFindFile($title);
             $embed_code = $file->transform(array('width' => $width))->toHtml();
             $params = array('alt' => $title->getText(), 'title' => $title->getText(), 'img-class' => 'thumbimage', 'align' => $layout, 'outerWidth' => $width, 'file' => $file, 'url' => $file->getUrl(), 'html' => $embed_code);
             $embed_code = F::app()->renderView('ThumbnailController', 'articleBlock', $params);
             // Make output match what's in a saved article
             if ($layout == 'center') {
                 $embed_code = '<div class="center">' . $embed_code . '</div>';
             }
             $summary = wfMessage('vet-added-from-placeholder')->plain();
             $text = substr_replace($text, $tag, $placeholder[1], strlen($placeholder_tag));
             $button_message = wfMessage('vet-placeholder-return')->plain();
             $success = $article_obj->doEdit($text, $summary);
         }
         if (!$success) {
             header('X-screen-type: error');
             return wfMessage('vet-insert-error')->plain();
         }
     }
     $tmpl = new EasyTemplate(dirname(__FILE__) . '/templates/');
     $tmpl->set_vars(array('tag' => $tag, 'message' => $message, 'code' => $embed_code, 'button_message' => $button_message));
     return $tmpl->render('summary');
 }