Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
0
 /**
  * get video detail
  * @param array $videoInfo [ array( 'title' => title, 'addedAt' => addedAt , 'addedBy' => addedBy ) ]
  * @param array $options
  *   [ array( 'thumbWidth' => int, 'thumbHeight' => int, 'postedInArticles' => int, 'getThumbnail' => bool, 'thumbOptions' => array ) ]
  *   Keys:
  *     thumbWidth - the width of the thumbnail to return (required)
  *     thumbHeight - the height of the thumbnail to return (required)
  *     getThumbnail - whether to return a fully formed html thumbnail of the video or not
  *     thumbOptions - the option of the thumbnail to return
  *     postedInArticles - the number of "posted in" article details to return
  * @return array $videoDetail
  */
 public function getVideoDetail($videoInfo, $options)
 {
     wfProfileIn(__METHOD__);
     $videoDetail = array();
     /** @var Title $title */
     $title = $videoInfo['title'];
     /** @var LocalFile|WikiaLocalFileShared $file */
     $file = WikiaFileHelper::getVideoFileFromTitle($title);
     if ($file) {
         // get thumbnail
         $thumb = $file->transform(['width' => $options['thumbWidth'], 'height' => $options['thumbHeight']]);
         $thumbUrl = $thumb->getUrl();
         // get user
         if (empty($videoInfo['addedBy'])) {
             $userName = '';
             $userUrl = '';
         } else {
             $user = User::newFromId($videoInfo['addedBy']);
             $userName = User::isIP($user->getName()) ? wfMessage('oasis-anon-user')->text() : $user->getName();
             $userUrl = $user->getUserPage()->getFullURL();
         }
         $thumbnail = '';
         if (!empty($options['getThumbnail'])) {
             $thumbOptions = empty($options['thumbOptions']) ? [] : $options['thumbOptions'];
             if (empty($thumbOptions['alt'])) {
                 $thumbOptions['alt'] = htmlspecialchars($title->getText());
             }
             $thumbnail = $thumb->toHtml($thumbOptions);
         }
         // get article list
         if (empty($options['postedInArticles'])) {
             $isTruncated = 0;
             $truncatedList = array();
         } else {
             $mediaQuery = new ArticlesUsingMediaQuery($title);
             $articleList = $mediaQuery->getArticleList();
             list($truncatedList, $isTruncated) = WikiaFileHelper::truncateArticleList($articleList, $options['postedInArticles']);
         }
         // video details
         $videoDetail = array('title' => $title->getDBKey(), 'fileTitle' => $title->getText(), 'description' => $this->getVideoDescription($file), 'fileUrl' => $title->getFullURL(), 'thumbUrl' => $thumbUrl, 'userName' => $userName, 'userUrl' => $userUrl, 'truncatedList' => $truncatedList, 'isTruncated' => $isTruncated, 'timestamp' => empty($videoInfo['addedAt']) ? '' : $videoInfo['addedAt'], 'duration' => (double) $file->getMetadataDuration(), 'viewsTotal' => empty($videoInfo['viewsTotal']) ? 0 : $videoInfo['viewsTotal'], 'provider' => $file->getProviderName(), 'embedUrl' => $file->getHandler()->getEmbedUrl(), 'videoId' => $file->getVideoId(), 'thumbnail' => $thumbnail, 'regionalRestrictions' => $file->getRegionalRestrictions());
     } else {
         Wikia::Log(__METHOD__, false, "No file found for '" . $videoInfo['title'] . "'");
     }
     wfProfileOut(__METHOD__);
     return $videoDetail;
 }