/** * @return array - list of vertical videos (premium videos) */ public function getModuleVideos() { $filter = 'all'; $paddedLimit = $this->getPaddedVideoLimit($this->limit); $mediaService = new \MediaQueryService(); $videoList = $mediaService->getVideoList($this->sort, $filter, $paddedLimit); $videosWithDetails = $this->getVideoDetailFromLocalWiki($videoList); foreach ($videosWithDetails as $video) { if ($this->atVideoLimit()) { break; } $this->addVideo($video); } return $this->videos; }
/** * get list of videos * @param string $sort [recent/popular/trend] * @param integer $page * @param array $providers * @param string $category * @param array $options * @return array $videos */ public function getVideos($sort, $page, $providers = [], $category = '', $options = []) { wfProfileIn(__METHOD__); if ($sort == 'premium') { $sort = 'recent'; $filter = 'premium'; } else { $filter = 'all'; } if ($this->app->checkSkin('wikiamobile')) { $limit = self::VIDEOS_PER_PAGE_MOBILE; $providers = $this->wg->WikiaMobileSupportedVideos; $thumbOptions = ['useTemplate' => true, 'fluid' => true, 'forceSize' => 'small', 'img-class' => 'media', 'dataParams' => true]; } else { $limit = self::VIDEOS_PER_PAGE; $providers = empty($providers) ? [] : explode(',', $providers); $thumbOptions = ['fluid' => true, 'showViews' => true, 'fixedHeight' => self::THUMBNAIL_HEIGHT, 'hidePlayButton' => true]; } // get video list $mediaService = new MediaQueryService(); $videoList = $mediaService->getVideoList($sort, $filter, $limit, $page, $providers, $category); $videoOptions = ['thumbWidth' => self::THUMBNAIL_WIDTH, 'thumbHeight' => self::THUMBNAIL_HEIGHT, 'postedInArticles' => self::POSTED_IN_ARTICLES, 'thumbOptions' => $thumbOptions, 'getThumbnail' => array_key_exists('getThumbnail', $options) ? $options['getThumbnail'] : true]; // get video detail $videos = []; $helper = new VideoHandlerHelper(); foreach ($videoList as $videoInfo) { $videoDetail = $helper->getVideoDetail($videoInfo, $videoOptions); if (!empty($videoDetail)) { $byUserMsg = WikiaFileHelper::getByUserMsg($videoDetail['userName'], $videoDetail['timestamp']); $viewTotal = wfMessage('videohandler-video-views', $this->wg->Lang->formatNum($videoDetail['viewsTotal']))->text(); $videos[] = ['title' => $videoDetail['fileTitle'], 'fileKey' => $videoDetail['title'], 'fileUrl' => $videoDetail['fileUrl'], 'thumbnail' => $videoDetail['thumbnail'], 'timestamp' => wfTimeFormatAgo($videoDetail['timestamp'], false), 'updated' => $videoDetail['timestamp'], 'viewTotal' => $viewTotal, 'byUserMsg' => $byUserMsg, 'truncatedList' => $videoDetail['truncatedList'], 'duration' => $videoDetail['duration'], 'thumbUrl' => $videoDetail['thumbUrl'], 'embedUrl' => $videoDetail['embedUrl']]; } } wfProfileOut(__METHOD__); return $videos; }
/** * Get list of videos (controller that provides access to MediaQueryService::getVideoList method) * @requestParam string sort [recent/popular/trend] * @requestParam integer limit (maximum = 100) * @requestParam integer page * @requestParam string|array providers - Only videos hosted by these providers will be returned. Default: all providers. * @requestParam string|array category - Only videos tagged with these categories will be returned. Default: any categories. * @requestParam integer width - the width of the thumbnail to return * @requestParam integer height - the height of the thumbnail to return * @requestParam integer detail [0/1] - check for getting video detail * @responseParam array * [array('title'=>value, 'provider'=>value, 'addedAt'=>value,'addedBy'=>value, 'duration'=>value, 'viewsTotal'=>value)] */ public function getVideoList() { wfProfileIn(__METHOD__); $params = $this->getVideoListParams(); // Key to cache the data under in memcache $cacheKey = $this->getVideoListCacheKey($params); $cacheOptions = ['cacheTTL' => \WikiaResponse::CACHE_STANDARD, 'negativeCacheTTL' => 0]; // Retrieve the result and if not null, cache it $videoList = \WikiaDataAccess::cacheWithOptions($cacheKey, function () use($params) { $mediaService = new \MediaQueryService(); $videoList = $mediaService->getVideoList($params['sort'], $params['filter'], $params['limit'], $params['page'], $params['providers'], $params['category']); // get video detail if (!empty($params['detail'])) { $videoOptions = ['thumbWidth' => $params['width'], 'thumbHeight' => $params['height']]; $helper = new \VideoHandlerHelper(); foreach ($videoList as &$videoInfo) { $videoDetail = $helper->getVideoDetail($videoInfo, $videoOptions); if (!empty($videoDetail)) { $videoInfo = array_merge($videoInfo, $videoDetail); } } unset($videoInfo); } return $videoList; }, $cacheOptions); $this->response->setVal('videos', $videoList); $this->response->setCacheValidity(\WikiaResponse::CACHE_STANDARD); wfProfileOut(__METHOD__); }