/** * This method pulls the data needed for a VideoInfo object from an existing file when the data does not exist * in the video_info table. This is used in the case where video_info data wasn't created when the video uploaded. * @param File $file - The file object to get video info for * @param boolean $premiumOnly - If true will exit immediately if $file is a local file * @return array|null - An array of data suitable for passing to the VideoInfo constructor */ public function getVideoDataFromFile($file, $premiumOnly = false) { wfProfileIn(__METHOD__); $video = null; if ($file instanceof File && $file->exists() && WikiaFileHelper::isFileTypeVideo($file)) { if (!($premiumOnly && $file->isLocal())) { $fileMetadata = $file->getMetadata(); $userId = $file->getUser('id'); $addedAt = $file->getTimestamp() ? $file->getTimestamp() : wfTimestamp(TS_MW); $duration = 0; $hdfile = 0; $videoId = ''; if ($fileMetadata) { $fileMetadata = unserialize($fileMetadata); if (array_key_exists('duration', $fileMetadata)) { $duration = $fileMetadata['duration']; } if (array_key_exists('hd', $fileMetadata)) { $hdfile = $fileMetadata['hd'] ? 1 : 0; } if (array_key_exists('videoId', $fileMetadata)) { $videoId = $fileMetadata['videoId']; } } $premium = $file->isLocal() ? 0 : 1; $video = array('videoTitle' => $file->getName(), 'videoId' => $videoId, 'provider' => $file->minor_mime, 'addedAt' => $addedAt, 'addedBy' => $userId, 'duration' => $duration, 'premium' => $premium, 'hdfile' => $hdfile); } } wfProfileOut(__METHOD__); return $video; }
public function getDuplicates() { wfProfileIn(__METHOD__); $img = $this->getDisplayedFile(); $handler = $img->getHandler(); if ($handler instanceof VideoHandler && $handler->isBroken()) { wfProfileOut(__METHOD__); return $this->dupes = array(); } else { $dupes = parent::getDuplicates(); $finalDupes = array(); foreach ($dupes as $dupe) { if (WikiaFileHelper::isFileTypeVideo($dupe) && $dupe instanceof WikiaLocalFile) { if ($dupe->getProviderName() != $img->getProviderName()) { continue; } if ($dupe->getVideoId() != $img->getVideoId()) { continue; } $finalDupes[] = $dupe; } } wfProfileOut(__METHOD__); return $finalDupes; } }
/** * add video * @param string $url * @return string error message or array( $videoTitle, $videoPageId, $videoProvider ) */ public function addVideo($url) { global $wgIsGhostVideo; wfProfileIn(__METHOD__); if (!$this->wg->User->isAllowed('videoupload')) { wfProfileOut(__METHOD__); return wfMessage('videos-error-admin-only')->plain(); } if (empty($url)) { wfProfileOut(__METHOD__); return wfMessage('videos-error-no-video-url')->text(); } $vHelper = new VideoHandlerHelper(); # @TODO Commenting out to fix MAIN-4436 -- Should be fixed correctly when content team is back # if ( !$vHelper->isVideoProviderSupported( $url ) ) { # wfProfileOut( __METHOD__ ); # return wfMessage( 'videos-error-provider-not-supported' )->parse(); # } try { // is it a WikiLink? $title = Title::newFromText($url, NS_FILE); if (!$title || !WikiaFileHelper::isFileTypeVideo($title)) { $title = Title::newFromText(str_replace(array('[[', ']]'), array('', ''), $url), NS_FILE); } if (!$title || !WikiaFileHelper::isFileTypeVideo($title)) { $file = $this->getVideoFileByUrl($url); if ($file) { $title = $file->getTitle(); } } if ($title && WikiaFileHelper::isFileTypeVideo($title)) { $videoTitle = $title; $videoPageId = $title->getArticleId(); $videoProvider = ''; wfRunHooks('AddPremiumVideo', array($title)); } else { if (empty($this->wg->allowNonPremiumVideos)) { wfProfileOut(__METHOD__); return wfMessage('videohandler-non-premium')->parse(); } list($videoTitle, $videoPageId, $videoProvider) = $this->addVideoVideoHandlers($url); $file = RepoGroup::singleton()->findFile($videoTitle); } if (!$file instanceof File) { WikiaLogger::instance()->error('\\VideoHandlerHelper->adDefaultVideoDescription() - File is empty', ['exception' => new Exception(), 'url' => $url, 'title' => $title, 'videoTitle' => $videoTitle, 'videoPageId' => $videoPageId, 'videoProvider' => $videoProvider, 'wgIsGhostVideo' => $wgIsGhostVideo]); wfProfileOut(__METHOD__); return wfMessage('videos-something-went-wrong')->parse(); } else { // Add a default description if available and one doesn't already exist $vHelper->addDefaultVideoDescription($file); } } catch (Exception $e) { wfProfileOut(__METHOD__); return $e->getMessage(); } wfProfileOut(__METHOD__); return array($videoTitle, $videoPageId, $videoProvider); }
/** * change title tag for Video Page and Image Page * @author Jacek Jursza * @param ImagePage $imgPage * @param $html * @return bool */ function onImagePageAfterImageLinks($imgPage, $html) { $file = $imgPage->getDisplayedFile(); /* @var $file LocalRepo */ $title = $imgPage->getTitle(); /* @var $title Title */ $newTitle = ''; if (!empty($file) && !empty($title)) { if (WikiaFileHelper::isFileTypeVideo($file)) { $newTitle = wfMsg('seotweaks-video') . ' - ' . $title->getBaseText(); } else { // It's not Video so lets check if it is Image if ($file instanceof LocalFile && $file->getHandler() instanceof BitmapHandler) { $newTitle = wfMsg('seotweaks-image') . ' - ' . $title->getBaseText(); } } if (!empty($newTitle)) { $this->wg->out->setPageTitle($newTitle); } } return true; }
public function execute() { global $wgUser, $wgTitle; $wgUser = User::newFromName('Wikia'); $wgUser->load(); //get list of pages from how-to category $aReturn = ApiService::call(array('action' => 'query', 'list' => 'categorymembers', 'cmtitle' => 'Category:How-to', 'cmnamespace' => '120')); //perform update foreach page from category foreach ($aReturn['query']['categorymembers'] as $cm) { $oWebinarTitle = Title::newFromText($cm['title']); $wgTitle = $oWebinarTitle; $oWebinarArticle = new Article($oWebinarTitle); echo "Webinar page: " . $oWebinarTitle->getText() . "\n"; //get video link $content = $oWebinarArticle->getContent(); //preq match $matches = $this->matchFile($content); if (!empty($matches)) { //remove params $aFileTitWithParams = explode('|', $matches[1]); //get file title $oFilePageTitle = Title::newFromText($aFileTitWithParams[0], NS_FILE); echo "video file title: " . $oFilePageTitle->getText() . "\n"; if (WikiaFileHelper::isFileTypeVideo($oFilePageTitle)) { //to test echo "=----------- IS VIDEO \n"; //prepare new content without link to video file $newFileContent = str_replace($matches[0], '', $content); //article obj $oFileArticle = new Article($oFilePageTitle); //set new contnet without file link at the begining $oFileArticle->doEdit($newFileContent, 'Moving How-to webinars to video file pages'); //set redirect $oWebinarArticle->doEdit("#redirect[[" . $oFilePageTitle->getPrefixedDBkey() . "]]", 'Setting redirect - conent was moveed to video file page'); } } } }
public function getMediaFromArticle(Title $title, $type = null, $limit = null) { wfProfileIn(__METHOD__); $memcKey = $this->getArticleMediaMemcKey($title); $titles = $this->wg->memc->get($memcKey); if (empty($titles)) { $articleId = $title->getArticleId(); if ($articleId) { $db = $this->wf->GetDB(DB_SLAVE); $result = $db->select(array('imagelinks'), array('il_to'), array("il_from = " . $articleId), __METHOD__, array("ORDER BY" => "il_to")); $titles = array(); while ($row = $db->fetchObject($result)) { $media = F::build('Title', array($row->il_to, NS_FILE), 'newFromText'); $articleService = F::build('ArticleService', array($media->getArticleID())); $file = wfFindFile($media); if (!empty($file)) { if ($file->canRender()) { $isVideo = WikiaFileHelper::isFileTypeVideo($file); if ($isVideo) { /** @var $videoHandler VideoHandler */ $videoHandler = $file->getHandler(); $thumb = $file->transform(array('width' => 320), 0); } else { $videoHandler = false; } $titles[] = array('title' => $media->getText(), 'desc' => $articleService->getTextSnippet(256), 'type' => $isVideo ? self::MEDIA_TYPE_VIDEO : self::MEDIA_TYPE_IMAGE, 'meta' => $videoHandler ? array_merge($videoHandler->getMetadata(true), $videoHandler->getEmbedSrcData()) : array(), 'thumbUrl' => !empty($thumb) ? $thumb->getUrl() : false); } } } $this->wg->memc->set($memcKey, $titles); } } if (!is_array($titles)) { $titles = array(); } if (count($titles) > 0 && $type) { $titles = array_filter($titles, function ($item) use($type) { return $type == $item['type']; }); } if ($limit && $limit > 0) { $titles = array_slice($titles, 0, $limit); } wfProfileOut(__METHOD__); return $titles; }
/** * Parse image options text and use it to make an image * @param Title $title * @param string $options * @param LinkHolderArray $holders * @param int $wikitextIdx */ function makeImage($title, $options, $holders = false) { wfProfileIn(__METHOD__); $wikitextIdx = RTEMarker::getDataIdx(RTEMarker::IMAGE_DATA, $options); // store wikitext for media placeholder rendering method self::$lastWikitext = RTEData::get('wikitext', $wikitextIdx); // call MW parser - image params will be populated parent::makeImage($title, $options, $holders); // maybe it's an image placeholder global $wgEnableImagePlaceholderExt; if (!empty($wgEnableImagePlaceholderExt)) { $isImagePlaceholder = ImagePlaceholderIsPlaceholder($title->getText()); // pass rendered image placeholder if ($isImagePlaceholder) { // return HTML stored by renderMediaPlaceholder() method $ret = self::$mediaPlaceholder; wfProfileOut(__METHOD__); return $ret; } } // check that given image exists $image = wfFindFile($title); $isBrokenImage = empty($image); // render broken image placeholder if ($isBrokenImage) { // handle not existing images $ret = RTELinkerHooks::makeBrokenImageLinkObj($title, '', '', '', '', false, $wikitextIdx); wfProfileOut(__METHOD__); return $ret; } $file = wfFindFile($title); $isVideo = WikiaFileHelper::isFileTypeVideo($file); // get and merge image parameters returned by Parser::makeImage $params = array_merge(self::$imageParams['frame'], self::$imageParams['handler']); // cleanup if (isset($params['title'])) { unset($params['title']); } // generate image data $data = array('type' => 'image', 'wikitext' => RTEData::get('wikitext', $wikitextIdx), 'title' => $title->getDBkey()); // try to resolve internal links in image caption (RT #90616) if (RTEData::resolveLinksInMediaCaption($data['wikitext'])) { // now resolve link markers in caption parsed to HTML if (!empty($holders)) { $holders->replace($params['caption']); } RTE::log(__METHOD__ . ': resolved internal link'); } // trigger an edgecase when image caption contains double brackets markers if (RTEData::checkWikitextForMarkers($data['wikitext'])) { RTE::$edgeCases[] = 'COMPLEX.09'; } // small fix: set value of thumbnail entry if (isset($params['thumbnail'])) { $params['thumbnail'] = true; } // keep caption only for thumbs and framed images if (!isset($params['thumbnail']) && !isset($params['framed'])) { $params['caption'] = ''; } // get "unparsed" caption from original wikitext and store parsed one as 'captionParsed' if ($params['caption'] != '') { $wikitext = trim($data['wikitext'], '[]'); $wikitextParts = self::explodeImageArgs($wikitext); // let's assume caption is the last part of image wikitext $originalCaption = end($wikitextParts); $originalCaption = htmlspecialchars_decode($originalCaption); // keep parsed caption and store its wikitext $params['captionParsed'] = $params['caption']; $params['caption'] = $originalCaption; } // pass link image parameter (BugId:6506) // this can be either link-title (internal links) or link-url (external links) if (isset($params['link-title']) && $params['link-title'] instanceof Title) { $params['link'] = $params['link-title']->getPrefixedText(); unset($params['link-title']); } else { if (isset($params['link-url'])) { $params['link'] = $params['link-url']; unset($params['link-url']); } } // parameters are cleaned up - store them in image's meta data $data['params'] = $params; RTE::log(__METHOD__, $data); // image width $imageWidth = intval($image->getWidth()); if (!empty($data['params']['width'])) { // width provided in wikitext $width = $data['params']['width']; // images with width provided should not be resized larger than the original file resolution (RT #41805) if ($imageWidth < $width) { $width = $imageWidth; } } else { if (!empty($data['params']['height'])) { $height = $data['params']['height']; $width = round($image->getWidth() * ($height / $image->getHeight())); } else { if (isset($data['params']['thumbnail'])) { // width not provided - get default for thumbs global $wgUser, $wgThumbLimits; $wopt = $wgUser->getGlobalPreference('thumbsize'); if (!isset($wgThumbLimits[$wopt])) { $wopt = User::getDefaultOption('thumbsize'); } $width = $wgThumbLimits[$wopt]; // thumbed images should not be resized larger than the original file resolution if ($imageWidth < $width) { $width = $imageWidth; } } else { // full size $width = $image->getWidth(); } } } // add extra CSS classes $imgClass = array('image'); if (isset($data['params']['thumbnail']) || $isVideo) { $imgClass[] = 'thumb'; } if (isset($data['params']['framed'])) { $imgClass[] = 'frame'; } if (isset($data['params']['frameless'])) { $imgClass[] = 'frameless'; } if (isset($data['params']['border'])) { $imgClass[] = 'border'; } if (isset($data['params']['align'])) { $imgClass[] = 'align' . ucfirst($data['params']['align']); } if ($data['params']['caption'] != '') { $imgClass[] = 'withCaption'; } // generate image thumbnail $thumb = $image->transform(array('width' => $width)); $thumbClass = get_class($thumb); // RT #25329 if ($thumbClass == 'OggAudioDisplay') { $data['type'] = 'ogg-file'; $ret = RTEMarker::generate(RTEMarker::PLACEHOLDER, RTEData::put('placeholder', $data)); wfProfileOut(__METHOD__); return $ret; } $ret = $thumb->toHtml(array('img-class' => implode(' ', $imgClass))); $mediaType = "image"; if ($isVideo) { $mediaType = "video"; } // add type attribute $ret = substr($ret, 0, -2) . ' type="' . $mediaType . '" />'; RTE::log(__METHOD__, $ret); // store data and mark HTML $ret = RTEData::addIdxToTag(RTEData::put('data', $data), $ret); wfProfileOut(__METHOD__); return $ret; }
/** * Clear total videos by category cache when video categories are added via the Category Select extension, * after checking if it was associated with one of the categories filtered in Special Videos. * @param $title * @param $categories * @return true */ public static function onCategorySelectSave($title, $categories) { if ($title instanceof Title && WikiaFileHelper::isFileTypeVideo($title)) { VideoInfoHooksHelper::clearCategories($title); } return true; }
/** * Render slider preview * * @author Jakub Kurcek */ public static function renderSliderPreview($slider) { global $wgTitle, $wgParser; wfProfileIn(__METHOD__); // use global instance of parser (RT #44689 / RT #44712) $parserOptions = new ParserOptions(); wfDebug(__METHOD__ . "\n" . print_r($slider, true)); // render slider images foreach ($slider['images'] as &$image) { $imageTitle = Title::newFromText($image['name'], NS_FILE); $image['pageTitle'] = ''; $img = wfFindFile($imageTitle); if (is_object($img) && $imageTitle->getNamespace() == NS_FILE) { // render thumbnail $is = new ImageServing(null, self::STRICT_IMG_WIDTH_PREV, array('w' => self::STRICT_IMG_WIDTH_PREV, 'h' => self::STRICT_IMG_HEIGHT_PREV)); $image['thumbnailBg'] = $is->getUrl($image['name'], $img->getWidth(), $img->getHeight()); } elseif (is_object($imageTitle)) { $image['pageTitle'] = $imageTitle->getText(); } $image['isFileTypeVideo'] = WikiaFileHelper::isFileTypeVideo($img); //need to use parse() - see RT#44270 $image['caption'] = $wgParser->parse($image['caption'], $wgTitle, $parserOptions)->getText(); // remove <p> tags from parser caption if (preg_match('/^<p>(.*)\\n?<\\/p>\\n?$/sU', $image['caption'], $m)) { $image['caption'] = $m[1]; } } wfDebug(__METHOD__ . '::after' . "\n" . print_r($slider, true)); // render gallery HTML preview $template = new EasyTemplate(dirname(__FILE__) . '/templates'); $template->set_vars(array('height' => self::STRICT_IMG_HEIGHT_PREV, 'slider' => $slider, 'width' => self::STRICT_IMG_WIDTH_PREV)); $html = $template->render('sliderPreview'); wfProfileOut(__METHOD__); return $html; }
/** * Render Media Gallery (gallery version 2014) * @return string */ private function renderMediaGallery() { $media = []; $result = ''; foreach ($this->mFiles as $val) { $file = wfFindFile($val[0]); if (empty($file) || WikiaFileHelper::isFileTypeVideo($file) || WikiaFileHelper::isFileTypeOgg($file)) { continue; } $media[] = ['title' => $val[0], 'caption' => $val[3], 'link' => $val[2]]; } if (!empty($media)) { $result = F::app()->renderView('MediaGalleryController', 'gallery', ['items' => $media, 'gallery_params' => $this->mData['params'], 'parser' => $this->mParser]); } return $result; }
/** * @brief - Returns pre-formatted social sharing urls and codes * @requestParam string fileTitle * @requestParam string articleTitle (optional) * @responseParam string url - raw url that is automically determined. This is determined to be either article url or file page url. * @responseParam string articleUrl - url to article page * @responseParam string fileUrl - url to file page * @responseParam string embedMarkup - embedable markup * @responseParam string networks - contains id(facebook, twitter, etc) and urls of external social networks */ public function getShareCodes() { $fileTitle = $this->request->getVal('fileTitle', ''); $fileTitle = urldecode($fileTitle); $file = wfFindFile($fileTitle); $shareUrl = ''; $articleUrl = ''; $articleNS = ''; $articleTitleText = ''; $embedMarkup = ''; $fileUrl = ''; $thumbUrl = ''; $networks = array(); if (!empty($file)) { $fileTitleObj = F::build('Title', array($fileTitle, NS_FILE), 'newFromText'); $fileTitle = $fileTitleObj->getText(); $articleTitle = $this->request->getVal('articleTitle'); $articleTitleObj = F::build('Title', array($articleTitle), 'newFromText'); if (!empty($articleTitleObj) && $articleTitleObj->exists()) { $fileParam = $fileTitleObj->getDBKey(); $articleUrl = $articleTitleObj->getFullURL("file={$fileParam}"); $articleNS = $articleTitleObj->getNamespace(); $articleTitleText = $articleTitleObj->getText(); } $fileUrl = $fileTitleObj->getFullURL(); // determine share url $sharingNamespaces = array(NS_MAIN, NS_CATEGORY); $shareUrl = !empty($articleUrl) && in_array($articleNS, $sharingNamespaces) ? $articleUrl : $fileUrl; $thumb = $file->transform(array('width' => 300, 'height' => 250)); $thumbUrl = $thumb->getUrl(); $linkDescription = wfMsg('lightbox-share-description', empty($articleUrl) ? $fileTitle : $articleTitleText, $this->wg->Sitename); if (WikiaFileHelper::isFileTypeVideo($file)) { $embedMarkup = $file->getEmbedCode(300, true, false); } else { $embedMarkup = "<a href=\"{$shareUrl}\"><img width=\"" . $thumb->getWidth() . "\" height=\"" . $thumb->getHeight() . "\" src=\"{$thumbUrl}\"/></a>"; } $shareNetworks = F::build('SocialSharingService')->getNetworks(array('facebook', 'twitter', 'stumbleupon', 'reddit', 'plusone')); foreach ($shareNetworks as $network) { $networks[] = array('id' => $network->getId(), 'url' => $network->getUrl($shareUrl, $linkDescription)); } // Don't show embed code for screenplay b/c it's using JW Player if (WikiaFileHelper::isFileTypeVideo($file) && $file->getProviderName() == 'screenplay') { $embedMarkup = false; } } $this->shareUrl = $shareUrl; $this->embedMarkup = $embedMarkup; $this->articleUrl = $articleUrl; $this->fileUrl = $fileUrl; $this->networks = $networks; $this->fileTitle = $fileTitle; $this->imageUrl = $thumbUrl; // set cache control to 1 day $this->response->setCacheValidity(86400, 86400, array(WikiaResponse::CACHE_TARGET_BROWSER, WikiaResponse::CACHE_TARGET_VARNISH)); }
public function renderMediaGroup() { wfProfileIn(__METHOD__); $items = $this->request->getVal('items', []); /** * This is a parser from ImageGallery * @var $parser Parser */ $parser = $this->request->getVal('parser'); //ImageGallery has parser as false by default //and getVal returns default value when there is no value for a parameter //false is not useful here but is a value nevertheless //that is why default value is set after getVal if (!$parser instanceof Parser) { $parser = $this->wg->Parser; } $first = null; $wikiText = ''; $result = ''; $params = []; //separate linked items from normal ones and select the first one //which will be rendered in the page foreach ($items as $item) { /** * @var $file File */ $file = wfFindFile($item['title']); if ($file instanceof File) { if (!empty($item['link']) || self::isSmallImage($file->getWidth(), $file->getHeight())) { $wikiText .= self::renderOutsideGallery($item); } else { if (empty($first)) { $first = ['data' => $item, 'file' => $file]; } //prepare data for media collection $info = ['name' => htmlspecialchars(urlencode($item['title']->getDBKey())), 'full' => wfReplaceImageServer($file->getFullUrl(), $file->getTimestamp())]; if (WikiaFileHelper::isFileTypeVideo($file)) { $info['type'] = 'video'; $info['provider'] = $file->getProviderName(); } if (!empty($item['caption'])) { $capt = $parser->internalParse($item['caption']); $parser->replaceLinkHolders($capt); //Kill all markers from gallery caption as if at this time they are not converted to HTML //We want have chance to Json encode it and this might really brake gallery HTML //https://wikia-inc.atlassian.net/browse/MOB-346 $info['capt'] = $parser->killMarkers($capt); } $params[] = $info; } } } if (!empty($first) && !empty($params)) { $file = $first['file']; $origWidth = $file->getWidth(); $origHeight = $file->getHeight(); //only one non-linked media left if (count($params) == 1) { $item = $first['data']; //build wikitext for a normal thumb $groupWikiText = '[[' . $item['title']->getPrefixedDBkey() . '|thumb|' . min($origWidth, self::THUMB_WIDTH) . 'px'; if ($item['caption']) { $groupWikiText .= "|{$item['caption']}"; } $groupWikiText .= "]]\n"; $wikiText = "{$groupWikiText}{$wikiText}"; } else { //many left, proceed preparing and rendering the media group $size = self::calculateMediaSize($origWidth, $origHeight); $thumb = $file->transform($size); $attribs = array('src' => wfReplaceImageServer($thumb->getUrl(), $file->getTimestamp()), 'width' => $size['width'], 'height' => $size['height']); $result = $this->render(self::GROUP, $attribs, $params, array(), false, Xml::element('img', $attribs, '', true), [], wfMessage('wikiamobile-media-group-footer', count($params))->inContentLanguage()->plain()); } } //if there's any raw wikitext left to parse //then do it now if (!empty($wikiText)) { $origVal = $this->wg->WikiaMobileDisableMediaGrouping; //avoid wikitext recursion $this->wg->WikiaMobileDisableMediaGrouping = true; //This wikiText is created locally here so we are safe with links also being normally replaced $result .= ParserPool::parse($wikiText, $this->wg->Title, new ParserOptions())->getText(); //restoring to previous value $this->wg->WikiaMobileDisableMediaGrouping = $origVal; } $this->response->setBody($result); wfProfileOut(__METHOD__); }
private function getMediaDataFromCache(Title $media, $length = 256) { wfProfileIn(__METHOD__); if (!isset($this->mediaCache[$media->getDBKey()])) { $file = wfFindFile($media); if (!empty($file) && $file->canRender()) { $articleService = new ArticleService($media); $isVideo = WikiaFileHelper::isFileTypeVideo($file); if ($isVideo) { /** @var $videoHandler VideoHandler */ $videoHandler = $file->getHandler(); $thumb = $file->transform(array('width' => 320), 0); } else { $videoHandler = false; } $this->mediaCache[$media->getDBKey()] = array('title' => $media->getText(), 'desc' => $articleService->getTextSnippet($length), 'type' => $isVideo ? self::MEDIA_TYPE_VIDEO : self::MEDIA_TYPE_IMAGE, 'meta' => $videoHandler ? array_merge($videoHandler->getVideoMetadata(true), $videoHandler->getEmbedSrcData()) : array(), 'thumbUrl' => !empty($thumb) ? $thumb->getUrl() : false); } else { $this->mediaCache[$media->getDBKey()] = false; } } wfProfileOut(__METHOD__); return $this->mediaCache[$media->getDBKey()]; }
/** * Hook: check for video files * @param array $images * @return bool true */ public static function onGlobalUsageLinksUpdateComplete(&$images) { $videoFiles = array(); foreach ($images as $image) { $file = wfFindFile($image); if ($file instanceof File && WikiaFileHelper::isFileTypeVideo($file)) { $videoFiles[] = $image; } } $images = $videoFiles; return true; }
public function getHTML() { global $wgCategoryExhibitionMediaSectionRows; $cachedContent = $this->getFromCache(); if (empty($cachedContent)) { // grabs data for videos and images $aTmpData = $this->fetchSectionItems(array(NS_FILE)); // we wan't old videos if (is_array($aTmpData) && count($aTmpData) > 0) { $pages = Paginator::newFromArray($aTmpData, $wgCategoryExhibitionMediaSectionRows * 4); $pageData = $pages->getPage($this->paginatorPosition, true); $aData = array(); foreach ($pageData as $item) { $itemTitle = Title::newFromID($item['page_id']); $forceHeight = ''; $forceWidth = ''; $isVideo = WikiaFileHelper::isFileTypeVideo($itemTitle); // item is image $image = wfFindFile($itemTitle); $elementClass = 'lightbox'; if (!is_object($image) || $image->height == 0 || $image->width == 0) { $imageSrc = ''; } else { $proportions = $image->width / $image->height; if ($proportions < 1) { $calculatedWidth = floor($proportions * $this->thumbWidth); } else { $calculatedWidth = $this->thumbMedia; } $forceWidth = floor($calculatedWidth); $forceHeight = floor($calculatedWidth / $proportions); $imageServing = new ImageServing(array($item['page_id']), $calculatedWidth, array("w" => $image->width, "h" => $image->height)); $imageSrc = wfReplaceImageServer($image->getThumbUrl($imageServing->getCut($image->width, $image->height) . "-" . $image->getName())); if ($isVideo) { $videoSizeClass = ThumbnailHelper::getThumbnailSize($forceWidth); $elementClass .= ' video video-thumbnail ' . $videoSizeClass; } } $linkedFiles = $this->getLinkedFiles($itemTitle); if (!empty($linkedFiles)) { $linkText = $linkedFiles->getText(); $linkFullUrl = $linkedFiles->getFullURL(); } else { $linkText = ''; $linkFullUrl = ''; } // types casting for proper caching; $aData[] = array('id' => $item['page_id'], 'title' => $itemTitle->getText(), 'key' => $itemTitle->getDBKey(), 'img' => (string) $imageSrc, 'url' => $itemTitle->getFullURL(), 'dimensions' => array('w' => (int) $forceWidth, 'h' => (int) $forceHeight), 'class' => $elementClass, 'data-ref' => $itemTitle->getPrefixedURL(), 'targetUrl' => $linkFullUrl, 'targetText' => $linkText, 'isVideo' => $isVideo); } $aContent = array('data' => $aData, 'category' => $this->categoryTitle->getText(), 'paginator' => $pages->getBarHTML($this->sUrl)); $this->saveToCache($aContent); } else { return false; } } else { $aContent = $cachedContent; } if (!empty($aContent) && is_array($aContent)) { $oTmpl = new EasyTemplate(dirname(__FILE__) . "/templates/"); $oTmpl->set_vars($aContent); $oTmpl->set_vars(array('fromAjax' => $this->isFromAjax)); if ($this->isFromAjax) { return array('page' => $oTmpl->render($this->templateName), 'paginator' => $oTmpl->mVars['paginator']); } else { return $oTmpl->render($this->templateName); } } }
private function getTemplateData($element) { if (! isset($element['file'])) return array(); $file = $element['file']; // crop the images correctly using extension:imageservice $is = new ImageServing(array(), self::THUMB_SIZE); $thumb_url = $is->getThumbnails(array($file)); $thumb_url = array_pop($thumb_url); $thumb_url = $thumb_url['url']; $userName = $file->user_text; $retval = array ( "file_url" => $element['url'], "image_url" => $file->getUrl(), "thumb_url" => $thumb_url, "image_filename" => $file->getTitle()->getFullText(), "user_href" => Wikia::link(Title::newFromText($userName, NS_USER), $userName), "links" => $this->getLinkedFiles($file->name), "isVideoThumb" => WikiaFileHelper::isFileTypeVideo( $file ), "date" => wfTimestamp(TS_ISO_8601, $file->timestamp)); return $retval; }
/** * Remove video * @requestParam string title * @responseParam string result [ok/error] * @responseParam string msg - result message */ public function removeVideo() { wfProfileIn(__METHOD__); $videoTitle = $this->getVal('title', ''); if (empty($videoTitle)) { $this->result = 'error'; $this->msg = wfMessage('videos-error-empty-title')->text(); wfProfileOut(__METHOD__); return; } // check if user is logged in if (!$this->wg->User->isLoggedIn()) { $this->result = 'error'; $this->msg = wfMessage('videos-error-not-logged-in')->text(); wfProfileOut(__METHOD__); return; } // check if user is blocked if ($this->wg->User->isBlocked()) { $this->result = 'error'; $this->msg = wfMessage('videos-error-blocked-user')->text(); wfProfileOut(__METHOD__); return; } // check if read-only if (wfReadOnly()) { $this->result = 'error'; $this->msg = wfMessage('videos-error-readonly')->text(); wfProfileOut(__METHOD__); return; } $error = ''; $title = Title::newFromText($videoTitle, NS_FILE); $file = $title instanceof Title ? wfFindfile($title) : false; if ($file instanceof File && WikiaFileHelper::isFileTypeVideo($file)) { // check permissions $permissionErrors = $title->getUserPermissionsErrors('delete', $this->wg->User); if (count($permissionErrors)) { $this->result = 'error'; $this->msg = wfMessage('videos-error-permissions')->text(); wfProfileOut(__METHOD__); return; } $reason = ''; $suppress = false; if ($file->isLocal()) { $status = Status::newFatal('cannotdelete', wfEscapeWikiText($title->getPrefixedText())); $page = WikiPage::factory($title); $dbw = wfGetDB(DB_MASTER); try { // delete the associated article first if ($page->doDeleteArticleReal($reason, $suppress, 0, false) >= WikiPage::DELETE_SUCCESS) { $status = $file->delete($reason, $suppress); if ($status->isOK()) { $dbw->commit(); } else { $dbw->rollback(); } } } catch (MWException $e) { // rollback before returning to prevent UI from displaying incorrect "View or restore N deleted edits?" $dbw->rollback(); $error = $e->getMessage(); } if ($status->isOK()) { $oldimage = null; $user = $this->wg->User; wfRunHooks('FileDeleteComplete', array(&$file, &$oldimage, &$page, &$user, &$reason)); } else { if (!empty($error)) { $error = $status->getMessage(); } } } else { $article = null; if ($title->exists()) { $article = Article::newFromID($title->getArticleID()); } else { $botUser = User::newFromName('WikiaBot'); $flags = EDIT_NEW | EDIT_SUPPRESS_RC | EDIT_FORCE_BOT; // @FIXME Set $article here after calling addCategoryVideos so that the doDeleteArticle call below works properly $videoHandlerHelper = new VideoHandlerHelper(); $status = $videoHandlerHelper->addCategoryVideos($title, $botUser, $flags); } if (is_object($article) && !$article->doDeleteArticle($reason, $suppress, 0, true, $error)) { if (empty($error)) { $error = wfMessage('videohandler-remove-error-unknown')->text(); } } } } else { $error = wfMessage('videohandler-error-video-no-exist')->text(); } if (empty($error)) { $this->result = 'ok'; $this->msg = wfMessage('videohandler-remove-video-modal-success', $title)->text(); } else { $this->result = 'error'; $this->msg = $error; } wfProfileOut(__METHOD__); }
private function add($item, $res) { wfProfileIn(__METHOD__); global $wgMemc; if ($this->removeDuplicatesType == 0) { //default $key = $res['user'] . '#' . $res['title'] . '#' . $res['comment']; if (is_array($res['rc_params']) && !empty($res['rc_params']['imageInserts'])) { $key .= json_encode($res['rc_params']['imageInserts']); } if (is_array($res['rc_params']) && !empty($res['rc_params']['categoryInserts'])) { $key .= json_encode($res['rc_params']['categoryInserts']); } global $wgWallNS; if (!empty($res['ns']) && !empty($wgWallNS) && in_array(MWNamespace::getSubject($res['ns']), $wgWallNS)) { $key = $res['title']; } } elseif ($this->removeDuplicatesType == 1) { //used in `shortlist`, activity tag $key = $res['title']; } if (!isset($this->results[$key])) { $item['timestamp'] = $res['timestamp']; if (!isset(self::$users[$res['user']])) { if (isset($res['anon'])) { $users[$res['user']] = Xml::element('a', array('href' => Skin::makeSpecialUrl('Contributions') . '/' . $res['user'], 'rel' => 'nofollow'), wfMsg('masthead-anonymous-user')); } else { $ut = Title::newFromText($res['user'], NS_USER); if (empty($ut)) { //we have malformed user names in UTF-8 that causes above function to fail (see FB#1731) wfProfileOut(__METHOD__); return; } if ($ut->isKnown()) { $users[$res['user']] = Xml::element('a', array('href' => $ut->getLocalUrl(), 'rel' => 'nofollow'), $res['user']); } else { $users[$res['user']] = Xml::element('a', array('href' => $ut->getLocalUrl(), 'rel' => 'nofollow', 'class' => 'new'), $res['user']); //$users[$res['user']] = Xml::element('a', array('href' => Skin::makeSpecialUrl('Contributions').'/'.$res['user'], 'rel' => 'nofollow'), $res['user']); } } } $item['user'] = $users[$res['user']]; $item['username'] = $res['user']; if (is_array($res['rc_params'])) { $useflags = !empty($this->parameters['flags']); $shortlist = $useflags && in_array('shortlist', $this->parameters['flags']); $hideimages = $useflags && ($shortlist || in_array('hideimages', $this->parameters['flags'])); $hidevideos = $useflags && ($shortlist || in_array('hidevideos', $this->parameters['flags'])); if (isset($res['rc_params']['autosummaryType'])) { $item['autosummaryType'] = $res['rc_params']['autosummaryType']; } if (isset($res['rc_params']['imageInserts'])) { $item['new_images'] = $item['new_videos'] = array(); foreach ($res['rc_params']['imageInserts'] as $imageName) { if (!$hidevideos && $imageName[0] == ':') { // video $video = self::getThumb(substr($imageName, 1)); if ($video) { $item['new_videos'][] = $video; } } elseif (!$hideimages) { // image if (!isset(self::$images[$imageName])) { wfProfileIn(__METHOD__ . "-imagelinks-count"); $memcKey = wfMemcKey('ac_image_cnt', $imageName); self::$images[$imageName] = $wgMemc->get($memcKey); // Note that memcache returns null if record does not exists in cache // versus 0 returned from database when image does not link to anything if (self::$images[$imageName] === false) { $dbr = wfGetDB(DB_SLAVE); self::$images[$imageName] = $dbr->selectField('imagelinks', 'count(*) as cnt', array('il_to' => $imageName), __METHOD__); $wgMemc->set($memcKey, self::$images[$imageName], 60 * 60 * 12); } wfProfileOut(__METHOD__ . "-imagelinks-count"); } if (self::$images[$imageName] < 20) { $imgageObj = false; $image = self::getThumb($imageName, $imgageObj); if ($image) { if (WikiaFileHelper::isFileTypeVideo($imgageObj)) { $item['new_videos'][] = $image; } else { $item['new_images'][] = $image; } } else { // this trick will avoid checking more then one time if image exists when it does not exists self::$images[$imageName] = 20; } } } } if (count($item['new_images']) == 0) { unset($item['new_images']); } if (count($item['new_videos']) == 0) { unset($item['new_videos']); } } if (isset($res['rc_params']['categoryInserts']) && count($res['rc_params']['categoryInserts'])) { $item['new_categories'] = $res['rc_params']['categoryInserts']; } if (isset($res['rc_params']['viewMode'])) { $item['viewMode'] = $res['rc_params']['viewMode']; } if (isset($res['rc_params']['CategorySelect'])) { $item['CategorySelect'] = $res['rc_params']['CategorySelect']; } if (isset($res['rc_params']['Badge'])) { $item['Badge'] = $res['rc_params']['Badge']; } } if (class_exists('Wall') && !empty($item['wall'])) { $wh = F::build('WallHelper', array()); if (!empty($item['parent-id'])) { $data = $wh->getWallComments($item['parent-id']); $item['comments'] = $data['comments']; $item['comments-count'] = $data['count']; } else { $data = $wh->getWallComments($item['article-id']); $item['comments'] = $data['comments']; $item['comments-count'] = $data['count']; } } $item['ns'] = $res['ns']; $this->results[$key] = $item; } wfProfileOut(__METHOD__); }
/** * Add items to loaded content */ function getContent($def_text = '') { $content = parent::getContent(); $addFile = $this->app->getGlobal('wgRequest')->getVal('addFile'); if ($addFile) { $file = wfFindFile($addFile); if ($file) { $title = $file->getTitle()->getText(); $content = "[[File:" . $title . "|right|thumb|335px]] " . $content; $type = WikiaFileHelper::isFileTypeVideo($file) ? 'video' : 'photo'; $this->helper->addJsVariable('wgEditPageAddFileType', $type); } } return $content; }
public function renderMediaGroup() { $this->wf->profileIn(__METHOD__); $items = $this->request->getVal('items', array()); $first = null; $wikiText = ''; $result = ''; $params = array(); //separate linked items from normal ones and select the first one //which will be rendered in the page foreach ($items as $item) { /** * @var $file File */ $file = $this->wf->FindFile($item['title']); if ($file instanceof File) { if (!empty($item['link'])) { //build wikitext for linked images to render separately $wikiText .= '[[' . $item['title']->getPrefixedDBkey() . '|link=' . $item['link']; if ($item['caption']) { $wikiText .= "|{$item['caption']}"; } $wikiText .= "]]\n"; } else { if (empty($first)) { $first = array('data' => $item, 'file' => $file); } //prepare data for media collection $info = array('name' => $item['title']->getText(), 'full' => $this->wf->ReplaceImageServer($file->getFullUrl(), $file->getTimestamp())); if (WikiaFileHelper::isFileTypeVideo($file)) { $info['type'] = 'video'; } if (!empty($item['caption'])) { $info['capt'] = $item['caption']; } $params[] = $info; } } } if (!empty($first) && !empty($params)) { $file = $first['file']; $origWidth = $file->getWidth(); $origHeight = $file->getHeight(); //only one non-linked media left if (count($params) == 1) { $item = $first['data']; //build wikitext for a normal thumb $groupWikiText = '[[' . $item['title']->getPrefixedDBkey() . '|thumb|' . min($origWidth, self::THUMB_WIDTH) . 'px'; if ($item['caption']) { $groupWikiText .= "|{$item['caption']}"; } $groupWikiText .= "]]\n"; $wikiText = "{$groupWikiText}{$wikiText}"; } else { //many left, proceed preparing and rendering the media group $size = self::calculateMediaSize($origWidth, $origHeight); $thumb = $file->transform($size); $attribs = array('src' => $this->wf->ReplaceImageServer($thumb->getUrl(), $file->getTimestamp()), 'width' => $size['width'], 'height' => $size['height']); $result = $this->render(self::GROUP, $attribs, $params, array(), false, Xml::element('img', $attribs, '', true), null, $this->wf->MsgForContent('wikiamobile-media-group-footer', count($params))); } } //if there's any raw wikitext left to parse //then do it now if (!empty($wikiText)) { $origVal = $this->wg->WikiaMobileDisableMediaGrouping; //avoid wikitext recursion $this->wg->WikiaMobileDisableMediaGrouping = true; $tmpParser = new Parser(); $result .= $tmpParser->parse($wikiText, $this->wg->Title, new ParserOptions())->getText(); //restoring to previous value $this->wg->WikiaMobileDisableMediaGrouping = $origVal; } $this->response->setBody($result); $this->wf->profileOut(__METHOD__); }
/** * Return a HTML representation of the image slider * * @author Jakub Kurcek */ private function renderSlider() { wfProfileIn(__METHOD__); // do not render empty sliders if (empty($this->mImages)) { wfProfileOut(__METHOD__); return ''; } $orientation = $this->getParam('orientation'); // setup image serving for "big" images if ($orientation == 'mosaic') { $imagesDimensions = array('w' => WikiaPhotoGalleryHelper::SLIDER_MOSAIC_MIN_IMG_WIDTH, 'h' => WikiaPhotoGalleryHelper::SLIDER_MOSAIC_MIN_IMG_HEIGHT); } else { $imagesDimensions = array('w' => WikiaPhotoGalleryHelper::SLIDER_MIN_IMG_WIDTH, 'h' => WikiaPhotoGalleryHelper::SLIDER_MIN_IMG_HEIGHT); } /* temp transition code until grid is fully rolled out, remove and integrate after transition */ global $wgOasisGrid; if ($orientation == 'mosaic' && !empty($wgOasisGrid)) { $imagesDimensions['w'] = WikiaPhotoGalleryHelper::WIKIA_GRID_SLIDER_MOSAIC_MIN_IMG_WIDTH; } /* end temp transistion code */ $imageServingForImages = new ImageServing(null, $imagesDimensions['w'], $imagesDimensions); // setup image serving for navigation thumbnails if ($orientation == 'mosaic') { $sliderClass = 'mosaic'; $thumbDimensions = array("w" => 155, "h" => 100); } else { if ($orientation == 'right') { $sliderClass = 'vertical'; $thumbDimensions = array("w" => 110, "h" => 50); } else { $sliderClass = 'horizontal'; $thumbDimensions = array("w" => 90, "h" => 70); } } /* temp transition code until grid is fully rolled out, remove and integrate after transition */ if ($orientation == 'mosaic' && !empty($wgOasisGrid)) { $thumbDimensions['w'] = WikiaPhotoGalleryHelper::WIKIA_GRID_THUMBNAIL_MAX_WIDTH; } /* end temp transistion code */ $imageServingForThumbs = new ImageServing(null, $thumbDimensions['w'], $thumbDimensions); $out = array(); $sliderImageLimit = $orientation == 'mosaic' ? 5 : 4; foreach ($this->mImages as $p => $pair) { /** * @var $nt Title * @var $text String * @var $link String */ $nt = $pair[0]; $text = $pair[1]; $link = $pair[2]; $linkText = $this->mData['images'][$p]['linktext']; $shortText = $this->mData['images'][$p]['shorttext']; $time = $descQuery = false; // parse link (RT #142515) $linkAttribs = $this->parseLink($nt->getLocalUrl(), $nt->getText(), $link); wfRunHooks('BeforeGalleryFindFile', array(&$this, &$nt, &$time, &$descQuery)); $img = wfFindFile($nt, $time); if (!WikiaFileHelper::isFileTypeVideo($img) && is_object($img) && $nt->getNamespace() == NS_FILE) { if (F::app()->checkSkin('wikiamobile')) { $imageUrl = wfReplaceImageServer($img->getUrl(), $img->getTimestamp()); } else { // generate cropped version of big image (fit within 660x360 box) // BugId:9678 image thumbnailer does not always land on 360px height since we scale on width // so this also scales image UP if it is too small (stretched is better than blank) // max() added due to BugId:20644 $imageUrl = $imageServingForImages->getUrl($img, max($imagesDimensions['w'], $img->getWidth()), max($imagesDimensions['h'], $img->getHeight())); } // generate navigation thumbnails $thumbUrl = $imageServingForThumbs->getUrl($img, $img->getWidth(), $img->getHeight()); $data = array('imageUrl' => $imageUrl, 'imageTitle' => $text, 'imageShortTitle' => $shortText, 'imageLink' => !empty($link) ? $linkAttribs['href'] : '', 'imageDescription' => $linkText, 'imageThumbnail' => $thumbUrl); if (F::app()->checkSkin('wikiamobile')) { $origWidth = $img->getWidth(); $origHeight = $img->getHeight(); $size = WikiaMobileMediaService::calculateMediaSize($origWidth, $origHeight); $thumb = $img->transform($size); $imageAttribs = array('src' => wfReplaceImageServer($thumb->getUrl(), $img->getTimestamp()), 'width' => $size['width'], 'height' => $size['height']); $imageParams = array('full' => $imageUrl); $data['mediaInfo'] = array('attributes' => $imageAttribs, 'parameters' => $imageParams, 'caption' => $text, 'noscript' => Xml::element('img', $imageAttribs, '', true)); } $out[] = $data; } if (count($out) >= $sliderImageLimit) { break; } } $html = ''; //check if we have something to show (images might not match required sizes) if (count($out)) { $template = new EasyTemplate(dirname(__FILE__) . '/templates'); $template->set_vars(array('sliderClass' => $sliderClass, 'images' => $out, 'thumbDimensions' => $thumbDimensions, 'sliderId' => $this->mData['id'], 'imagesDimensions' => $imagesDimensions)); if (F::app()->checkSkin('wikiamobile')) { $html = $template->render('renderWikiaMobileSlider'); } else { if ($orientation == 'mosaic') { $html = $template->render('renderMosaicSlider'); } else { $html = $template->render('renderSlider'); } } if ($orientation == 'mosaic') { $sliderResources = array('/resources/wikia/libraries/modernizr/modernizr-2.0.6.js', '/extensions/wikia/WikiaPhotoGallery/css/WikiaPhotoGallery.slidertag.mosaic.scss', '/extensions/wikia/WikiaPhotoGallery/js/WikiaPhotoGallery.slider.mosaic.js'); $javascriptInitializationFunction = 'WikiaMosaicSliderMasterControl.init'; } else { $sliderResources = array('/extensions/wikia/WikiaPhotoGallery/css/WikiaPhotoGallery.slidertag.css', '/extensions/wikia/WikiaPhotoGallery/js/WikiaPhotoGallery.slider.js'); $javascriptInitializationFunction = 'WikiaPhotoGallerySlider.init'; } $html .= F::build('JSSnippets')->addToStack($sliderResources, array(), $javascriptInitializationFunction, array($this->mData['id'])); //load WikiaMobile resources if needed using JSSnippets filtering mechanism $html .= F::build('JSSnippets')->addToStack(array('wikiaphotogallery_slider_scss_wikiamobile', 'wikiaphotogallery_slider_js_wikiamobile')); } wfProfileOut(__METHOD__); return $html; }
/** * Returns pre-formatted social sharing urls and codes * @requestParam string fileTitle * @requestParam string articleTitle (optional) * @responseParam string url - raw url that is automically determined. This is determined to be either article url or file page url. * @responseParam string articleUrl - url to article page * @responseParam string fileUrl - url to file page * @responseParam string networks - contains id(facebook, twitter, etc) and urls of external social networks */ public function getShareCodes() { $fileTitle = urldecode($this->request->getVal('fileTitle', '')); $file = wfFindFile($fileTitle); $shareUrl = ''; $articleUrl = ''; $articleNS = ''; $articleTitleText = ''; $fileUrl = ''; $thumbUrl = ''; $networks = array(); if (!empty($file)) { $fileTitleObj = Title::newFromText($fileTitle, NS_FILE); $fileTitle = $fileTitleObj->getText(); $articleTitle = $this->request->getVal('articleTitle'); $articleTitleObj = Title::newFromText($articleTitle); if (!empty($articleTitleObj) && $articleTitleObj->exists()) { $fileParam = wfUrlencode($fileTitleObj->getDBKey()); $articleUrl = $articleTitleObj->getFullURL("file={$fileParam}"); $articleNS = $articleTitleObj->getNamespace(); $articleTitleText = $articleTitleObj->getText(); } // check if the file is added to the wiki if (WikiaFileHelper::isAdded($file)) { $fileUrl = $fileTitleObj->getFullURL(); } else { $fileUrl = WikiaFileHelper::getFullUrlPremiumVideo($fileTitleObj->getDBkey()); } // determine share url $sharingNamespaces = array(NS_MAIN, NS_CATEGORY); $shareUrl = !empty($articleUrl) && in_array($articleNS, $sharingNamespaces) ? $articleUrl : $fileUrl; $thumb = $file->transform(array('width' => 300, 'height' => 250)); $thumbUrl = $thumb->getUrl(); if (WikiaFileHelper::isFileTypeVideo($file)) { $msgSuffix = '-video'; } else { $msgSuffix = ''; } $msgArticleTitle = empty($articleUrl) ? $fileTitle : $articleTitleText; $linkDescription = wfMessage('lightbox-share-description' . $msgSuffix, $msgArticleTitle, $this->wg->Sitename)->text(); $shareNetworks = SocialSharingService::getInstance()->getNetworks(array('facebook', 'twitter', 'stumbleupon', 'reddit', 'plusone')); foreach ($shareNetworks as $network) { $networks[] = array('id' => $network->getId(), 'url' => $network->getUrl($shareUrl, $linkDescription)); } } $this->shareUrl = $shareUrl; $this->articleUrl = $articleUrl; $this->fileUrl = $fileUrl; $this->networks = $networks; $this->fileTitle = $fileTitle; $this->imageUrl = $thumbUrl; // set cache control to 1 day $this->response->setCacheValidity(WikiaResponse::CACHE_STANDARD); }
public static function checkExtensionCompatibilityResult(&$result, &$file, &$oldMime, &$newExt) { if (WikiaFileHelper::isFileTypeVideo($file) && $newExt == "") { $result = true; } return true; }
protected function getFromFile($title) { $file = wfFindFile($title); if ($file instanceof LocalFile) { //media type: photo, video if (WikiaFileHelper::isFileTypeVideo($file)) { /* @var VideoHandler $handler */ $handler = VideoHandler::getHandler($file->getMimeType()); $typeInfo = explode('/', $file->getMimeType()); $metadata = $handler ? $handler->getVideoMetadata(true) : null; return ['type' => static::VIDEO_TYPE, 'provider' => isset($typeInfo[1]) ? $typeInfo[1] : static::UNKNOWN_PROVIDER, 'metadata' => ['title' => isset($metadata['title']) ? $metadata['title'] : '', 'description' => isset($metadata['description']) ? $metadata['description'] : '', 'duration' => isset($metadata['duration']) ? (int) $metadata['duration'] : 0]]; } else { return ['type' => static::IMAGE_TYPE]; } } return []; }
/** * Hook: Clear cache (videos by category) when video is deleted. We only need * to check if the file is a local video, we don't need the rest of the parameters * OnFileDeleteComplete passes in by default. Instead, after verifying the file is * a local video we find the latest program and clear the cache for the category * names defined in the category assets for that program. * @param LocalFile $file * @param $oldimage * @param $article * @param User $user * @param $reason * @return true */ public static function onFileDeleteComplete(&$file, $oldimage, $article, $user, $reason) { if (WikiaFileHelper::isFileTypeVideo($file) && $file->isLocal()) { $controller = new VideoHomePageController(); $program = $controller->getProgram(); $assets = $program->getAssetsBySection(VideoHomePageController::MODULE_CATEGORY); $helper = new VideoPageToolHelper(); foreach ($assets as $asset) { $title = Title::newFromText($asset->getCategoryName(), NS_CATEGORY); $helper->invalidateCacheVideosByCategory($title->getDBkey()); } } return true; }
echo "MUT is *{$mut}*\n"; // 1. count number of articles in content namespace $queryArticleCnt = "SELECT COUNT(*) AS cnt FROM page WHERE page_namespace IN ( " . implode(",", $wgContentNamespaces) . ")"; $rows = $dbw->query($queryArticleCnt); $row = $dbw->fetchObject($rows); $totalArticleCnt = $row->cnt; echo "Total articles in content namespaces: " . $totalArticleCnt . " \n"; // 2. count number of local videos in articles $queryLocalVideo = "SELECT COUNT(*) AS cnt\r\n \t\t FROM imagelinks il LEFT JOIN image i ON il.il_to = i.img_name\r\n \t\t WHERE i.img_major_mime = 'video' "; $rows = $dbw->query($queryLocalVideo); $row = $dbw->fetchObject($rows); $localVideoCnt = $row->cnt; echo "Local video cnt in articles: " . $localVideoCnt . " \n"; // 3. count number of videos from video wiki $queryRepositoryVideo = "SELECT il.*, i.img_major_mime\r\n\t\t\t FROM imagelinks il LEFT JOIN image i ON il.il_to = i.img_name\r\n\t\t\t WHERE i.img_major_mime IS NULL "; $rows = $dbw->query($queryRepositoryVideo); $aAllFiles = array(); while ($file = $dbw->fetchObject($rows)) { $aAllFiles[] = $file->il_to; } $repositoryVideoCnt = 0; if (count($aAllFiles) > 0) { foreach ($aAllFiles as $fileName) { $oTitle = Title::newFromText($fileName, NS_FILE); $oFile = wfFindFile($oTitle); if (!empty($oFile) && WikiaFileHelper::isFileTypeVideo($oFile)) { $repositoryVideoCnt++; } } } echo "Repo video cnt in articles: " . $repositoryVideoCnt . "\n";
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; }