コード例 #1
0
ファイル: WikiaFilePage.php プロジェクト: Tjorriemorrie/app
 /**
  * Display info about the video below the video player: provider, views, expiration date (if any)
  */
 public function getVideoInfoLine($file)
 {
     wfProfileIn(__METHOD__);
     $app = F::app();
     $captionDetails = array('expireDate' => $file->getExpirationDate(), 'provider' => $file->getProviderName(), 'providerUrl' => $file->getProviderHomeUrl(), 'detailUrl' => $file->getProviderDetailUrl(), 'views' => MediaQueryService::getTotalVideoViewsByTitle($file->getTitle()->getDBKey()), 'regionalRestrictions' => $file->getRegionalRestrictions());
     $caption = $app->renderView('FilePageController', 'videoCaption', $captionDetails);
     wfProfileOut(__METHOD__);
     return $caption;
 }
コード例 #2
0
 public static function onThumbnailVideoHTML($options, $linkAttribs, $imageAttribs, File $file, &$html)
 {
     global $wgRTEParserEnabled;
     if (!empty($wgRTEParserEnabled)) {
         return true;
     }
     if (is_null(self::$isWikiaMobile)) {
         self::init();
     }
     if (self::$isWikiaMobile) {
         wfProfileIn(__METHOD__);
         /**
          * WikiaMobile: lazy loading images in a SEO-friendly manner
          * @author Federico "Lox" Lucignano <federico@wikia-inc.com
          * @author Artur Klajnerok <*****@*****.**>
          */
         $origImg = Xml::element('img', $imageAttribs, '', true);
         if (empty($imageAttribs['alt'])) {
             unset($imageAttribs['alt']);
         }
         //Not all 'files' have getProviderName defined
         if (is_callable([$file, 'getProviderName'])) {
             $provider = $file->getProviderName();
         } else {
             $provider = '';
         }
         $imageParams = array('type' => 'video', 'provider' => $provider, 'full' => $imageAttribs['src']);
         if (!empty($imageAttribs['data-video-key'])) {
             $imageParams['name'] = htmlspecialchars($imageAttribs['data-video-key']);
         }
         if (!empty($options['caption'])) {
             $imageParams['capt'] = 1;
         }
         // TODO: this resizes every video thumbnail with a width over 64px regardless of where it appears.
         // We may want to add the ability to allow custom image widths (like on the file page history table for example)
         $size = WikiaMobileMediaService::calculateMediaSize($file->getWidth(), $file->getHeight());
         $thumb = $file->transform($size);
         $imageAttribs['src'] = wfReplaceImageServer($thumb->getUrl(), $file->getTimestamp());
         $imageAttribs['width'] = $size['width'];
         $imageAttribs['height'] = $size['height'];
         $data = ['attributes' => $imageAttribs, 'parameters' => [$imageParams], 'anchorAttributes' => $linkAttribs, 'noscript' => $origImg, 'isSmall' => WikiaMobileMediaService::isSmallImage($imageAttribs['width'], $imageAttribs['height'])];
         $title = $file->getTitle()->getDBKey();
         $titleText = $file->getTitle()->getText();
         $views = MediaQueryService::getTotalVideoViewsByTitle($title);
         $data['content'] = Xml::element('span', ['class' => 'videoInfo'], "{$titleText} (" . $file->getHandler()->getFormattedDuration() . ", " . wfMessage('wikiamobile-video-views-counter', $views)->inContentLanguage()->text() . ')');
         $html = F::app()->sendRequest('WikiaMobileMediaService', 'renderImageTag', $data, true)->toString();
         wfProfileOut(__METHOD__);
     }
     return true;
 }
コード例 #3
0
 /**
  * @static
  * @param Title $fileTitle
  * @param array $config ( contextWidth, contextHeight, imageMaxWidth, userAvatarWidth )
  * TODO - this method is very specific to lightbox.  This needs to be refactored back out to lightbox, and return just the basic objects (file, user, tect)
  * @return array
  */
 public static function getMediaDetail($fileTitle, $config = array())
 {
     $data = array('mediaType' => '', 'videoEmbedCode' => '', 'playerAsset' => '', 'imageUrl' => '', 'fileUrl' => '', 'rawImageUrl' => '', 'description' => '', 'userThumbUrl' => '', 'userId' => '', 'userName' => '', 'userPageUrl' => '', 'articles' => array(), 'providerName' => '', 'videoViews' => 0, 'exists' => false, 'isAdded' => true, 'extraHeight' => 0);
     if (!empty($fileTitle)) {
         if ($fileTitle->getNamespace() != NS_FILE) {
             $fileTitle = Title::newFromText($fileTitle->getDBKey(), NS_FILE);
         }
         $file = self::getFileFromTitle($fileTitle, true);
         if (!empty($file)) {
             $config = self::getMediaDetailConfig($config);
             $data['exists'] = true;
             $data['mediaType'] = self::isFileTypeVideo($file) ? 'video' : 'image';
             $width = (int) $file->getWidth();
             $height = (int) $file->getHeight();
             if ($data['mediaType'] == 'video') {
                 $width = $config['contextWidth'] ? $config['contextWidth'] : $width;
                 $height = $config['contextHeight'] ? $config['contextHeight'] : $height;
                 if (isset($config['maxHeight'])) {
                     $file->setEmbedCodeMaxHeight($config['maxHeight']);
                 }
                 $options = ['autoplay' => true, 'isAjax' => true, 'isInline' => !empty($config['isInline'])];
                 $data['videoEmbedCode'] = $file->getEmbedCode($width, $options);
                 $data['playerAsset'] = $file->getPlayerAssetUrl();
                 $data['videoViews'] = MediaQueryService::getTotalVideoViewsByTitle($fileTitle->getDBKey());
                 $data['providerName'] = $file->getProviderName();
                 $data['duration'] = $file->getMetadataDuration();
                 $data['isAdded'] = self::isAdded($file);
                 $mediaPage = self::getMediaPage($fileTitle);
                 // Extra height is needed for lightbox when more elements must be fitted
                 if (strtolower($data['providerName']) == 'crunchyroll') {
                     $data['extraHeight'] = CrunchyrollVideoHandler::CRUNCHYROLL_WIDGET_HEIGHT_PX;
                 }
             } else {
                 $width = !empty($config['imageMaxWidth']) ? min($config['imageMaxWidth'], $width) : $width;
                 $mediaPage = new ImagePage($fileTitle);
             }
             $thumb = $file->transform(array('width' => $width, 'height' => $height), 0);
             $user = User::newFromId($file->getUser('id'));
             // get article list
             $mediaQuery = new ArticlesUsingMediaQuery($fileTitle);
             $articleList = $mediaQuery->getArticleList();
             if ($data['isAdded']) {
                 $data['fileUrl'] = $fileTitle->getFullUrl();
             } else {
                 $data['fileUrl'] = self::getFullUrlPremiumVideo($fileTitle->getDBkey());
             }
             $data['imageUrl'] = $thumb->getUrl();
             $data['rawImageUrl'] = $file->getUrl();
             $data['userId'] = $user->getId();
             $data['userName'] = $user->getName();
             $data['userThumbUrl'] = AvatarService::getAvatarUrl($user, $config['userAvatarWidth']);
             $data['userPageUrl'] = $user->getUserPage()->getFullURL();
             $data['description'] = $mediaPage->getContent();
             $data['articles'] = $articleList;
             $data['width'] = $width;
             $data['height'] = $height;
         }
     }
     return $data;
 }
コード例 #4
0
 public function onThumbnailVideoHTML($options, $linkAttribs, $imageAttribs, File $file, &$html)
 {
     $this->wf->profileIn(__METHOD__);
     if (self::$isWikiaMobile) {
         /**
          * WikiaMobile: lazy loading images in a SEO-friendly manner
          * @author Federico "Lox" Lucignano <federico@wikia-inc.com
          * @author Artur Klajnerok <*****@*****.**>
          */
         $origImg = Xml::element('img', $imageAttribs, '', true);
         if (empty($imageAttribs['alt'])) {
             unset($imageAttribs['alt']);
         }
         $imageParams = array('type' => 'video', 'full' => $imageAttribs['src']);
         if (!empty($linkAttribs['data-video-name'])) {
             $imageParams['name'] = $linkAttribs['data-video-name'];
         }
         if (!empty($options['caption'])) {
             $imageParams['capt'] = true;
         }
         if ($file instanceof File) {
             $size = WikiaMobileMediaService::calculateMediaSize($file->getWidth(), $file->getHeight());
             $thumb = $file->transform($size);
             $imageAttribs['src'] = wfReplaceImageServer($thumb->getUrl(), $file->getTimestamp());
             $imageAttribs['width'] = $size['width'];
             $imageAttribs['height'] = $size['height'];
         }
         $data = array('attributes' => $imageAttribs, 'parameters' => array($imageParams), 'anchorAttributes' => $linkAttribs, 'noscript' => $origImg);
         if ($file instanceof File) {
             $title = $file->getTitle()->getDBKey();
             $titleText = $file->getTitle()->getText();
             $data['content'] = Xml::element('span', array('class' => 'videoInfo'), "{$titleText} (" . $file->getHandler()->getFormattedDuration() . ", " . $this->wf->MsgForContent('wikiamobile-video-views-counter', MediaQueryService::getTotalVideoViewsByTitle($title)) . ')');
         }
         $html = $this->app->sendRequest('WikiaMobileMediaService', 'renderImageTag', $data, true)->toString();
     }
     $this->wf->profileOut(__METHOD__);
     return true;
 }
コード例 #5
0
 public function getCaruselElement()
 {
     wfProfileIn(__METHOD__);
     $video = $this->getVal('video');
     if (empty($video)) {
         $title = $this->getVal('videoTitle');
         $rvs = F::build('RelatedVideosService');
         $video = $rvs->getRelatedVideoDataFromTitle(array('title' => $title));
     }
     $preloaded = $this->getVal('preloaded');
     $videoTitle = F::build('Title', array($video['id'], NS_FILE), 'newFromText');
     $videoFile = wfFindFile($videoTitle);
     if ($videoFile) {
         $videoThumbObj = $videoFile->transform(array('width' => $video['thumbnailData']['width'], 'height' => $video['thumbnailData']['height']));
         $videoThumb = $videoThumbObj->toHtml(array('custom-url-link' => $video['fullUrl'], 'linkAttribs' => array('class' => 'video-thumbnail lightbox', 'data-video-name' => $video['title'], 'data-external' => $video['external'], 'data-ref' => $video['prefixedUrl']), 'duration' => true, 'src' => $preloaded ? false : wfBlankImgUrl(), 'constHeight' => RelatedVideosService::$height, 'usePreloading' => true, 'disableRDF' => true));
         $video['views'] = MediaQueryService::getTotalVideoViewsByTitle($videoTitle->getDBKey());
         // Add ellipses if title is too long
         $maxDescriptionLength = 45;
         $video['truncatedTitle'] = strlen($video['title']) > $maxDescriptionLength ? substr($video['title'], 0, $maxDescriptionLength) . '&#8230;' : $video['title'];
         $video['viewsMsg'] = wfMsg('related-videos-video-views', $this->wg->ContLang->formatNum($video['views']));
         $userGroups = $this->wg->User->getEffectiveGroups();
         $isAdmin = in_array('admin', $userGroups) || in_array('staff', $userGroups);
         $this->removeTooltip = wfMsg('related-videos-tooltip-remove');
         $this->videoThumb = $videoThumb;
         $this->video = $video;
         $this->preloaded = $preloaded;
         $this->isAdmin = $isAdmin;
     } else {
         Wikia::log(__METHOD__, false, 'A video file not found. ID: ' . $video['id']);
     }
     // set cache control to 1 day
     $this->response->setCacheValidity(86400, 86400, array(WikiaResponse::CACHE_TARGET_BROWSER, WikiaResponse::CACHE_TARGET_VARNISH));
     wfProfileOut(__METHOD__);
 }
コード例 #6
0
 /**
  * @static
  * @param Title $fileTitle
  * @param array $config ( contextWidth, contextHeight, imageMaxWidth, userAvatarWidth )
  * TODO - this method is very specific to lightbox.  This needs to be refactored back out to lightbox, and return just the basic objects (file, user, tect)
  */
 public static function getMediaDetail($fileTitle, $config = array())
 {
     $data = array('mediaType' => '', 'videoEmbedCode' => '', 'playerAsset' => '', 'imageUrl' => '', 'fileUrl' => '', 'rawImageUrl' => '', 'description' => '', 'userThumbUrl' => '', 'userId' => '', 'userName' => '', 'userPageUrl' => '', 'articles' => array(), 'providerName' => '', 'videoViews' => 0, 'exists' => false);
     if (!empty($fileTitle)) {
         if ($fileTitle->getNamespace() != NS_FILE) {
             $fileTitle = F::build('Title', array($fileTitle->getDBKey(), NS_FILE), 'newFromText');
         }
         $file = wfFindFile($fileTitle);
         if (!empty($file)) {
             $config = self::getMediaDetailConfig($config);
             $data['exists'] = true;
             $data['mediaType'] = self::isFileTypeVideo($file) ? 'video' : 'image';
             $width = $file->getWidth();
             $height = $file->getHeight();
             if ($data['mediaType'] == 'video') {
                 $width = $config['contextWidth'] ? $config['contextWidth'] : $width;
                 $height = $config['contextHeight'] ? $config['contextHeight'] : $height;
                 if (isset($config['maxHeight'])) {
                     $file->setEmbedCodeMaxHeight($config['maxHeight']);
                 }
                 $data['videoEmbedCode'] = $file->getEmbedCode($width, true, true);
                 $data['playerAsset'] = $file->getPlayerAssetUrl();
                 $data['videoViews'] = MediaQueryService::getTotalVideoViewsByTitle($fileTitle->getDBKey());
                 $mediaPage = F::build('WikiaVideoPage', array($fileTitle));
                 $data['providerName'] = $file->getProviderName();
             } else {
                 $width = $width > $config['imageMaxWidth'] ? $config['imageMaxWidth'] : $width;
                 $mediaPage = F::build('ImagePage', array($fileTitle));
             }
             $thumb = $file->transform(array('width' => $width, 'height' => $height), 0);
             $user = F::build('User', array($file->getUser('id')), 'newFromId');
             // get article list
             $mediaQuery = F::build('ArticlesUsingMediaQuery', array($fileTitle));
             $articleList = $mediaQuery->getArticleList();
             $data['imageUrl'] = $thumb->getUrl();
             $data['fileUrl'] = $fileTitle->getLocalUrl();
             $data['rawImageUrl'] = $file->getUrl();
             $data['userId'] = $user->getId();
             $data['userName'] = $user->getName();
             $data['userThumbUrl'] = F::build('AvatarService', array($user, $config['userAvatarWidth']), 'getAvatarUrl');
             $data['userPageUrl'] = $user->getUserPage()->getFullURL();
             $data['description'] = $mediaPage->getContent();
             $data['articles'] = $articleList;
         }
     }
     return $data;
 }