Ejemplo n.º 1
0
 /**
  * @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;
 }
Ejemplo n.º 2
0
 /**
  * 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;
 }
Ejemplo n.º 3
0
 private function videoEntry(Title $title)
 {
     $entries = array();
     $articleVideos = $this->mMediaService->getMediaFromArticle($title, MediaQueryService::MEDIA_TYPE_VIDEO);
     foreach ($articleVideos as $videoTitleData) {
         $metaData = $videoTitleData['meta'];
         if ($metaData['canEmbed'] === 0) {
             continue;
         }
         $description = !empty($videoTitleData['desc']) ? $videoTitleData['desc'] : (!empty($metaData['description']) ? $metaData['description'] : $videoTitleData['title']);
         $entry = "\t\t<video:video>\n" . "\t\t\t<video:title><![CDATA[{$videoTitleData['title']}]]></video:title>\n" . "\t\t\t<video:description><![CDATA[{$description}]]></video:description>\n" . (!empty($videoTitleData['thumbUrl']) ? "\t\t\t<video:thumbnail_loc>{$videoTitleData['thumbUrl']}</video:thumbnail_loc>\n" : "") . ($metaData['srcType'] == 'player' ? "\t\t\t<video:player_loc allow_embed=\"yes\" " . (!empty($metaData['autoplayParam']) ? "autoplay=\"{$metaData['autoplayParam']}\"" : "") . ">" . htmlentities($metaData['srcParam']) . "</video:player_loc>\n" : "\t\t\t<video:content_loc>" . htmlentities($metaData['srcParam']) . "</video:content_loc>\n") . (!empty($metaData['duration']) ? "\t\t\t<video:duration>{$metaData['duration']}</video:duration>\n" : "") . "\t\t\t<video:family_friendly>yes</video:family_friendly>\n" . "\t\t</video:video>\n";
         $entries[] = $entry;
     }
     return implode("\t\n", $entries);
 }
Ejemplo n.º 4
0
 private function videoEntry(Title $title)
 {
     wfProfileIn(__METHOD__);
     $file = wfFindFile($title);
     $videoTitleData = $this->mMediaService->getMediaData($title, 500);
     $isVideo = WikiaFileHelper::isFileTypeVideo($file);
     if (!$isVideo) {
         wfProfileOut(__METHOD__);
         return '';
     }
     $metaData = $videoTitleData['meta'];
     if ($videoTitleData['type'] != MediaQueryService::MEDIA_TYPE_VIDEO || $metaData['canEmbed'] === 0) {
         wfProfileOut(__METHOD__);
         return '';
     }
     $description = !empty($videoTitleData['desc']) ? $videoTitleData['desc'] . ' ' : (!empty($metaData['description']) ? $metaData['description'] . ' ' : '');
     $description .= $videoTitleData['title'];
     $entry = "\t\t<video:video>\n" . "\t\t\t<video:title><![CDATA[{$videoTitleData['title']}]]></video:title>\n" . "\t\t\t<video:description><![CDATA[{$description}]]></video:description>\n" . (!empty($videoTitleData['thumbUrl']) ? "\t\t\t<video:thumbnail_loc>{$videoTitleData['thumbUrl']}</video:thumbnail_loc>\n" : "") . ($metaData['srcType'] == 'player' ? "\t\t\t<video:player_loc allow_embed=\"yes\" " . (!empty($metaData['autoplayParam']) ? "autoplay=\"{$metaData['autoplayParam']}\"" : "") . ">" . htmlentities($metaData['srcParam']) . "</video:player_loc>\n" : "\t\t\t<video:content_loc>" . htmlentities($metaData['srcParam']) . "</video:content_loc>\n") . (!empty($metaData['duration']) ? "\t\t\t<video:duration>{$metaData['duration']}</video:duration>\n" : "") . "\t\t\t<video:family_friendly>yes</video:family_friendly>\n" . "\t\t</video:video>\n";
     wfProfileOut(__METHOD__);
     return $entry;
 }
Ejemplo n.º 5
0
 function query()
 {
     global $wgRequest, $wgHTTPProxy;
     $query = $wgRequest->getText('query');
     $page = $wgRequest->getVal('page', 1);
     $sourceId = $wgRequest->getVal('sourceId');
     if ($sourceId == 1) {
         $flickrAPI = new phpFlickr('bac0bd138f5d0819982149f67c0ca734');
         $proxyArr = explode(':', $wgHTTPProxy);
         $flickrAPI->setProxy($proxyArr[0], $proxyArr[1]);
         $flickrResult = $flickrAPI->photos_search(array('tags' => $query, 'tag_mode' => 'all', 'page' => $page, 'per_page' => 8, 'license' => '4,5', 'sort' => 'interestingness-desc'));
         $tmpl = new EasyTemplate(dirname(__FILE__) . '/templates/');
         $tmpl->set_vars(array('results' => $flickrResult, 'query' => addslashes($query)));
         return $tmpl->render('results_flickr');
     } else {
         if ($sourceId == 0) {
             if ((int) $page == 0) {
                 $page = 1;
             }
             $mediaService = new MediaQueryService();
             $results = $mediaService->searchInTitle($query, $page, 8);
             $tmpl = new EasyTemplate(dirname(__FILE__) . '/templates/');
             $tmpl->set_vars(array('results' => $results, 'query' => addslashes($query)));
             return $tmpl->render('results_thiswiki');
         }
     }
 }
 /**
  * Return thumbs of images search result
  */
 public static function getSearchResultThumbs($query, $limit = 50)
 {
     wfProfileIn(__METHOD__);
     $images = array();
     if (!empty($query)) {
         $mediaService = new MediaQueryService();
         $results = $mediaService->searchInTitle($query, 1, $limit);
         if (!empty($results['images'])) {
             foreach ($results['images'] as $img) {
                 $oImageTitle = Title::newFromText($img['title'], NS_FILE);
                 $thumb = self::getResultsThumbnailUrl($oImageTitle);
                 if ($thumb) {
                     $images[] = array('name' => $oImageTitle->getText(), 'thumb' => $thumb);
                 }
             }
         }
     }
     wfProfileOut(__METHOD__);
     return $images;
 }
Ejemplo n.º 7
0
 public function execute()
 {
     $this->test = $this->hasOption('test');
     $this->verbose = $this->hasOption('verbose');
     $workingVideos = 0;
     $deletedVideos = 0;
     $privateVideos = 0;
     $otherErrorVideos = 0;
     $log = WikiaLogger::instance();
     // Only write to memcache, no reads. We want to make sure to always talk to each of the provider's API directly.
     // Since each time a request is made to these APIs the response is cached for 1 day, disallow memcache reads
     // so we can be sure to not be pulling stale data.
     F::app()->wg->AllowMemcacheReads = false;
     F::app()->wg->AllowMemcacheWrites = true;
     $this->debug("(debugging output enabled)\n ");
     $allVideos = $this->getVideos();
     foreach ($allVideos as $provider => $videos) {
         $class = ucfirst($provider) . "ApiWrapper";
         foreach ($videos as $video) {
             try {
                 // No need to assign this object to anything, we're just trying to catch exceptions during its creation
                 new $class($video['video_id']);
                 // If an exception isn't thrown by this point, we know the video is still good
                 $this->debug("Found working video: " . $video['video_title']);
                 $workingVideos++;
             } catch (Exception $e) {
                 $removeVideo = true;
                 $loggingParams = ["video_title" => $video["video_title"], "video_id" => $video["video_id"], "error" => $e->getMessage(), "exception" => get_class($e), "status_code" => $e->getStatusCode()];
                 $log->info("Video with error encountered", $loggingParams);
                 if ($e instanceof VideoNotFoundException) {
                     $this->debug("Found deleted video: " . $video['video_title']);
                     $deletedVideos++;
                     $status = self::STATUS_DELETED;
                 } elseif ($e instanceof VideoIsPrivateException) {
                     $this->debug("Found private video: " . $video['video_title']);
                     $privateVideos++;
                     $status = self::STATUS_PRIVATE;
                 } else {
                     $this->debug("Found other video: " . $video['video_title']);
                     $this->debug($e->getMessage());
                     $otherErrorVideos++;
                     $status = self::STATUS_OTHER_ERROR;
                     $removeVideo = false;
                 }
                 if (!$this->test) {
                     wfSetWikiaPageProp(WPP_VIDEO_STATUS, $video['page_id'], $status);
                     if ($removeVideo) {
                         $this->setRemovedValue($video, $removeVideo);
                     }
                 }
             }
         }
     }
     if (!$this->test) {
         $mediaService = new MediaQueryService();
         $mediaService->clearCacheTotalVideos();
         $memcKeyRecent = wfMemcKey('videomodule', 'local_videos', VideosModule::CACHE_VERSION, "recent");
         F::app()->wg->Memc->delete($memcKeyRecent);
     }
     echo "\n========SUMMARY========\n";
     echo "Found {$workingVideos} working videos\n";
     echo "Found {$deletedVideos} deleted videos\n";
     echo "Found {$privateVideos} private videos\n";
     echo "Found {$otherErrorVideos} other videos\n";
 }
Ejemplo n.º 8
0
 /**
  * Add given number of recently uploaded images to slideshow
  */
 private function addRecentlyUploaded($limit)
 {
     wfProfileIn(__METHOD__);
     $uploadedImages = MediaQueryService::getRecentlyUploaded($limit);
     // remove images already added to slideshow
     $this->mFiles = array();
     $this->mData['imagesShown'] = array();
     // add recently uploaded images to slideshow
     if (!empty($uploadedImages)) {
         /** @var Title $image */
         foreach ($uploadedImages as $image) {
             $this->add($image);
             // store list of images (to be used by front-end)
             $this->mData['imagesShown'][] = array('name' => $image->getText(), 'caption' => '', 'link' => '', 'linktext' => '', 'recentlyUploaded' => true, 'shorttext' => '');
             // Only add real images (bug #5586)
             if ($image->getNamespace() == NS_FILE) {
                 $this->mParser->mOutput->addImage($image->getDBkey());
             }
         }
     }
     wfProfileOut(__METHOD__);
 }
 /**
  * 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__);
 }
 private function getVideoInfo($title)
 {
     $mediaService = new MediaQueryService();
     $mediaInfo = $mediaService->getMediaData($title);
     if (!empty($mediaInfo)) {
         if ($mediaInfo['type'] === 'video') {
             $type = 'video';
             $provider = $mediaInfo['meta']['provider'];
             $thumbUrl = $mediaInfo['thumbUrl'];
             $videoId = $mediaInfo['meta']['videoId'];
             return [$type, ['provider' => $provider, 'thumb_url' => $thumbUrl, 'videoId' => $videoId]];
         }
     }
     return [null, null];
 }
Ejemplo n.º 11
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.º 12
0
 /**
  * check if premium video exists
  * @return integer $videoExist [0/1]
  */
 public function premiumVideosExist()
 {
     $mediaService = new MediaQueryService();
     $videoExist = (bool) $mediaService->getTotalPremiumVideos();
     return $videoExist;
 }
Ejemplo n.º 13
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;
 }
 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__);
 }
Ejemplo n.º 15
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;
 }
Ejemplo n.º 16
0
 /**
  * Render default page header (with edit dropdown, history dropdown, ...)
  *
  * @param: array $params
  *    key: showSearchBox (default: false)
  */
 public function executeIndex($params)
 {
     global $wgTitle, $wgArticle, $wgOut, $wgUser, $wgContLang, $wgSupressPageTitle, $wgSupressPageSubtitle, $wgSuppressNamespacePrefix, $wgEnableWallExt;
     wfProfileIn(__METHOD__);
     $this->isUserLoggedIn = $wgUser->isLoggedIn();
     // check for video add button permissions
     $this->showAddVideoBtn = $wgUser->isAllowed('videoupload');
     // page namespace
     $ns = $wgTitle->getNamespace();
     /** start of wikia changes @author nAndy */
     $this->isWallEnabled = !empty($wgEnableWallExt) && $ns == NS_USER_WALL;
     /** end of wikia changes */
     // currently used skin
     $skin = RequestContext::getMain()->getSkin();
     // action button (edit / view soruce) and dropdown for it
     $this->prepareActionButton();
     // dropdown actions
     $this->dropdown = $this->getDropdownActions();
     /** start of wikia changes @author nAndy */
     $response = $this->getResponse();
     if ($response instanceof WikiaResponse) {
         wfRunHooks('PageHeaderIndexAfterActionButtonPrepared', array($response, $ns, $skin));
         /** @author Jakub */
         $this->extraButtons = array();
         wfRunHooks('PageHeaderIndexExtraButtons', array($response));
     } else {
         // it happened on TimQ's devbox that $response was probably null fb#28747
         WikiaLogger::instance()->error('Response not an instance of WikiaResponse', ['ex' => new Exception()]);
     }
     /** end of wikia changes */
     // for not existing pages page header is a bit different
     $this->pageExists = !empty($wgTitle) && $wgTitle->exists();
     // default title "settings" (RT #145371), don't touch special pages
     if ($ns != NS_SPECIAL) {
         $this->displaytitle = true;
         $this->title = $wgOut->getPageTitle();
     } else {
         // on special pages titles are already properly encoded (BugId:5983)
         $this->displaytitle = true;
     }
     // perform namespace and special page check
     // use service to get data
     $service = PageStatsService::newFromTitle($wgTitle);
     // comments - moved here to display comments even on deleted/non-existant pages
     $this->comments = $service->getCommentsCount();
     if ($this->pageExists) {
         // mainpage?
         if (WikiaPageType::isMainPage()) {
             $this->isMainPage = true;
         }
         // number of pages on this wiki
         $this->tallyMsg = wfMessage('oasis-total-articles-mainpage', SiteStats::articles())->parse();
     }
     // remove namespaces prefix from title
     $namespaces = array(NS_MEDIAWIKI, NS_TEMPLATE, NS_CATEGORY, NS_FILE);
     if (in_array($ns, array_merge($namespaces, $wgSuppressNamespacePrefix))) {
         $this->title = $wgTitle->getText();
         $this->displaytitle = false;
     }
     // talk pages
     if ($wgTitle->isTalkPage()) {
         // remove comments & FB like button
         $this->comments = false;
         // Talk: <page name without namespace prefix>
         $this->displaytitle = true;
         $this->title = Xml::element('strong', array(), $wgContLang->getNsText(NS_TALK) . ':');
         $this->title .= htmlspecialchars($wgTitle->getText());
         // back to subject article link
         switch ($ns) {
             case NS_TEMPLATE_TALK:
                 $msgKey = 'oasis-page-header-back-to-template';
                 break;
             case NS_MEDIAWIKI_TALK:
                 $msgKey = 'oasis-page-header-back-to-mediawiki';
                 break;
             case NS_CATEGORY_TALK:
                 $msgKey = 'oasis-page-header-back-to-category';
                 break;
             case NS_FILE_TALK:
                 $msgKey = 'oasis-page-header-back-to-file';
                 break;
             default:
                 $msgKey = 'oasis-page-header-back-to-article';
         }
         $this->pageTalkSubject = Wikia::link($wgTitle->getSubjectPage(), wfMsg($msgKey), array('accesskey' => 'c'));
     }
     // forum namespace
     if ($ns == NS_FORUM) {
         // remove comments button
         $this->comments = false;
         // remove namespace prefix
         $this->title = $wgTitle->getText();
         $this->displaytitle = false;
     }
     // mainpage
     if (WikiaPageType::isMainPage()) {
         // change page title to just "Home"
         $this->title = wfMsg('oasis-home');
     }
     // render page type info
     switch ($ns) {
         case NS_MEDIAWIKI:
             $this->pageType = wfMsg('oasis-page-header-subtitle-mediawiki');
             break;
         case NS_TEMPLATE:
             $this->pageType = wfMsg('oasis-page-header-subtitle-template');
             break;
         case NS_SPECIAL:
             $this->pageType = wfMsg('oasis-page-header-subtitle-special');
             // remove comments button (fix FB#3404 - Marooned)
             $this->comments = false;
             if ($wgTitle->isSpecial('Newimages')) {
                 $this->isNewFiles = true;
             }
             if ($wgTitle->isSpecial('Videos')) {
                 $this->isSpecialVideos = true;
                 $mediaService = new MediaQueryService();
                 $this->tallyMsg = wfMessage('specialvideos-wiki-videos-tally', $mediaService->getTotalVideos())->parse();
             }
             if ($wgTitle->isSpecial('LicensedVideoSwap')) {
                 $this->pageType = "";
             }
             break;
         case NS_CATEGORY:
             $this->pageType = wfMsg('oasis-page-header-subtitle-category');
             break;
         case NS_FORUM:
             $this->pageType = wfMsg('oasis-page-header-subtitle-forum');
             break;
     }
     // render subpage info
     $this->pageSubject = $skin->subPageSubtitle();
     if (in_array($wgTitle->getNamespace(), BodyController::getUserPagesNamespaces())) {
         $title = explode(':', $this->title, 2);
         // User:Foo/World_Of_Warcraft:_Residers_in_Shadows (BAC-494)
         if (count($title) >= 2 && $wgTitle->getNsText() == str_replace(' ', '_', $title[0])) {
             // in case of error page (showErrorPage) $title is just a string (cannot explode it)
             $this->title = $title[1];
         }
     }
     // render MW subtitle (contains old revision data)
     $this->subtitle = $wgOut->getSubtitle();
     // render redirect info (redirected from)
     if (!empty($wgArticle->mRedirectedFrom)) {
         $this->pageRedirect = trim($this->subtitle, '()');
         $this->subtitle = '';
     }
     // render redirect page (redirect to)
     if ($wgTitle->isRedirect()) {
         $this->pageType = $this->subtitle;
         $this->subtitle = '';
     }
     if (!empty($wgSupressPageTitle)) {
         $this->title = '';
         $this->subtitle = '';
     }
     if (!empty($wgSupressPageSubtitle)) {
         $this->subtitle = '';
         $this->pageSubtitle = '';
     } else {
         // render pageType, pageSubject and pageSubtitle as one message
         $subtitle = array_filter(array($this->pageType, $this->pageTalkSubject, $this->pageSubject, $this->pageRedirect));
         /*
          * support for language variants
          * this adds links which automatically convert the content to that variant
          *
          * @author tor@wikia-inc.com
          * @author macbre@wikia-inc.com
          */
         $variants = $this->skinTemplate->get('content_navigation')['variants'];
         if (!empty($variants)) {
             foreach ($variants as $variant) {
                 $subtitle[] = Xml::element('a', array('href' => $variant['href'], 'rel' => 'nofollow', 'id' => $variant['id']), $variant['text']);
             }
         }
         $pipe = wfMsg('pipe-separator');
         $this->pageSubtitle = implode(" {$pipe} ", $subtitle);
     }
     // force AjaxLogin popup for "Add a page" button (moved from the template)
     $this->loginClass = !empty($this->wg->DisableAnonymousEditing) ? ' require-login' : '';
     // render monetization module
     if (!empty($params['monetizationModules'])) {
         $this->monetizationModules = $params['monetizationModules'];
     }
     wfProfileOut(__METHOD__);
 }
 /**
  * Get all categories associated with a given video, compare them with the categories we're using as filters
  * on the Special:Videos page, and clear the cache for total videos in categories which match.
  * @param $title
  * @param null||array $categories
  */
 private static function clearCategories($title, $categories = null)
 {
     if (is_null($categories)) {
         $categories = array_map(function ($category) {
             return explode(":", $category)[1];
         }, array_keys($title->getParentCategories()));
     }
     $helper = new MediaQueryService();
     foreach ($categories as $category) {
         if (in_array($category, SpecialVideosHelper::$verticalCategoryFilters)) {
             $helper->clearCacheTotalVideosByCategory($category);
         }
     }
 }
Ejemplo n.º 18
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;
 }