Example #1
0
 /**
  * @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)));
 }
 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);
 }