/** * Get the video details (things like videoId, provider, description, regional restrictions, etc) * for video from the local wiki. * * @param array $videos A list of video titles * @return array */ public function getVideoDetailFromLocalWiki(array $videos) { $videoDetails = []; $helper = new \VideoHandlerHelper(); foreach ($videos as $video) { $details = $helper->getVideoDetail($video, self::$videoOptions); if (!empty($details)) { $videoDetails[] = $details; } } return $videoDetails; }
/** * Correctly formats response as expected by VET, and inflates video data on each result. * * @param array $searchResponse * @return array */ protected function postProcessSearchResponse(array $searchResponse) { $config = $this->getConfig(); $data = []; $start = $config->getStart(); $pos = $start; $videoOptions = ['thumbWidth' => $this->getWidth(), 'thumbHeight' => $this->getHeight(), 'getThumbnail' => true, 'thumbOptions' => ['forceSize' => 'small']]; // Determine the source for the search $isLocalSearch = $this->getSearchType() === 'local'; $helper = new VideoHandlerHelper(); foreach ($searchResponse['items'] as $singleVideoData) { if (empty($singleVideoData['title'])) { continue; } // Get data about this video from the video wiki if ($isLocalSearch) { $videosDetail = $helper->getVideoDetail($singleVideoData, $videoOptions); } else { $videosDetail = $helper->getVideoDetailFromWiki(F::app()->wg->WikiaVideoRepoDBName, $singleVideoData['title'], $videoOptions); } $trimTitle = $this->getTrimTitle(); if (!empty($trimTitle)) { $videosDetail['fileTitle'] = mb_substr($singleVideoData['title'], 0, $trimTitle); } $singleVideoData['pos'] = $pos++; $data[] = $videosDetail; } return ['totalItemCount' => $searchResponse['total'], 'nextStartFrom' => $start + $config->getLimit(), 'items' => $data]; }
/** * Get a list of non-premium videos that are available to swap * * @param string $sort - The sort order for the video list (options: recent, popular, trend) * @param integer $page - Which page to display. Each page contains self::VIDEOS_PER_PAGE videos * @param boolean $useMaster * @return array - Returns a list of video metadata */ public function getRegularVideoList($sort, $page, $useMaster = false) { wfProfileIn(__METHOD__); // Get the list of videos that haven't been swapped yet $videoList = $this->getUnswappedVideoList($sort, self::VIDEOS_PER_PAGE, $page, $useMaster); // Reuse code from VideoHandlerHelper $helper = new VideoHandlerHelper(); // Get a list of what videos the user has already looked at $visitedList = unserialize($this->wg->User->getGlobalAttribute(LicensedVideoSwapHelper::USER_VISITED_LIST)); // Go through each video and add additional detail needed to display the video $videos = array(); foreach ($videoList as $videoInfo) { $suggestions = $this->getVideoSuggestions($videoInfo['title']); // Leave out this video if it has no suggestions if (empty($suggestions)) { continue; } $videoDetail = $helper->getVideoDetail($videoInfo, $this->defaultVideoOptions); if (!empty($videoDetail)) { $videoDetail['videoSuggestions'] = $suggestions; $seeMoreLink = SpecialPage::getTitleFor("WhatLinksHere")->escapeLocalUrl(); $seeMoreLink .= '/' . $this->app->wg->ContLang->getNsText(NS_FILE) . ':' . $videoDetail['title']; $videoDetail['seeMoreLink'] = $seeMoreLink; $videoDetail['confirmKeep'] = $this->isStatusKeep($videoInfo['status']) && $this->isStatusNew($videoInfo['status']); $videoDetail['isNew'] = $this->isStatusNew($videoInfo['status']); // Unset the isNew flag if this user has already played this video if (isset($visitedList[$videoInfo['title']])) { $videoDetail['isNew'] = false; } $videos[] = $videoDetail; } else { // Something is wrong with the existing video. Mark this as having no suggestions // to hide it here. Could mark it as skipped but then it would show up on the // history page and that would be confusing. $titleObj = Title::newFromText($videoInfo['title'], NS_FILE); $articleId = $titleObj->getArticleID(); wfSetWikiaPageProp(WPP_LVS_EMPTY_SUGGEST, $articleId, 1); } } wfProfileOut(__METHOD__); return $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__); }